Re: [linux-audio-dev] one for the C++ gurus

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] one for the C++ gurus
From: Paul Davis (pbd_AT_Op.Net)
Date: Tue Mar 12 2002 - 16:28:17 EET


> #ifndef _ERRORMACRO_H_SATIE
> #define _ERRORMACRO_H_SATIE
>
> #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
> #define error(...) do {\
> sprintf(loggermsgbuffer, "%s:%s:%d: ",__FILE__, __FUNCTION__,
>__LINE__); \
> sprintf(loggermsgbuffer2, __VA_ARGS__); \
> mainlog.logmessage(loggermsgbuffer, loggermsgbuffer2,
>mainlog.debug); \
> } while (0)

i haven't used gcc's varargs macros, but from reading the info file
for gcc on this, this macro seems wrong. according to that, it should
be something like:

   #define error(format,args...) do {\
          sprintf(loggermsgbuffer, "%s:%s:%d: ",__FILE__, __FUNCTION__, __LINE__); \
          sprintf(loggermsgbuffer2, format, ## args); \
          mainlog.logmessage(loggermsgbuffer, loggermsgbuffer2, mainlog.debug); \
   } while (0)

this assumes that the way the error macro is used is:

     error ("the value %d is wrong - here's why: %s", value, msg);

it would be even better to use snprintf to avoid buffer overflows:

   #define error(format,args...) do {\
          snprintf(loggermsgbuffer, sizeof(loggermsgbuffer), "%s:%s:%d: ",__FILE__, __FUNCTION__, __LINE__); \
          snprintf(loggermsgbuffer2, sizeof(loggermsgbuffer2), format, ## args); \
          mainlog.logmessage(loggermsgbuffer, loggermsgbuffer2, mainlog.debug); \
   } while (0)


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Tue Mar 12 2002 - 16:16:24 EET