This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, libcpp]: Check the result of vasprintf
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Uros Bizjak <ubizjak at gmail dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 9 Dec 2014 22:24:39 +0000
- Subject: Re: [PATCH, libcpp]: Check the result of vasprintf
- Authentication-results: sourceware.org; auth=none
- References: <CAFULd4YMrT+yj0vxPF_-xjiR0PyCt3pwibEqbtEEC0FTtk1wbA at mail dot gmail dot com>
On Tue, 9 Dec 2014, Uros Bizjak wrote:
> Attached patch checks the return value and sets ptr to NULL in this case.
>
> 2014-12-09 Uros Bizjak <ubizjak@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?
No, this will just continue to pass NULL into cpp_define, and so into
strlen, where it isn't a valid argument. You need to give an error
message for allocation failure and exit, much like xmalloc does (or put
xvasprintf in libiberty and use that here - see
<https://gcc.gnu.org/ml/gcc-patches/2009-11/msg01448.html> and
<https://gcc.gnu.org/ml/gcc-patches/2009-11/msg01449.html> - I don't know
if that's the latest version).
--
Joseph S. Myers
joseph@codesourcery.com