add missing fopen() return checks Fixes some clang-19 static analysis warnings of the form: ``` Null pointer passed to 4th parameter expecting 'nonnull' ``` Bug: 474642915 Change-Id: I353a4d6cc2569b2cd741822e4854d27296ccb777
diff --git a/av1/common/debugmodes.c b/av1/common/debugmodes.c index d9a9672..667d988 100644 --- a/av1/common/debugmodes.c +++ b/av1/common/debugmodes.c
@@ -96,6 +96,7 @@ void av1_print_uncompressed_frame_header(const uint8_t *data, int size, const char *filename) { FILE *hdrFile = fopen(filename, "w"); + if (!hdrFile) return; fwrite(data, size, sizeof(uint8_t), hdrFile); // Reset order hints(7bit + a previous bit) to 0, so that all camera frame @@ -109,6 +110,7 @@ void av1_print_frame_contexts(const FRAME_CONTEXT *fc, const char *filename) { FILE *fcFile = fopen(filename, "w"); + if (!fcFile) return; const uint16_t *fcp = (uint16_t *)fc; const unsigned int n_contexts = sizeof(FRAME_CONTEXT) / sizeof(uint16_t); unsigned int i;
diff --git a/av1/encoder/partition_strategy.c b/av1/encoder/partition_strategy.c index 4b44ba4..e3c4178 100644 --- a/av1/encoder/partition_strategy.c +++ b/av1/encoder/partition_strategy.c
@@ -2469,6 +2469,7 @@ snprintf(filename, sizeof(filename), "%s/motion_search_feature_sb%d", path, sb_counter); FILE *pfile = fopen(filename, "w"); + if (pfile == NULL) return; fprintf(pfile, "%d,%d,%d,%d,%d\n", mi_row, mi_col, bsize, block_size_wide[fixed_block_size], num_blocks); for (int i = 0; i < num_blocks; ++i) {
diff --git a/examples/lightfield_decoder.c b/examples/lightfield_decoder.c index d77235f..13945c5 100644 --- a/examples/lightfield_decoder.c +++ b/examples/lightfield_decoder.c
@@ -248,6 +248,10 @@ snprintf(name, sizeof(name), "ref_%d.yuv", i); printf("writing ref image to %s, %u, %u\n", name, img->d_w, img->d_h); FILE *ref_file = fopen(name, "wb"); + if (!ref_file) { + fprintf(stderr, "Unable to open ref_file '%s'\n", name); + continue; + } aom_img_write(img, ref_file); fclose(ref_file); }
diff --git a/examples/lightfield_tile_list_decoder.c b/examples/lightfield_tile_list_decoder.c index dd6391e..ead9c22 100644 --- a/examples/lightfield_tile_list_decoder.c +++ b/examples/lightfield_tile_list_decoder.c
@@ -186,6 +186,10 @@ snprintf(name, sizeof(name), "ref_%d.yuv", i); printf("writing ref image to %s, %u, %u\n", name, img->d_w, img->d_h); FILE *ref_file = fopen(name, "wb"); + if (!ref_file) { + fprintf(stderr, "Unable to open ref_file '%s'\n", name); + continue; + } aom_img_write(img, ref_file); fclose(ref_file); }