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 <barryjzhao@tencent.com>
This commit is contained in:
Jun Zhao
2026-03-09 08:47:49 +08:00
committed by toots
parent c29206e456
commit c51a420b59

View File

@@ -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) {