Skip to content

Commit 9127a5e

Browse files
committed
libretro-common/samples/streams/rzip: silence fgets -Wunused-result
Minor bit-rot cleanup. Every CI build of the libretro-common samples workflow emitted: rzip.c:246:7: warning: ignoring return value of 'fgets' declared with attribute 'warn_unused_result' [-Wunused-result] The sample prompts the user with "Overwrite? [Y/n]" and reads the reply with fgets. The existing code already handles fgets failure correctly -- reply[0] is initialised to '\0' on line 242, so an EOF or read error leaves reply[0] == '\0' and the subsequent "if (reply[0] != 'Y')" short-circuits to the safe "don't overwrite" path. The warning is the tool correctly noticing that the return value is unused; the code is in fact correct. Fix: cast the fgets call to (void)! to explicitly signal that the return is intentionally ignored. Add a comment explaining the fail-safe interaction with the reply[0] == '\0' init. This is the same (void)!<call> idiom used elsewhere in the repository to silence GCC/glibc's warn_unused_result without changing behaviour. Verified: - CFLAGS += -Wall -Wunused-result -pedantic -std=gnu99: clean compile (warning gone, no new warnings). - Full libretro-common samples CI dry-run: Built: 15 Ran: 15 Failed: 0 The only remaining warning in the full dry-run is the pre-existing "ISO C forbids an empty translation unit" from compat_snprintf.c, which is in the main library (not a sample) and has a different root cause -- separate concern. Regression test: NONE. This is a diagnostic cleanup on a build-only sample; there is no behaviour change to discriminate.
1 parent f3bf03e commit 9127a5e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • libretro-common/samples/streams/rzip

libretro-common/samples/streams/rzip/rzip.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,13 @@ int main(int argc, char *argv[])
243243

244244
printf("WARNING: Output file already exists: %s\n", out_file_path);
245245
printf(" Overwrite? [Y/n]: ");
246-
fgets(reply, sizeof(reply), stdin);
246+
/* Ignore the fgets return value intentionally -- on EOF or
247+
* error we fall through to the reply[0] check below, which
248+
* fails the 'Y' comparison (reply[0] stays '\0' from the
249+
* initialisation above) and bails out safely without
250+
* overwriting. Cast to void to silence -Wunused-result on
251+
* GCC/glibc, which attaches warn_unused_result to fgets. */
252+
(void)!fgets(reply, sizeof(reply), stdin);
247253
if (reply[0] != 'Y')
248254
goto end;
249255
}

0 commit comments

Comments
 (0)