[PATCH] dmx: Annotate dmxlog.c with _X_ATTRIBUTE_PRINTF

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 26 16:19:29 PDT 2012


On Thu, Apr 26, 2012 at 03:11:20PM +0200, Michal Suchanek wrote:
> On 26 April 2012 07:20, Peter Hutterer <peter.hutterer at who-t.net> wrote:
> > On Mon, Apr 23, 2012 at 07:02:29PM +0200, Michal Suchanek wrote:
> >> From c3b73397fce271cefac7a72d5be498aed516dc59 Mon Sep 17 00:00:00 2001
> >> From: Michal Suchanek <hramrach at gmail.com>
> >> Date: Mon, 23 Apr 2012 15:28:07 +0200
> >> Subject: [PATCH] dmx: Annotate dmxlog.c with _X_ATTRIBUTE_PRINTF and
> >>  _X_NORETURN
> >>
> >>   * and fix resulting printf warning in dmxLogVisua
> >>
> >> Signed-off-by: Michal Suchanek <hramrach at gmail.com>
> 
> >>  /** Provide an ErrorF function when used stand-alone. */
> >> -void
> >> +void _X_ATTRIBUTE_PRINTF(1, 0)
> >>  ErrorF(const char *format, ...)
> >
> > ack to the principle, though it seems the convention is to have the
> > attributes after the function name and in the header file. The latter
> > doesn't apply for ErrorF here, but others like dmxLogInput and friends
> > should be annotated in the header.
> 
> Yes, some of the functions are declared in the header and should be
> annotated there.
> 
> Attaching an updated patch.

merged, thanks.

Cheers,
  Peter

