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]

Re: [PATCH]: Add -Wcast-qual to the bootstrap warning flags


On Mon, 24 Sep 2007, Jakub Jelinek wrote:

> On Mon, Sep 24, 2007 at 10:35:45AM -0400, Kaveh R. GHAZI wrote:
> > On Sun, 23 Sep 2007, Andrew Pinski wrote:
> >
> > > On 9/23/07, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
> > >
> > > > +       asprintf (CONST_CAST(char **, &m68k_library_id_string),
> > >                                               ^
> > > Missing space.  Also this looks wrong anyways.
> >
> > What do you think is wrong with this exactly?  The m68k_library_id_string
> > variable is a const object that's being initialized here in asprintf.
> > Initializing const objects is one of the legitimate cases I've enumerated
> > for using CONST_CAST.  And as I mentioned I did "make cc1" cross-targetted
> > to m68k-unknown-linux-gnu (among many others) to ensure I didn't introduce
> > a typo.
>
> I don't think this is legitimate.  You should simply:
> char *temp;
> asprintf (&temp, ....);
> m68k_library_id_string = temp;
>
> i.e. completely prepare the object as non-const and only when it is
> fully prepared store address of the temp object into the const char *
> var.

<Shrug>, okay.


> The asprintf call does no error checking btw, it can fail e.g. if malloc
> fails (probably that's the only reason when format string is %d).
> So it should be checked as well.
> 	Jakub

Well that was a preexisting fault unrelated to my patch.  But I can fix
that as well if you like.  Would aborting on an error, like xmalloc does,
be acceptable in this situation?

		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu


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