[Rpm-maint] [patch] warnings for rpmExpand(), rpmlog(), rpmGetPath()

Panu Matilainen pmatilai at redhat.com
Thu Feb 14 08:44:33 UTC 2008


On Wed, 13 Feb 2008, Michal Marek wrote:

> Hi,

Hi,

> gcc allows to mark variadic functions that expect a terminating NULL as
> such and issues a warning if the caller doesn't pass the NULL. A similar
> mechanism is available for printf-like functions. What about using this
> for the few variadic functions in the rpmlib API? It would help to catch
> some mistakes at compile-time rather than at run-time, e.g:
>
>  char *test1 = rpmExpand("%_sourcedir");
>  char *test2 = rpmExpand("%_topdir", " ");
>
> $ gcc -Wall -I ./include -c test.c
> test.c: In function 'main':
> test.c:9: warning: not enough variable arguments to fit a sentinel
> test.c:10: warning: missing sentinel in function call
>
> Attached are two patches, the first one marks rpmExpand() and
> rpmGetPath() with __attribute__((sentinel)) for gcc 4.0+ and rpmlog()
> with __attribute__((format (printf, 2, 3))). The second patch silences
> warnings in rpmlog() calls that now show up.
>
> Comments?

Considering the amount of warnings the extra checking already found, 
I'd say there's little doubt of it's usefulness.

I also have little doubt that there are a number of other gcc extensions 
too that would be useful. So instead of littering the headers with
#if defined(__GNUC__) && __GNUC__ >= <someversion>
#endif
everywhere, might as well add macros for them centrally someplace, 
similarly to what glib's gmacros.h does:

#if     __GNUC__ >= 4
#define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
#else
#define G_GNUC_NULL_TERMINATED
#endif

..etc. Maybe just grab a copy of gmacros.h instead of reinventing the 
wheel...

 	- Panu -



More information about the Rpm-maint mailing list