CP/M sbrk now handles overflow correctly.
This commit is contained in:
parent
a91ab5c599
commit
19f5ee3399
|
@ -31,13 +31,25 @@ int brk(void* newend)
|
|||
void* sbrk(int increment)
|
||||
{
|
||||
char* old;
|
||||
char* new;
|
||||
|
||||
if (increment == 0)
|
||||
return current;
|
||||
|
||||
old = current;
|
||||
if (brk(old + increment) < 0)
|
||||
return OUT_OF_MEMORY;
|
||||
new = old + increment;
|
||||
|
||||
if ((increment > 0) && (new <= old))
|
||||
goto out_of_memory;
|
||||
else if ((increment < 0) && (new >= old))
|
||||
goto out_of_memory;
|
||||
|
||||
if (brk(new) < 0)
|
||||
goto out_of_memory;
|
||||
|
||||
return old;
|
||||
|
||||
out_of_memory:
|
||||
errno = ENOMEM;
|
||||
return OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue