Re: [PATCH 4/7] builtin: directly predefine builtin macros

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jun 05, 2018 at 03:06:46AM +0100, Ramsay Jones wrote:
> 
> 
> > @@ -1111,14 +1111,20 @@ static char **handle_switch(char *arg, char **next)
> >  
> >  static void predefined_sizeof(const char *name, unsigned bits)
> >  {
> > -	add_pre_buffer("#weak_define __SIZEOF_%s__ %d\n", name, bits/8);
> > +	char *buf;
> > +
> > +	asprintf(&buf, "__SIZEOF_%s__", name);
> 
> asprintf() is a GNU extension, that is not in the C or POSIX
> standards, although I think it may be in _some_ BSDs. Also, if
> it should fail to allocate memory for the result, it will return
> -1 and the 'buf' return will be undefined.
> 
> I don't think you should use this non-standard function.

It seems to be supported on BSDs but yes, you're right, better to
stick to standard functions. In fact I had already removed a call
to vasprintf() I had used in a previous version but I forgot about
those ones.

> >  static void predefined_max(const char *name, const char *suffix, unsigned bits)
> >  {
> >  	unsigned long long max = (1ULL << (bits - 1 )) - 1;
> > +	char *buf, *val;
> >  
> > -	add_pre_buffer("#weak_define __%s_MAX__ %#llx%s\n", name, max, suffix);
> > +	asprintf(&buf, "__%s_MAX__", name);
> > +	asprintf(&val, "%#llx%s", max, suffix);
> 
> ditto times two. ;-)

And the last one wasn't even needed since it could have been done
with predefinef().
 
I'll resend later a new version with these calls removed.


Thanks for noticing all this
-- Luc
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux