Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Feb 2004 10:09:03 +0100
From:      des@des.no (Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=)
To:        hackers@freebsd.org
Subject:   how to fool gcc?
Message-ID:  <xzpad3r5mj4.fsf@dwp.des.no>

next in thread | raw e-mail | index | archive | help
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) =3D=3D 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:

cc -O -pipe -march=3Dpentium2 -I/usr/src/lib/libpam/libpam -I/home/des/proj=
ects/openpam/include -DLIB_MAJ=3D2 -g -DDEBUG -Wsystem-headers -Werror -Wal=
l -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes -Wpointer-ari=
th -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align=
 -Wbad-function-cast -Wchar-subscripts -Winline -Wnested-externs -Wredundan=
t-decls -c /home/des/projects/openpam/lib/openpam_get_option.c
/home/des/projects/openpam/lib/openpam_get_option.c: In function `openpam_g=
et_option':
/home/des/projects/openpam/lib/openpam_get_option.c:62: warning: reading th=
rough null pointer (arg 4)
/home/des/projects/openpam/lib/openpam_get_option.c:73: warning: reading th=
rough null pointer (arg 4)
*** Error code 1

Stop in /usr/src/lib/libpam/libpam.

I've tried various twists to fool gcc, such as casting (s) to (const
char *) and adding 0 to it hoping that the addition would defeat its
NULL pointer check.  Nothing I've tried works, though, and I would
really hate to have to lower the WANRS level just for this.

Any suggestions?

DES
--=20
Dag-Erling Sm=F8rgrav - des@des.no



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpad3r5mj4.fsf>