From owner-freebsd-bugs@FreeBSD.ORG Mon Mar 4 01:50:01 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 357DCE22 for ; Mon, 4 Mar 2013 01:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 184B1294 for ; Mon, 4 Mar 2013 01:50:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.6/8.14.6) with ESMTP id r241o05l091983 for ; Mon, 4 Mar 2013 01:50:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.6/8.14.6/Submit) id r241o0q3091982; Mon, 4 Mar 2013 01:50:00 GMT (envelope-from gnats) Resent-Date: Mon, 4 Mar 2013 01:50:00 GMT Resent-Message-Id: <201303040150.r241o0q3091982@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Dmitry Marakasov Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 68039C81 for ; Mon, 4 Mar 2013 01:44:11 +0000 (UTC) (envelope-from amdmi3@amdmi3.ru) Received: from smtp.timeweb.ru (smtp.timeweb.ru [92.53.116.57]) by mx1.freebsd.org (Postfix) with ESMTP id 251B7270 for ; Mon, 4 Mar 2013 01:44:10 +0000 (UTC) Received: from [213.148.20.85] (helo=hive.panopticon) by smtp.timeweb.ru with esmtpsa (TLS1.0:DHE_RSA_CAMELLIA_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1UCKRe-0000Uv-Ga for FreeBSD-gnats-submit@freebsd.org; Mon, 04 Mar 2013 05:44:02 +0400 Received: from hades.panopticon (hades.panopticon [192.168.0.32]) by hive.panopticon (Postfix) with ESMTP id E01DCB84D for ; Mon, 4 Mar 2013 05:44:01 +0400 (MSK) Received: by hades.panopticon (Postfix, from userid 1000) id 603DB48E; Mon, 4 Mar 2013 05:44:01 +0400 (MSK) Message-Id: <20130304014401.603DB48E@hades.panopticon> Date: Mon, 4 Mar 2013 05:44:01 +0400 (MSK) From: Dmitry Marakasov To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: misc/176628: [stdint.h] use safer way of definint __WORDSIZE X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Dmitry Marakasov List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Mar 2013 01:50:01 -0000 >Number: 176628 >Category: misc >Synopsis: [stdint.h] use safer way of definint __WORDSIZE >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Mar 04 01:50:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Dmitry Marakasov >Release: FreeBSD 9.0-RELEASE-p3 amd64 >Organization: >Environment: System: FreeBSD hades.panopticon 9.0-RELEASE-p3 FreeBSD 9.0-RELEASE-p3 #0: Wed Jun 13 17:39:20 MSK 2012 root@hades.panopticon:/usr/obj/usr/src/sys/HADES amd64 >Description: r228529 introduced __WORDSIZE macro: --- sys/sys/stdint.h +#if defined(UINTPTR_MAX) && defined(UINT64_MAX) && (UINTPTR_MAX == UINT64_MAX) +#define __WORDSIZE 64 +#else +#define __WORDSIZE 32 +#endif --- However the way it's defined is utterly unsafe: when UINTPTR_MAX or UINT64_MAX are not defined (which is the case for C++, as their definitions in e.g. x86/_stint.h are wrapped in #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) __WORDSIZE is always defined as 32, which is wrong on 64bit systems. I have two solutions for the problem. First one uses the same way of testing for 64bit pointers, but doesn't define __WORDSIZE if it can't be detected reliably. Second one uses different way of testing for 64bit pointers with checking for __LP64__. The second one looks much more useful, but I'm not sure if __LP64__ has the right semantics and will work in all platforms. Also, can't it just be unconditionally defined to (sizeof(int*)*8)? >How-To-Repeat: >Fix: --- wordsize.patch begins here --- diff --git sys/sys/stdint.h sys/sys/stdint.h index 762e879..de10869 100644 --- sys/sys/stdint.h +++ sys/sys/stdint.h @@ -65,10 +65,12 @@ typedef __uintmax_t uintmax_t; #endif /* GNU and Darwin define this and people seem to think it's portable */ -#if defined(UINTPTR_MAX) && defined(UINT64_MAX) && (UINTPTR_MAX == UINT64_MAX) -#define __WORDSIZE 64 -#else -#define __WORDSIZE 32 +#if defined(UINTPTR_MAX) && defined(UINT64_MAX) +# if UINTPTR_MAX == UINT64_MAX +# define __WORDSIZE 64 +# else +# define __WORDSIZE 32 +# endif #endif /* Limits of wchar_t. */ --- wordsize.patch ends here --- --- wordsize.1.patch begins here --- diff --git sys/sys/stdint.h sys/sys/stdint.h index 762e879..b921b99 100644 --- sys/sys/stdint.h +++ sys/sys/stdint.h @@ -65,7 +65,7 @@ typedef __uintmax_t uintmax_t; #endif /* GNU and Darwin define this and people seem to think it's portable */ -#if defined(UINTPTR_MAX) && defined(UINT64_MAX) && (UINTPTR_MAX == UINT64_MAX) +#if defined(__LP64__) #define __WORDSIZE 64 #else #define __WORDSIZE 32 --- wordsize.1.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: