jart / blink

tiniest x86-64-linux emulator
ISC License
6.89k stars 217 forks source link

Fix "warn_unused_result" errors #140

Closed jiripospisil closed 1 year ago

jiripospisil commented 1 year ago

The compilation fails when compiling on Arch Linux using makepkg (config):

cc -fno-align-functions -fno-common -pthread -fpie -march=x86-64 -mtune=generic
-O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat
-Werror=format-security         -fstack-clash-protection -fcf-protection
-fno-omit-frame-pointer -fno-optimize-sibling-calls -fcf-protection=none
-U_FORTIFY_SOURCE -D_FILE_OFFSET_BITS=64 -D_DARWIN_C_SOURCE -D_DEFAULT_SOURCE
-D_BSD_SOURCE -D_GNU_SOURCE -iquote. -DCONFIG_ARGUMENTS="\"\""
-DBUILD_TOOLCHAIN="\"cc (GCC) 13.1.1 20230429\"" -DBUILD_TIMESTAMP="\"Mon Jun
5 11:09:39 UTC 2023\"" -DBLINK_COMMITS="\"\"" -DBLINK_UNAME_V="\"DEFAULT\""
-DBLINK_GITSHA="\"\"" -DBUILD_MODE="\"\""  -c -o o//blink/blink.o blink/blink.c
blink/blink.c: In function ‘Print’: blink/blink.c:251:9:

error: ignoring return value of ‘write’ declared with attribute
‘warn_unused_result’ [-Werror=unused-result]
251 |   (void)write(fd, s, strlen(s));
    | ^~~~~~~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as
errors make: *** [build/rules.mk:13: o//blink/blink.o]

Use (void)! to avoid the error as suggested at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34.

tkchia commented 1 year ago

Hello @jiripospisil,

Thanks. This is one way to deal with the warning, I suppose.

(As an alternative, we could say, "OK, GCC, you win", and tweak the code to actually detect and handle incomplete writes... Cosmopolitan has an xwrite function which basically does this.)

Thank you!

jiripospisil commented 1 year ago

Hello! If this was application code then absolutely, but the reason there was a previous attempt to ignore the errors is simply because it's used only to print usage or warn about illegal arguments on the command line.