[PATCH] dmx: Annotate dmxlog.c with _X_ATTRIBUTE_PRINTF

Peter Hutterer peter.hutterer at who-t.net
Wed Apr 25 22:20:57 PDT 2012


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>
> ---
>  hw/dmx/dmxlog.c |   31 ++++++++++++++++---------------
>  1 file changed, 16 insertions(+), 15 deletions(-)
> 
> diff --git a/hw/dmx/dmxlog.c b/hw/dmx/dmxlog.c
> index 33aee59..c7d64db 100644
> --- a/hw/dmx/dmxlog.c
> +++ b/hw/dmx/dmxlog.c
> @@ -72,7 +72,7 @@ dmxGetLogLevel(void)
>   * program, then the ultimate output routines have to be defined.  */
>  
>  /** 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.

Cheers,
  Peter

>  {
>      va_list args;
> @@ -85,7 +85,7 @@ ErrorF(const char *format, ...)
>  }
>  
>  /** Provide an VFatalError function when used stand-alone. */
> -static void
> +static void _X_ATTRIBUTE_PRINTF(1, 0) _X_NORETURN
>  VFatalError(const char *format, va_list args)
>  {
>      vfprintf(stderr, format, args);     /* RATS: We assume the format string
> @@ -95,7 +95,7 @@ VFatalError(const char *format, va_list args)
>  }
>  
>  /** Provide an VErrorF function when used stand-alone. */
> -void
> +void _X_ATTRIBUTE_PRINTF(1, 0)
>  VErrorF(const char *format, va_list args)
>  {
>      vfprintf(stderr, format, args);     /* RATS: We assume the format string
> @@ -104,8 +104,8 @@ 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);
> -static void
> +extern void AbortServer(void) _X_NORETURN;
> +static void _X_ATTRIBUTE_PRINTF(1, 0) _X_NORETURN
>  VFatalError(const char *format, va_list args)
>  {
>      VErrorF(format, args);
> @@ -162,7 +162,7 @@ dmxHeader(dmxLogLevel logLevel, DMXInputInfo * dmxInput,
>  
>  /* Prints the error message with the appropriate low-level X output
>   * routine. */
> -static void
> +static void _X_ATTRIBUTE_PRINTF(2, 0)
>  dmxMessage(dmxLogLevel logLevel, const char *format, va_list args)
>  {
>      if (logLevel == dmxFatal || logLevel >= dmxCurrentLogLevel) {
> @@ -175,7 +175,7 @@ dmxMessage(dmxLogLevel logLevel, const char *format, va_list args)
>  
>  /** Log the specified message at the specified \a logLevel.  \a format
>   * can be a printf-like format expression. */
> -void
> +void _X_ATTRIBUTE_PRINTF(2, 3)
>  dmxLog(dmxLogLevel logLevel, const char *format, ...)
>  {
>      va_list args;
> @@ -187,7 +187,7 @@ dmxLog(dmxLogLevel logLevel, const char *format, ...)
>  }
>  
>  /** Continue a log message without printing the message prefix. */
> -void
> +void _X_ATTRIBUTE_PRINTF(2, 3)
>  dmxLogCont(dmxLogLevel logLevel, const char *format, ...)
>  {
>      va_list args;
> @@ -201,7 +201,7 @@ dmxLogCont(dmxLogLevel logLevel, const char *format, ...)
>  /** Log an informational message (at level #dmxInfo) related to ouput.
>   * The message prefix will contain backend information from \a
>   * dmxScreen. */
> -void
> +void _X_ATTRIBUTE_PRINTF(2, 3)
>  dmxLogOutput(DMXScreenInfo * dmxScreen, const char *format, ...)
>  {
>      va_list args;
> @@ -214,7 +214,7 @@ dmxLogOutput(DMXScreenInfo * dmxScreen, const char *format, ...)
>  
>  /** Continue a message related to output without printing the message
>   * prefix. */
> -void
> +void _X_ATTRIBUTE_PRINTF(2, 3)
>  dmxLogOutputCont(DMXScreenInfo * dmxScreen, const char *format, ...)
>  {
>      va_list args;
> @@ -227,7 +227,7 @@ dmxLogOutputCont(DMXScreenInfo * dmxScreen, const char *format, ...)
>  /** Log a warning message (at level #dmxWarning) related to output.
>   * The message prefix will contain backend information from \a
>   * dmxScreen. */
> -void
> +void _X_ATTRIBUTE_PRINTF(2, 3)
>  dmxLogOutputWarning(DMXScreenInfo * dmxScreen, const char *format, ...)
>  {
>      va_list args;
> @@ -240,7 +240,7 @@ dmxLogOutputWarning(DMXScreenInfo * dmxScreen, const char *format, ...)
>  
>  /** Log an informational message (at level #dmxInfo) related to input.
>   * The message prefix will contain information from \a dmxInput. */
> -void
> +void _X_ATTRIBUTE_PRINTF(2, 3)
>  dmxLogInput(DMXInputInfo * dmxInput, const char *format, ...)
>  {
>      va_list args;
> @@ -253,7 +253,7 @@ dmxLogInput(DMXInputInfo * dmxInput, const char *format, ...)
>  
>  /** Continue a message related to input without printing the message
>   * prefix. */
> -void
> +void _X_ATTRIBUTE_PRINTF(2, 3)
>  dmxLogInputCont(DMXInputInfo * dmxInput, const char *format, ...)
>  {
>      va_list args;
> @@ -300,10 +300,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 +312,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,
> -- 
> 1.7.9.5
> 



More information about the xorg-devel mailing list