Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WLdUE-0003in-HY for pgsql-odbc@arkaria.postgresql.org; Thu, 06 Mar 2014 18:57:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WLdUE-0000yQ-1e for pgsql-odbc@arkaria.postgresql.org; Thu, 06 Mar 2014 18:57:42 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WLdUD-0000yK-CK for pgsql-odbc@postgresql.org; Thu, 06 Mar 2014 18:57:41 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WLdU9-0006mV-FB for pgsql-odbc@postgresql.org; Thu, 06 Mar 2014 18:57:40 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 2B1F228472; Thu, 6 Mar 2014 10:57:36 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 2656DB0327; Thu, 6 Mar 2014 10:57:36 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 94C5EC0062; Thu, 6 Mar 2014 10:57:33 -0800 (PST) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA; Thu, 6 Mar 2014 10:57:30 -0800 (PST) Message-ID: <5318C519.7020209@vmware.com> Date: Thu, 06 Mar 2014 20:57:29 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10 MIME-Version: 1.0 To: Tom Lane CC: Michael Paquier , PostgreSQL mailing lists Subject: Re: Elimination of (more or less) all compilation warnings on OSX References: <53187E62.4080907@vmware.com> <53189C96.1050609@vmware.com> <27047.1394124651@sss.pgh.pa.us> In-Reply-To: <27047.1394124651@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="------------030106080801010808050804" X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org This is a multi-part message in MIME format. --------------030106080801010808050804 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 03/06/2014 06:50 PM, Tom Lane wrote: > Heikki Linnakangas writes: >> It's worth noting that isspace, isdigit etc. take an "unsigned char" >> argument. The compiler won't warn if you pass a "char", so you have to >> be careful with that. In practice, I don't think it will lead to actual >> bugs on any real platform and locale, but still.. > > It definitely used to lead to bugs on some old platforms. It may be > that everybody is more careful nowadays, but the POSIX spec is still > perfectly clear about it: > > The c argument is an int, the value of which the application > shall ensure is a character representable as an unsigned char or > equal to the value of the macro EOF. If the argument has any > other value, the behavior is undefined. > > I had my old HPUX box hacked up so that gcc would produce "subscript > is a char" warnings for unsafe usage. It seems a bit more difficult to > get modern platforms to do that, though; people stopped exposing the > underlying flag array in the system headers ... A-ha, clever. I bet we could do something similar with modern compilers too. Searching around, I found this trick (from https://stackoverflow.com/questions/4712720/typechecking-macro-arguments-in-c): > #define CHECK_TYPE(var, type) \ > { \ > __typeof(var) *__tmp; \ > __tmp = (type *) NULL; \ > (void) __tmp; /* to avoid "set but not used" warnings */ \ > } The idea is to create a pointer variable that has the same type as the argument, and assign an unsigned char value to it. With -Wpointer-sign, gcc will complain. That's not portable, but that's OK. If we can get some compilers to complain, that's enough. With that, we can do: #ifdef isalnum #undef isalnum #endif #define isalnum(x) ((CHECK_TYPE(x, unsigned char)), isalnum(x)) I did that for all the is* routines, and unsurprisingly there were a bunch of places were we got that wrong in psqlodbc. I'll fix those after we get the minor release out. I'll also try that on the PostgreSQL sources. - Heikki --------------030106080801010808050804 Content-Type: text/x-diff; name="warn-on-signed-arg-to-isalnum-and-friends-1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="warn-on-signed-arg-to-isalnum-and-friends-1.patch" diff --git a/psqlodbc.h b/psqlodbc.h index 0468e0a..785b6eb 100644 --- a/psqlodbc.h +++ b/psqlodbc.h @@ -9,6 +9,68 @@ #ifndef __PSQLODBC_H__ #define __PSQLODBC_H__ +#include + +#define CHECK_TYPE(var, type) \ + { \ + __typeof(var) *__tmp; \ + __tmp = (type *) NULL; \ + (void) __tmp; /* to avoid "set but not used" warnings */ \ + } + +#ifdef isalnum +#undef isalnum +#endif +#define isalnum(x) ((CHECK_TYPE(x, unsigned char)), isalnum(x)) +#ifdef isalpha +#undef isalpha +#endif +#define isalpha(x) ((CHECK_TYPE(x, unsigned char)), isalpha(x)) +#ifdef isascii +#undef isascii +#endif +#define isascii(x) ((CHECK_TYPE(x, unsigned char)), isascii(x)) +#ifdef isblank +#undef isblank +#endif +#define isblank(x) ((CHECK_TYPE(x, unsigned char)), isblank(x)) +#ifdef iscntrl +#undef iscntrl +#endif +#define iscntrl(x) ((CHECK_TYPE(x, unsigned char)), iscntrl(x)) +#ifdef isdigit +#undef isdigit +#endif +#define isdigit(x) ((CHECK_TYPE(x, unsigned char)), isdigit(x)) +#ifdef isgraph +#undef isgraph +#endif +#define isgraph(x) ((CHECK_TYPE(x, unsigned char)), isgraph(x)) +#ifdef islower +#undef islower +#endif +#define islower(x) ((CHECK_TYPE(x, unsigned char)), islower(x)) +#ifdef isprint +#undef isprint +#endif +#define isprint(x) ((CHECK_TYPE(x, unsigned char)), isprint(x)) +#ifdef ispunct +#undef ispunct +#endif +#define ispunct(x) ((CHECK_TYPE(x, unsigned char)), ispunct(x)) +#ifdef isspace +#undef isspace +#endif +#define isspace(x) ((CHECK_TYPE(x, unsigned char)), isspace(x)) +#ifdef isupper +#undef isupper +#endif +#define isupper(x) ((CHECK_TYPE(x, unsigned char)), isupper(x)) +#ifdef isxdigit +#undef isxdigit +#endif +#define isxdigit(x) ((CHECK_TYPE(x, unsigned char)), isxdigit(x)) + /* #define __MS_REPORTS_ANSI_CHAR__ */ #ifndef WIN32 --------------030106080801010808050804 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc --------------030106080801010808050804--