From patchwork Thu Oct 12 01:54:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: flashrom-git@coreboot.org X-Patchwork-Id: 824648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=flashrom.org (client-ip=80.81.252.135; helo=mail.coreboot.org; envelope-from=flashrom-bounces@flashrom.org; receiver=) Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yCDTP5Ngzz9t2S for ; Thu, 12 Oct 2017 12:55:52 +1100 (AEDT) Received: from [127.0.0.1] (helo=ra.coreboot.org) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1e2Shp-0006t6-16; Thu, 12 Oct 2017 03:54:37 +0200 Received: from flashrom-git by mail.coreboot.org with local (Exim 4.86_2) (envelope-from ) id 1e2Shn-0006s6-3R for flashrom@flashrom.org; Thu, 12 Oct 2017 03:54:35 +0200 Date: Thu, 12 Oct 2017 03:54:35 +0200 To: flashrom@flashrom.org MIME-Version: 1.0 From: flashrom-git@coreboot.org In-Reply-To: <150777327502.26364.14546710967404495772@ra.coreboot.org> References: <150777327502.26364.14546710967404495772@ra.coreboot.org> X-Git-Host: ra.coreboot.org X-Git-Repo: flashrom X-Git-Refname: refs/heads/stable X-Git-Reftype: branch X-Git-Rev: 51e430392d125ad7b36ec43e1448f3235d221b39 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.4.dev Auto-Submitted: auto-generated Message-Id: Subject: [flashrom] 01/01: Fix undefined behavior in some preprocessor define checks X-BeenThere: flashrom@flashrom.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: flashrom discussion and development mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: flashrom@flashrom.org Errors-To: flashrom-bounces@flashrom.org Sender: "flashrom" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff This is an automated email from the git hooks/post-receive script. flashrom-git pushed a commit to branch stable in repository flashrom. View the commit online: https://www.flashrom.org/git/flashrom.git/commit/?id=51e430392d125ad7b36ec43e1448f3235d221b39 commit 51e430392d125ad7b36ec43e1448f3235d221b39 Author: Stefan Tauner AuthorDate: Fri Dec 2 02:09:23 2016 +0100 Fix undefined behavior in some preprocessor define checks Macros like the one below would produce undefined behavior when used as expression/condition in #if preprocessor directives: This patch replaces all such statements with a more verbose but well-defined #if/#define x 1/#else/#define x 0/#endif Found by clang (warning introduced in r258128), reported by Idwer. Signed-off-by: Stefan Tauner Acked-by: Carl-Daniel Hailfinger --- hwaccess.c | 18 +++++++++++++++--- platform.h | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/hwaccess.c b/hwaccess.c index 1901ee6a7..80852e71f 100644 --- a/hwaccess.c +++ b/hwaccess.c @@ -37,9 +37,21 @@ #error "Unknown operating system" #endif -#define USE_IOPL (IS_LINUX || IS_MACOSX || defined(__NetBSD__) || defined(__OpenBSD__)) -#define USE_DEV_IO (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)) -#define USE_IOPERM (defined(__gnu_hurd__)) +#if (IS_LINUX || IS_MACOSX || defined(__NetBSD__) || defined(__OpenBSD__)) + #define USE_IOPL (1) +#else + #define USE_IOPL (0) +#endif +#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)) + #define USE_DEV_IO (1) +#else + #define USE_DEV_IO (0) +#endif +#if (defined(__gnu_hurd__)) + #define USE_IOPERM (1) +#else + #define USE_IOPERM (0) +#endif #if USE_IOPERM #include diff --git a/platform.h b/platform.h index c5a52ef89..d70a6e0dd 100644 --- a/platform.h +++ b/platform.h @@ -25,9 +25,21 @@ #define __PLATFORM_H__ 1 // Helper defines for operating systems -#define IS_LINUX (defined(__gnu_linux__) || defined(__linux__)) -#define IS_MACOSX (defined(__APPLE__) && defined(__MACH__)) /* yes, both. */ -#define IS_WINDOWS (defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__WINDOWS__)) +#if (defined(__gnu_linux__) || defined(__linux__)) + #define IS_LINUX (1) +#else + #define IS_LINUX (0) +#endif +#if (defined(__APPLE__) && defined(__MACH__)) /* yes, both. */ + #define IS_MACOSX (1) +#else + #define IS_MACOSX (0) +#endif +#if (defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__WINDOWS__)) + #define IS_WINDOWS (1) +#else + #define IS_WINDOWS (0) +#endif // Likewise for target architectures #if defined (__i386__) || defined (__x86_64__) || defined(__amd64__)