Skip to content

Commit

Permalink
Use C style NULL pointer checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillof committed Aug 22, 2024
1 parent 2fd1201 commit b10d82b
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/zip_add_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ _zip_add_entry(zip_t *za) {
return -1;
}
rentries = (zip_entry_t *)realloc(za->entry, sizeof(struct zip_entry) * (size_t)nalloc);
if (!rentries) {
if (rentries == NULL) {
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return -1;
}
Expand Down
8 changes: 5 additions & 3 deletions lib/zip_dirent.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ void
_zip_cdir_free(zip_cdir_t *cd) {
zip_uint64_t i;

if (!cd)
if (cd == NULL) {
return;
}

for (i = 0; i < cd->nentry; i++)
_zip_entry_finalize(cd->entry + i);
Expand Down Expand Up @@ -139,6 +140,7 @@ _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivor
zip_entry_t *entry = za->entry + filelist[i].idx;

if (_zip_dirent_write(za, entry->changes ? entry->changes : entry->orig, ZIP_FL_CENTRAL) < 0) {
za->write_crc = NULL;
return -1;
}
}
Expand Down Expand Up @@ -446,7 +448,7 @@ _zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, boo

if (filename_len) {
zde->filename = _zip_read_string(buffer, src, filename_len, 1, error);
if (!zde->filename) {
if (zde->filename == NULL) {
if (zip_error_code_zip(error) == ZIP_ER_EOF) {
zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_VARIABLE_SIZE_OVERFLOW);
}
Expand Down Expand Up @@ -490,7 +492,7 @@ _zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, boo

if (comment_len) {
zde->comment = _zip_read_string(buffer, src, comment_len, 0, error);
if (!zde->comment) {
if (zde->comment == NULL) {
if (!from_buffer) {
_zip_buffer_free(buffer);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/zip_fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ ZIP_EXTERN zip_int64_t
zip_fread(zip_file_t *zf, void *outbuf, zip_uint64_t toread) {
zip_int64_t n;

if (!zf)
if (zf == NULL) {
return -1;
}

if (zf->error.zip_err != 0)
if (zf->error.zip_err != 0) {
return -1;
}

if (toread > ZIP_INT64_MAX) {
zip_error_set(&zf->error, ZIP_ER_INVAL, 0);
Expand Down
8 changes: 5 additions & 3 deletions lib/zip_fseek.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@

ZIP_EXTERN zip_int8_t
zip_fseek(zip_file_t *zf, zip_int64_t offset, int whence) {
if (!zf)
if (zf == NULL) {
return -1;
}

if (zf->error.zip_err != 0)
if (zf->error.zip_err != 0) {
return -1;
}

if (zip_source_seek(zf->src, offset, whence) < 0) {
zip_error_set_from_source(&zf->error, zf->src);
Expand All @@ -53,7 +55,7 @@ zip_fseek(zip_file_t *zf, zip_int64_t offset, int whence) {

ZIP_EXTERN int
zip_file_is_seekable(zip_file_t *zfile) {
if (!zfile) {
if (zfile == NULL) {
return -1;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/zip_ftell.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ ZIP_EXTERN zip_int64_t
zip_ftell(zip_file_t *zf) {
zip_int64_t res;

if (!zf)
if (zf == NULL) {
return -1;
}

if (zf->error.zip_err != 0)
if (zf->error.zip_err != 0) {
return -1;
}

res = zip_source_tell(zf->src);
if (res < 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/zip_io_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ _zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp
}

r = (zip_uint8_t *)malloc(length + (nulp ? 1 : 0));
if (!r) {
if (r == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/zip_memdup.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ _zip_memdup(const void *mem, size_t len, zip_error_t *error) {
return NULL;

ret = malloc(len);
if (!ret) {
if (ret == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/zip_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ _zip_new(zip_error_t *error) {
zip_t *za;

za = (zip_t *)malloc(sizeof(struct zip));
if (!za) {
if (za == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
return NULL;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/zip_source_file.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef _HAD_ZIP_SOURCE_FILE_H
#define _HAD_ZIP_SOURCE_FILE_H

/*
zip_source_file.h -- header for common file operations
Copyright (C) 2020-2022 Dieter Baron and Thomas Klausner
Expand Down Expand Up @@ -88,3 +91,5 @@ struct zip_source_file_operations {
};

zip_source_t *zip_source_file_common_new(const char *fname, void *file, zip_uint64_t start, zip_int64_t len, const zip_stat_t *st, zip_source_file_operations_t *ops, void *ops_userdata, zip_error_t *error);

#endif /* _HAD_ZIP_SOURCE_FILE_H */
2 changes: 1 addition & 1 deletion lib/zipint.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,4 @@ int _zip_unchange(zip_t *, zip_uint64_t, int);
void _zip_unchange_data(zip_entry_t *);
int _zip_write(zip_t *za, const void *data, zip_uint64_t length);

#endif /* zipint.h */
#endif /* _HAD_ZIPINT_H */

0 comments on commit b10d82b

Please sign in to comment.