xmalloc_[open_]read[_close]: do not ignore xrealloc return value

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-05-15 23:23:23 +02:00
parent c15f40c3e7
commit 071ede1e5d
2 changed files with 8 additions and 2 deletions

View File

@ -965,6 +965,12 @@ enum {
/* How long the longest ESC sequence we know? */ /* How long the longest ESC sequence we know? */
KEYCODE_BUFFER_SIZE = 4 KEYCODE_BUFFER_SIZE = 4
}; };
/* Note: fd may be in blocking or non-blocking mode, both make sense.
* For one, less uses non-blocking mode.
* Only the first read syscall inside read_key may block indefinitely
* (unless fd is in non-blocking mode),
* subsequent reads will time out after a few milliseconds.
*/
int read_key(int fd, smalluint *nbuffered, char *buffer) FAST_FUNC; int read_key(int fd, smalluint *nbuffered, char *buffer) FAST_FUNC;

View File

@ -229,7 +229,7 @@ void* FAST_FUNC xmalloc_read(int fd, size_t *maxsz_p)
if (size > 64*1024) if (size > 64*1024)
size = 64*1024; size = 64*1024;
} }
xrealloc(buf, total + 1); buf = xrealloc(buf, total + 1);
buf[total] = '\0'; buf[total] = '\0';
if (maxsz_p) if (maxsz_p)
@ -273,7 +273,7 @@ void* FAST_FUNC xmalloc_open_read_close(const char *filename, size_t *maxsz_p)
free(buf); free(buf);
return NULL; return NULL;
} }
xrealloc(buf, size + 1); buf = xrealloc(buf, size + 1);
buf[size] = '\0'; buf[size] = '\0';
if (maxsz_p) if (maxsz_p)