[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Wget2 and ignoring return value of 'freopen', declared with attribute wa
From: |
Jeffrey Walton |
Subject: |
Wget2 and ignoring return value of 'freopen', declared with attribute warn_unused_result |
Date: |
Tue, 23 Jun 2020 17:44:13 -0400 |
Hi Everyone/Tim,
I see this on occasion:
libwget_xml_parse_buffer_fuzzer.c: In function 'LLVMFuzzerTestOneInput':
libwget_xml_parse_buffer_fuzzer.c:65:2: warning: ignoring return value
of 'freopen', declared with attribute warn_unused_result
[-Wunused-result]
freopen("/dev/null", "r", stdin);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I _think_ the way to handle that nowadays in a portable way is to:
#define WGET_UNUSED(x) ((void)(x))
int ret = freopen("/dev/null", "r", stdin);
WGET_UNUSED(ret);
In the past a cast to void used to work. But it has not been working
lately, with GCC9 or GCC10, and it now generates a warning, too:
(void)freopen("/dev/null", "r", stdin);
The WGET_UNUSED macro is really portable. You can also use it for
function parameters on all the compilers I test. (Unlike, say, a GCC
attribute).
Jeff
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Wget2 and ignoring return value of 'freopen', declared with attribute warn_unused_result,
Jeffrey Walton <=