diff mbox

[fixincludes] : Check return value of getcwd

Message ID CAFULd4bkDSX5daG0h6_AoVocgQEFyQGdHi2+jLnqp_UoTmeDeA@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak Dec. 9, 2014, 6:52 p.m. UTC
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?
diff mbox

Patch

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