diff options
author | Daniel Friesel <derf@chaosdorf.de> | 2017-04-02 14:58:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-02 14:58:04 +0200 |
commit | 78a840ed30c454d5cfa2acb482fb31e08a637ce6 (patch) | |
tree | cd63cd58b2639398525f155b16156a7a9121b05a /src/utils.c | |
parent | 1e042038c579c208d5f82a53f769a9f3cd2f1ae9 (diff) | |
parent | bdee6af09f84c224f8ba60006d3b4b977b4882e8 (diff) |
Merge pull request #287 from stoeckmann/empty-file
Avoid out of boundary read on empty/broken file.
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/utils.c b/src/utils.c index bd189d3..2c0809c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -183,14 +183,14 @@ char *ereadfile(char *path) { char buffer[4096]; FILE *fp; - int count; + size_t count; fp = fopen(path, "r"); if (!fp) return NULL; count = fread(buffer, sizeof(char), sizeof(buffer) - 1, fp); - if (buffer[count - 1] == '\n') + if (count > 0 && buffer[count - 1] == '\n') buffer[count - 1] = '\0'; else buffer[count] = '\0'; |