Hello!

The compilation with gentoo glibc 2.20 emits following warning:

../../../gcc-svn/trunk/libcpp/directives.c:2411:28: warning: ignoring
return value of ‘int vasprintf(char**, const char*, __gnuc_va_list)’,
declared with attribute warn_unused_result [-Wunused-result]

The manpage says:

If memory allocation wasn't possible, or some other error occurs,
these functions will return -1, and the contents of strp is undefined.

Attached patch checks the return value and sets ptr to NULL in this case.

2014-12-09  Uros Bizjak  <ubiz...@gmail.com>

    * directives.c (cpp_define_formatted): Check return value of
    vasprintf and in case of error set ptr to NULL.

Bootstrapped on x86_64-linux-gnu.

OK for mainline?

Uros.

Index: directives.c
===================================================================
--- directives.c        (revision 218525)
+++ directives.c        (working copy)
@@ -2408,7 +2408,8 @@ cpp_define_formatted (cpp_reader *pfile, const cha

   va_list ap;
   va_start (ap, fmt);
-  vasprintf (&ptr, fmt, ap);
+  if (vasprintf (&ptr, fmt, ap) < 0)
+    ptr = NULL;
   va_end (ap);

   cpp_define (pfile, ptr);

Reply via email to