From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 10 01:29:32 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D5DEC16A4CE for ; Tue, 10 Feb 2004 01:29:32 -0800 (PST) Received: from mail.ut.caldera.com (mail.ut.caldera.com [216.250.130.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9218B43D1F for ; Tue, 10 Feb 2004 01:29:32 -0800 (PST) (envelope-from hmohanan@sco.com) Received: (qmail 12558 invoked from network); 10 Feb 2004 09:29:32 -0000 Received: from vms.caldera.com (216.250.130.31) by mail.ut.caldera.com with SMTP; 10 Feb 2004 09:29:32 -0000 Received: from vms.caldera.com (localhost [127.0.0.1]) by localhost (Postfix) with ESMTP id 4D4F1A005; Tue, 10 Feb 2004 02:29:31 -0700 (MST) Received: from sco.com (unknown [192.168.248.41]) by vms.caldera.com (Postfix) with ESMTP id 5C7CAA002; Tue, 10 Feb 2004 02:29:28 -0700 (MST) Message-ID: <4028A463.4090001@sco.com> Date: Tue, 10 Feb 2004 14:59:07 +0530 From: Harish Mohanan User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?ISO-8859-1?Q?Dag-Erling_Sm=F8rgrav?= References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit cc: hackers@freebsd.org Subject: Re: how to fool gcc? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Feb 2004 09:29:33 -0000 try compiling without optimisation i.e. without the -O flag to gcc. Harish Dag-Erling Smørgrav wrote: >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: > >cc -O -pipe -march=pentium2 -I/usr/src/lib/libpam/libpam -I/home/des/projects/openpam/include -DLIB_MAJ=2 -g -DDEBUG -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wbad-function-cast -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -c /home/des/projects/openpam/lib/openpam_get_option.c >/home/des/projects/openpam/lib/openpam_get_option.c: In function `openpam_get_option': >/home/des/projects/openpam/lib/openpam_get_option.c:62: warning: reading through null pointer (arg 4) >/home/des/projects/openpam/lib/openpam_get_option.c:73: warning: reading through 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 > >