how to fool gcc?

Zajcev Evgeny zevlg at yandex.ru
Tue Feb 10 02:42:53 PST 2004


des at des.no (Dag-Erling SmЬrgrav) writes:

> I'm having trouble with some uncommitted OpenPAM patches that I'd like
> to get into the tree.  The problem actually doesn't occur with a
> normal build, but it prevents me from building a debugging version of
> libpam.
>
> Part of the patch declares openpam_log(3) as printf-like so gcc can
> check format strings etc.  However, openpam_log(3) is also used in
> debugging macros such as this:
>
> #define RETURNS(s) do { \
>         if ((s) == NULL) \
>                 openpam_log(PAM_LOG_DEBUG, "returning NULL"); \
>         else \
>                 openpam_log(PAM_LOG_DEBUG, "returning '%s'", (s)); \
>         return (s); \
> } while (0)
>
> The problem is that when it encounters RETURNS(NULL), gcc complains
> that I'm passing a NULL argument to printf(3), even though it should
> be obvious that I'm not:
>

Maybe just have copy of `s' inside while statement?  Something like:

> #define RETURNS(s) do { \
>         if ((s) == NULL) \
>                 openpam_log(PAM_LOG_DEBUG, "returning NULL"); \
>         else \
>                 openpam_log(PAM_LOG_DEBUG, "returning '%s'", (s)); \
>         return (s); \
> } while (0)

-- 
lg


More information about the freebsd-hackers mailing list