This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: implement fdiagnostics-print-source-range-info
On Wed, 5 Aug 2009, Manuel López-Ibáñez wrote:
> 2009/8/4 Joseph S. Myers <joseph@codesourcery.com>:
> > On Tue, 4 Aug 2009, Manuel López-Ibáñez wrote:
> >
> >> + ?if (flag_show_ranges && num_ranges)
> >> + ? ?{
> >> + ? ? ?int i;
> >> + ? ? ?char * rangestr = NULL;
> >> + ? ? ?char * tmpstr;
> >> +
> >> + ? ? ?asprintf(&tmpstr, "%s", "");
> >
> > You need to check the return value of asprintf (tmpstr is undefined if
> > asprintf fails), and note the space needed before "(".
>
> What is the proper way to fail if the return value is not positive? I
> see other uses of asprintf and vasprintf but none of them actually
> check their return value.
Fail the same way as xmalloc. The right way is probably to add xasprintf
and xvasprintf functions to libiberty (gengtype has its own xasprintf
function; gnulib has xasprintf and xvasprintf so there's precedent for
those names) and make the existing callers use them.
--
Joseph S. Myers
joseph@codesourcery.com