[PATCH:ico] Convert icoFatal() to be a varargs function
Peter Hutterer
peter.hutterer at who-t.net
Sun Jan 18 13:21:02 PST 2015
On Fri, Jan 16, 2015 at 11:27:00PM -0800, Alan Coopersmith wrote:
> Drops needless NULL arguments and enables printf format checking.
>
> Gets rid of gcc 4.8 warning:
> ico.c: In function ‘icoFatal’:
> ico.c:265:2: warning: format not a string literal, argument types not checked [-Wformat-nonliteral]
> fprintf(stderr, fmt, a0);
> ^
>
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
it's like the future is already here! can I have my flying car now?
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
Cheers,
Peter
> ---
> ico.c | 23 +++++++++++++----------
> 1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/ico.c b/ico.c
> index 832ec16..785f3bf 100644
> --- a/ico.c
> +++ b/ico.c
> @@ -87,6 +87,7 @@ SOFTWARE.
> #include <X11/Xfuncs.h>
> #include <X11/keysym.h>
> #include <stdio.h>
> +#include <stdarg.h>
> #ifdef MULTIBUFFER
> #include <X11/extensions/multibuf.h>
> #endif /* MULTIBUFFER */
> @@ -256,13 +257,15 @@ static xcondition_rec count_cond;/* Xthreads doesn't define an equivalent to
> *****************************************************************************/
>
>
> -static void icoFatal (const char *fmt, const char *a0) _X_NORETURN;
> -
> -static void
> -icoFatal(const char *fmt, const char *a0)
> +static void _X_NORETURN _X_ATTRIBUTE_PRINTF(1, 2)
> +icoFatal(const char *fmt, ...)
> {
> + va_list args;
> +
> fprintf(stderr, "%s: ", ProgramName);
> - fprintf(stderr, fmt, a0);
> + va_start(args, fmt);
> + vfprintf(stderr, fmt, args);
> + va_end(args);
> fprintf(stderr, "\n");
> exit(1);
> }
> @@ -754,7 +757,7 @@ initDBufs(struct closure *closure, unsigned long fg, unsigned long bg,
> closure->plane_masks,closure->totalplanes, closure->pixels,1);
> /* allocate color planes */
> if (t==0) {
> - icoFatal("can't allocate enough color planes", NULL);
> + icoFatal("can't allocate enough color planes");
> }
> }
>
> @@ -847,7 +850,7 @@ do_ico_window(void *ptr)
> #endif
> closure->cmap = XDefaultColormap(dpy,DefaultScreen(dpy));
> if (!closure->cmap) {
> - icoFatal("no default colormap!", NULL);
> + icoFatal("no default colormap!");
> }
>
> fg = WhitePixel(dpy, DefaultScreen(dpy));
> @@ -930,7 +933,7 @@ do_ico_window(void *ptr)
> printf("thread %x got Expose\n", xthread_self());
> #endif
> if (XGetWindowAttributes(dpy,closure->draw_window,&xwa)==0) {
> - icoFatal("cannot get window attributes (size)", NULL);
> + icoFatal("cannot get window attributes (size)");
> }
> closure->winW = xwa.width;
> closure->winH = xwa.height;
> @@ -967,7 +970,7 @@ do_ico_window(void *ptr)
> 0, 0, closure->winW, closure->winH, 0, 0);
> closure->win = closure->multibuffers[1];
> } else
> - icoFatal ("unable to obtain 2 buffers", NULL);
> + icoFatal ("unable to obtain 2 buffers");
> }
> #endif /* MULTIBUFFER */
> if (closure->win == None) closure->win = closure->draw_window;
> @@ -1288,7 +1291,7 @@ int main(int argc, const char **argv)
> }
>
> if (!dofaces && !doedges)
> - icoFatal("nothing to draw", NULL);
> + icoFatal("nothing to draw");
>
> #ifdef MULTITHREAD
> XInitThreads();
> --
> 1.7.9.2
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
More information about the xorg-devel
mailing list