From c51a420b59f950528a5eeec9b953af1bd48be86c Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Mon, 9 Mar 2026 08:47:49 +0800 Subject: [PATCH] doc/examples/hw_decode: check fopen return value for output file The output file fopen() result is not checked. If it fails (e.g. permission denied or invalid path), output_file is NULL and the subsequent fwrite() call will crash. Add a NULL check with an error message, consistent with the existing error handling pattern in this example. Signed-off-by: Jun Zhao --- doc/examples/hw_decode.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/examples/hw_decode.c b/doc/examples/hw_decode.c index 7c73d59d93..7ecb70b181 100644 --- a/doc/examples/hw_decode.c +++ b/doc/examples/hw_decode.c @@ -233,6 +233,10 @@ int main(int argc, char *argv[]) /* open the file to dump raw data */ output_file = fopen(argv[3], "w+b"); + if (!output_file) { + fprintf(stderr, "Cannot open output file '%s'\n", argv[3]); + return -1; + } /* actual decoding and dump the raw data */ while (ret >= 0) {