Closed Bug 836455 Opened 7 years ago Closed 7 years ago

nptest.cpp:1392:48: error: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result [-Werror=unused-result]

Categories

(Core :: Plug-ins, defect, P3)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: dholbert, Assigned: dholbert)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

When I try to do a local opt build w/ --enable-warnings-as-errors, I get this build error:
{
dom/plugins/test/testplugin/nptest.cpp: In function ‘void NPP_StreamAsFile(NPP, NPStream*, const char*)’:
plugins/test/testplugin/nptest.cpp:1392:48: error: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result [-Werror=unused-result]
}

Looks like we need to just sanity-check the return value of fread().
Or unused << since this is test code.
Priority: -- → P3
We apparently tried that before, and it triggers linking errors. See bug 754198 comment 9.

Might as well just fix this the "right" way (checking the return value), and not worry about those linking errors.
Attached patch fixSplinter Review
Attachment #708281 - Flags: review?(benjamin)
Comment on attachment 708281 [details] [diff] [review]
fix

>-    fread(instanceData->fileBuf, 1, size, file);
>+    size_t sizeRead = fread(instanceData->fileBuf, 1, size, file);
>+    if (sizeRead != size) {

Just to decode this, if you don't know fread()'s parameters by heart:

We're attempting to read 'size' chunks of data, w/ each chunk having a length of '1', from file, into fileBuf.  So, read 'size' bytes.

The return value is the number of chunks read -- so, i.e. the number of bytes read, since our chunk size is 1. So if all is well, it should return 'size'.
Attachment #708281 - Flags: review?(benjamin) → review+
Green linux/mac try run:  https://tbpl.mozilla.org/?tree=Try&rev=517774a31e08

Landed: https://hg.mozilla.org/mozilla-central/rev/96c341954032
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Flags: in-testsuite-
OS: Linux → All
Hardware: x86_64 → All
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.