diff --git a/mongoose.c b/mongoose.c index 1cc814e4..7377d3c3 100644 --- a/mongoose.c +++ b/mongoose.c @@ -788,12 +788,13 @@ static void *ff_open(const char *path, int flags) { unsigned char mode = FA_READ; if (flags & MG_FS_WRITE) mode |= FA_WRITE | FA_OPEN_ALWAYS | FA_OPEN_APPEND; if (f_open(&f, path, mode) == 0) { - FIL *fp = calloc(1, sizeof(*fp)); - memcpy(fp, &f, sizeof(*fp)); - return fp; - } else { - return NULL; + FIL *fp; + if ((fp = calloc(1, sizeof(*fp))) != NULL) { + memcpy(fp, &f, sizeof(*fp)); + return fp; + } } + return NULL; } static void ff_close(void *fp) { @@ -913,9 +914,10 @@ static void *packed_open(const char *path, int flags) { struct packed_file *fp = NULL; if (data == NULL) return NULL; if (flags & MG_FS_WRITE) return NULL; - fp = (struct packed_file *) calloc(1, sizeof(*fp)); - fp->size = size; - fp->data = data; + if ((fp = (struct packed_file *) calloc(1, sizeof(*fp))) != NULL) { + fp->size = size; + fp->data = data; + } return (void *) fp; } diff --git a/src/fs_fat.c b/src/fs_fat.c index 2997dd67..030aafb3 100644 --- a/src/fs_fat.c +++ b/src/fs_fat.c @@ -73,12 +73,13 @@ static void *ff_open(const char *path, int flags) { unsigned char mode = FA_READ; if (flags & MG_FS_WRITE) mode |= FA_WRITE | FA_OPEN_ALWAYS | FA_OPEN_APPEND; if (f_open(&f, path, mode) == 0) { - FIL *fp = calloc(1, sizeof(*fp)); - memcpy(fp, &f, sizeof(*fp)); - return fp; - } else { - return NULL; + FIL *fp; + if ((fp = calloc(1, sizeof(*fp))) != NULL) { + memcpy(fp, &f, sizeof(*fp)); + return fp; + } } + return NULL; } static void ff_close(void *fp) { diff --git a/src/fs_packed.c b/src/fs_packed.c index 70908193..e2e60a44 100644 --- a/src/fs_packed.c +++ b/src/fs_packed.c @@ -67,9 +67,10 @@ static void *packed_open(const char *path, int flags) { struct packed_file *fp = NULL; if (data == NULL) return NULL; if (flags & MG_FS_WRITE) return NULL; - fp = (struct packed_file *) calloc(1, sizeof(*fp)); - fp->size = size; - fp->data = data; + if ((fp = (struct packed_file *) calloc(1, sizeof(*fp))) != NULL) { + fp->size = size; + fp->data = data; + } return (void *) fp; }