[Bug c/29480] Feature request - Addition to FORTIFY_SOURCE feature

robert at linuxfromscratch dot org gcc-bugzilla@gcc.gnu.org
Sun Oct 15 19:41:00 GMT 2006



------- Comment #2 from robert at linuxfromscratch dot org  2006-10-15 19:41 -------
echo '#include <unistd.h>
int main () {
chdir( "/" );
}' > example.c

$ gcc -o example example.c -D_FORTIFY_SOURCE -O2
example.c: In function 'main':
example.c:5: warning: ignoring return value of 'chdir', declared with attribute
warn_unused_result

echo '#include <unistd.h>
#include <assert.h>
int main () {
assert (chdir( "/" ));
}' > example2.c

$ gcc -o example2 example2.c -D_FORTIFY_SOURCE -O2

With assert(3) there's no warning.

These warnings usually affect fwrite(), dup(), chdir(), fchown(), fgets(),
write(), mktemp(), mkstemp(), and mkdtemp(). The results of these are usually
checked later by other functions, but FORTIFY_SOURCE does not know that and
complains.

To silence the warning we could either add more logic to FORTIFY_SOURCE to
follow functions, checking if their returns go unused in the completed code, or
add assert(3).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29480



More information about the Gcc-bugs mailing list