> From 85448cb38bab8e3afb30bdf82a718c1ac579ce12 Mon Sep 17 00:00:00 2001
> From: Michal Suchanek <hramrach at gmail.com>
> Date: Mon, 23 Apr 2012 15:28:07 +0200
> Subject: [PATCH] dmx: Annotate dmxlog.c with _X_ATTRIBUTE_PRINTF and
>  _X_NORETURN
> 
>   * and fix resulting printf warning in dmxLogVisual
> 
> Signed-off-by: Michal Suchanek <hramrach at gmail.com>
> ---
>  hw/dmx/dmxlog.c |   13 ++++++++++---
>  hw/dmx/dmxlog.h |   19 ++++++++++++-------
>  2 files changed, 22 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/dmx/dmxlog.c b/hw/dmx/dmxlog.c
> index 33aee59..3249c48 100644
> --- a/hw/dmx/dmxlog.c
> +++ b/hw/dmx/dmxlog.c
> @@ -86,6 +86,8 @@ ErrorF(const char *format, ...)
>  
>  /** Provide an VFatalError function when used stand-alone. */
>  static void
> +VFatalError(const char *format, va_list args) _X_ATTRIBUTE_PRINTF(1, 0) _X_NORETURN;
> +static void
>  VFatalError(const char *format, va_list args)
>  {
>      vfprintf(stderr, format, args);     /* RATS: We assume the format string
> @@ -104,7 +106,9 @@ VErrorF(const char *format, va_list args)
>  }
>  #else
>  /** This function was removed between XFree86 4.3.0 and XFree86 4.4.0. */
> -extern void AbortServer(void);
> +extern void AbortServer(void) _X_NORETURN;
> +static void
> +VFatalError(const char *format, va_list args) _X_ATTRIBUTE_PRINTF(1, 0) _X_NORETURN;
>  static void
>  VFatalError(const char *format, va_list args)
>  {
> @@ -163,6 +167,8 @@ dmxHeader(dmxLogLevel logLevel, DMXInputInfo * dmxInput,
>  /* Prints the error message with the appropriate low-level X output
>   * routine. */
>  static void
> +dmxMessage(dmxLogLevel logLevel, const char *format, va_list args) _X_ATTRIBUTE_PRINTF(2, 0);
> +static void
>  dmxMessage(dmxLogLevel logLevel, const char *format, va_list args)
>  {
>      if (logLevel == dmxFatal || logLevel >= dmxCurrentLogLevel) {
> @@ -300,10 +306,11 @@ dmxLogVisual(DMXScreenInfo * dmxScreen, XVisualInfo * vi, int defaultVisual)
>          class = "DirectColor";
>          break;
>      }
> +#define VisualLogFormat "0x%02lx %s %2db %db/rgb %3d 0x%04lx 0x%04lx 0x%04lx%s\n"
>  
>      if (dmxScreen) {
>          dmxLogOutput(dmxScreen,
> -                     "0x%02x %s %2db %db/rgb %3d 0x%04x 0x%04x 0x%04x%s\n",
> +                     VisualLogFormat,
>                       vi->visualid, class, vi->depth, vi->bits_per_rgb,
>                       vi->colormap_size,
>                       vi->red_mask, vi->green_mask, vi->blue_mask,
> @@ -311,7 +318,7 @@ dmxLogVisual(DMXScreenInfo * dmxScreen, XVisualInfo * vi, int defaultVisual)
>      }
>      else {
>          dmxLog(dmxInfo,
> -               "  0x%02x %s %2db %db/rgb %3d 0x%04x 0x%04x 0x%04x%s\n",
> +               "  " VisualLogFormat,
>                 vi->visualid, class, vi->depth, vi->bits_per_rgb,
>                 vi->colormap_size,
>                 vi->red_mask, vi->green_mask, vi->blue_mask,
> diff --git a/hw/dmx/dmxlog.h b/hw/dmx/dmxlog.h
> index 4d4cd26..162484b 100644
> --- a/hw/dmx/dmxlog.h
> +++ b/hw/dmx/dmxlog.h
> @@ -55,18 +55,23 @@ typedef enum {
>  /* Logging functions used by Xserver/hw/dmx routines. */
>  extern dmxLogLevel dmxSetLogLevel(dmxLogLevel newLevel);
>  extern dmxLogLevel dmxGetLogLevel(void);
> -extern void dmxLog(dmxLogLevel logLevel, const char *format, ...);
> -extern void dmxLogCont(dmxLogLevel logLevel, const char *format, ...);
> +extern void dmxLog(dmxLogLevel logLevel, const char *format,
> +                             ...) _X_ATTRIBUTE_PRINTF(2, 3);
> +extern void dmxLogCont(dmxLogLevel logLevel, const char *format,
> +                             ...) _X_ATTRIBUTE_PRINTF(2, 3);
>  extern const char *dmxEventName(int type);
>  
>  #ifndef DMX_LOG_STANDALONE
> -extern void dmxLogOutput(DMXScreenInfo * dmxScreen, const char *format, ...);
> +extern void dmxLogOutput(DMXScreenInfo * dmxScreen, const char *format,
> +                             ...) _X_ATTRIBUTE_PRINTF(2, 3);
>  extern void dmxLogOutputCont(DMXScreenInfo * dmxScreen, const char *format,
> -                             ...);
> +                             ...) _X_ATTRIBUTE_PRINTF(2, 3);
>  extern void dmxLogOutputWarning(DMXScreenInfo * dmxScreen, const char *format,
> -                                ...);
> -extern void dmxLogInput(DMXInputInfo * dmxInput, const char *format, ...);
> -extern void dmxLogInputCont(DMXInputInfo * dmxInput, const char *format, ...);
> +                             ...) _X_ATTRIBUTE_PRINTF(2, 3);
> +extern void dmxLogInput(DMXInputInfo * dmxInput, const char *format,
> +                             ...) _X_ATTRIBUTE_PRINTF(2, 3);
> +extern void dmxLogInputCont(DMXInputInfo * dmxInput, const char *format,
> +                             ...) _X_ATTRIBUTE_PRINTF(2, 3);
>  extern void dmxLogArgs(dmxLogLevel logLevel, int argc, char **argv);
>  extern void dmxLogVisual(DMXScreenInfo * dmxScreen, XVisualInfo * vi,
>                           int defaultVisual);
> -- 
> 1.7.9.5
> 



More information about the xorg-devel mailing list