This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, fixincludes]: Check return value of getcwd
- From: Uros Bizjak <ubizjak at gmail dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 9 Dec 2014 19:52:29 +0100
- Subject: [PATCH, fixincludes]: Check return value of getcwd
- Authentication-results: sourceware.org; auth=none
Hello!
The compilation with gentoo glibc 2.20 emits following warning:
../../../gcc-svn/trunk/fixincludes/server.c:195:10: warning: ignoring
return value of âgetcwdâ, declared with attribute warn_unused_result
[-Wunused-result]
The manpage says:
On failure, these functions return NULL, and errno is set to indicate
the error. The contents of the array pointed to by buf are undefined
on error.
Attached patch checks the return value and sets buff[0] to 0 in this case.
2014-12-09 Uros Bizjak <ubizjak@gmail.com>
* server.c (server_setup): Check return value of
getcwd and in case of error set buff[0] to 0.
Bootstrapped on x86_64-linux-gnu.
OK for mainline?
Index: server.c
===================================================================
--- server.c (revision 218525)
+++ server.c (working copy)
@@ -192,7 +192,8 @@ server_setup (void)
fputs ("trap : 1\n", server_pair.pf_write);
fflush (server_pair.pf_write);
- getcwd (buff, MAXPATHLEN + 1);
+ if (getcwd (buff, MAXPATHLEN + 1) == NULL)
+ buff[0] = 0;
p_cur_dir = xstrdup (buff);
}