mirror of
https://github.com/troglobit/editline.git
synced 2025-06-24 16:52:42 +08:00
Handle realloc() failures better
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
deb2884310
commit
cf8f962e4f
@ -178,8 +178,12 @@ static void tty_put(const char c)
|
||||
|
||||
Screen[ScreenCount] = c;
|
||||
if (++ScreenCount >= ScreenSize) {
|
||||
char *ptr;
|
||||
|
||||
ScreenSize += SCREEN_INC;
|
||||
Screen = realloc(Screen, sizeof(char) * ScreenSize);
|
||||
ptr = realloc(Screen, sizeof(char) * ScreenSize);
|
||||
if (ptr)
|
||||
Screen = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1281,9 +1285,12 @@ static char *read_redirected(void)
|
||||
int oldpos = end - line;
|
||||
|
||||
size += MEM_INC;
|
||||
p = line = realloc(line, sizeof(char) * size);
|
||||
if (!p)
|
||||
p = realloc(line, sizeof(char) * size);
|
||||
if (!p) {
|
||||
free(line);
|
||||
return NULL;
|
||||
}
|
||||
line = p;
|
||||
end = p + size;
|
||||
|
||||
p += oldpos; /* Continue where we left off... */
|
||||
|
Loading…
Reference in New Issue
Block a user