Skip to content

Commit

Permalink
use malloc instead
Browse files Browse the repository at this point in the history
  • Loading branch information
wkliao committed May 18, 2022
1 parent 72a0bfb commit 385f0ea
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libdispatch/dutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,13 @@ NC_readfilen(const char* filename, NCbytes* content, long long amount)
int
NC_readfileF(FILE* stream, NCbytes* content, long long amount)
{
#define READ_BLOCK_SIZE 4194304
int ret = NC_NOERR;
long long red = 0;
char part[4194304];
char *part = (char*) malloc(4194304);

while(amount < 0 || red < amount) {
size_t count = fread(part, 1, sizeof(part), stream);
size_t count = fread(part, 1, 4194304, stream);
if(ferror(stream)) {ret = NC_EIO; goto done;}
if(count > 0) ncbytesappendn(content,part,(unsigned long)count);
red += count;
Expand All @@ -297,6 +298,7 @@ NC_readfileF(FILE* stream, NCbytes* content, long long amount)
}
ncbytesnull(content);
done:
free(part);
return ret;
}

Expand Down

0 comments on commit 385f0ea

Please sign in to comment.