This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, fixincludes]: Check return value of getcwd


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);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]