Skip to content

Conversation

@yuce
Copy link

@yuce yuce commented Dec 23, 2025

When I try to make the project using GCC 13.3.0, I get the following errors about ignoring the return result of fread in the load_file functions in mqjs.c and example.c:

gcc -Wall -g -MMD -Werror -D_GNU_SOURCE -fno-math-errno -fno-trapping-math -Os -c -o mqjs.o mqjs.c
mqjs.c: In function ‘load_file’:
mqjs.c:253:5: error: ignoring return value of ‘fread’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  253 |     fread(buf, 1, buf_len, f);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:109: mqjs.o] Error 1

And

gcc -Wall -g -MMD -Werror -D_GNU_SOURCE -fno-math-errno -fno-trapping-math -Os -c -o example.o example.c
example.c: In function ‘load_file’:
example.c:244:5: error: ignoring return value of ‘fread’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  244 |     fread(buf, 1, buf_len, f);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:109: example.o] Error 1

This PR fixes that by exiting if buf_len bytes are not read.

buf = malloc(buf_len + 1);
fread(buf, 1, buf_len, f);
if (fread(buf, 1, buf_len, f) != buf_len) {
printf("not read %d bytes\n", buf_len);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better: fprintf(stderr,"Can't read %d bytes in %s\n", buf_len, filename );

and also in the other file.

@bellard
Copy link
Owner

bellard commented Dec 24, 2025

just ignoring the warning is acceptable too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants