don't use variable length array

This commit is contained in:
Yuichi Nishiwaki 2015-01-27 13:54:41 +09:00
parent de294b0784
commit 914c295177
1 changed files with 11 additions and 1 deletions

View File

@ -330,11 +330,17 @@ xfflush(xFILE *file)
PIC_INLINE size_t
xfread(void *ptr, size_t block, size_t nitems, xFILE *file)
{
char cbuf[256], *buf;
char *dst = (char *)ptr;
char buf[block];
size_t i, offset;
int n;
if (block <= 256) {
buf = cbuf;
} else {
buf = malloc(block);
}
for (i = 0; i < nitems; ++i) {
offset = 0;
if (file->ungot != -1 && block > 0) {
@ -359,6 +365,10 @@ xfread(void *ptr, size_t block, size_t nitems, xFILE *file)
}
exit:
if (cbuf != buf) {
free(buf);
}
return i;
}