diff options
author | Christos Zoulas <christos@zoulas.com> | 2023-04-02 16:31:54 +0000 |
---|---|---|
committer | Christos Zoulas <christos@zoulas.com> | 2023-04-02 16:31:54 +0000 |
commit | 9337839b47ef5e7d8af943e2287e5aaac3040a21 (patch) | |
tree | 1da2f397013b70d35935a90ea1c03628b57dfdba | |
parent | ed4cea40369e1645e761ff039aac407c0c3d8365 (diff) | |
download | file-git-9337839b47ef5e7d8af943e2287e5aaac3040a21.tar.gz |
Avoid 0 size malloc
-rw-r--r-- | src/buffer.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/buffer.c b/src/buffer.c index ac9fd155..fbdb2222 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: buffer.c,v 1.10 2022/09/24 20:30:13 christos Exp $") +FILE_RCSID("@(#)$File: buffer.c,v 1.11 2023/04/02 16:31:54 christos Exp $") #endif /* lint */ #include "magic.h" @@ -69,8 +69,10 @@ buffer_fill(const struct buffer *bb) if (!S_ISREG(b->st.st_mode)) goto out; - b->elen = CAST(size_t, b->st.st_size) < b->flen ? + b->elen = CAST(size_t, b->st.st_size) < b->flen ? CAST(size_t, b->st.st_size) : b->flen; + if (b->elen == 0) + return 0; if ((b->ebuf = malloc(b->elen)) == NULL) goto out; |