Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp660552ybv; Thu, 13 Feb 2020 07:20:41 -0800 (PST) X-Google-Smtp-Source: APXvYqyPa7f3IOMWx0NZ/ngWH5BAAsro+7lt42d0r3b1U9W0BanuG7U43J/8L3riSnrH58suwrEq X-Received: by 2002:a54:4705:: with SMTP id k5mr487701oik.154.1581607241253; Thu, 13 Feb 2020 07:20:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581607241; cv=none; d=google.com; s=arc-20160816; b=miaMOwnoTaZLJ8x3ezJ2gJ6wv7XQcVaoOli47tvIQaK/LG8j71paQ1IUjM/6RjuxJw S/czk9xgBxOxOcyFjWCEVSGiGWN9wLSTgGwSYoYSnJbVP7+Yj5E3oK6IIgY9yxKqZvbP FFBEcbN2MrfduxH888hcct1WV5yHOxrDr3J+VLZwe9ABGYNVnsSkG7VL3FYKEXUSRKlD puNiyhNW3JdZB32F+5d7U4dHeLNN17cMBuBz2wFGoTxjiHsM6mCYihqaXyyErw9dtnR+ lWTDHOJvlAGXEFGoNb2QIXQp0QvGBO393UasULU2SfVeTtMbMf1u1psPk/pdoUQBaKFX WpZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=FzwndPNG9cL8oQtA52+rBVe5lruQNhcNOn+JDkai228=; b=sX8H1MwGinxgIiBSkaXMxr+ewQK6m0AU3KPwiE11Six6s4e/XXKOP9KNMk7+Sx+WRi 6YB6SQuPQah7NmPN76zFYM7pqgbMcTIeuMFWCPRolCzEjTGd0kF5VS3Y5FNTm6ZHlb3Q WWXj+tS+eM7hulSZVR3X9Ga/td7IZdAIMSbhD1hgiQ8UbmTas+T3bvpmr7B6tc4/oR6m blKA+4Hd9gszd42nvtx8UertZGeoKGdoEuo5py7DdknMcYUvgruTKnR+FrDEJUjy9Vtv DLsVQh8+JEvYIrILLx1BzO1AqHTeM9ocEzT7e5vXPKtNU8v/0gSS3B3V5Cn5qFozxz5Y 3KrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=EGPpPhRY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si1384709otk.234.2020.02.13.07.20.28; Thu, 13 Feb 2020 07:20:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=EGPpPhRY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727690AbgBMPUP (ORCPT + 99 others); Thu, 13 Feb 2020 10:20:15 -0500 Received: from gateway24.websitewelcome.com ([192.185.51.202]:29849 "EHLO gateway24.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725781AbgBMPUP (ORCPT ); Thu, 13 Feb 2020 10:20:15 -0500 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 74AA826C53 for ; Thu, 13 Feb 2020 09:20:06 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 2GHejKvRhRP4z2GHejmOYb; Thu, 13 Feb 2020 09:20:06 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Type:MIME-Version:Message-ID:Subject: Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=FzwndPNG9cL8oQtA52+rBVe5lruQNhcNOn+JDkai228=; b=EGPpPhRYbskr6+VmGSSowwhgSS 9xIje5KbQw7090l6jCfXnLcyAUhOT03gaAeAlpVdLeZBIlk181fQ+SuoFXZhwVGcjhbv2TkRJepoH 2iK0H1JfjzliWgwCrfBd8/yhcSkokWXt7szg/FfrK8m72TEP3Zhqk+WunpEyBxKZlPgH3mv53ppQJ iLaVhL0zGjK8aqdy4m1FMFoT32LQ/6H/4P89OGDrgzy7JuL2dg9yuYDqhmw430/Q9uY6pgK6JD8MT M5Y/EzydgpeKCe8twYrmStpmJi7yYj8FI5WLIXnMXkSE7RocZ1nxz+ejeg4SbHoOA8esiytzJoZsK nux3Jrcg==; Received: from [200.68.140.15] (port=13063 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.92) (envelope-from ) id 1j2GHc-003Adg-P2; Thu, 13 Feb 2020 09:20:04 -0600 Date: Thu, 13 Feb 2020 09:22:41 -0600 From: "Gustavo A. R. Silva" To: Peter Oberparleiter Cc: linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] gcov: gcc_4_7: Replace zero-length array with flexible-array member Message-ID: <20200213152241.GA877@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 200.68.140.15 X-Source-L: No X-Exim-ID: 1j2GHc-003Adg-P2 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [200.68.140.15]:13063 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 21 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] https://github.com/KSPP/linux/issues/21 [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva --- kernel/gcov/gcc_4_7.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/gcov/gcc_4_7.c b/kernel/gcov/gcc_4_7.c index ec37563674d6..908fdf5098c3 100644 --- a/kernel/gcov/gcc_4_7.c +++ b/kernel/gcov/gcc_4_7.c @@ -68,7 +68,7 @@ struct gcov_fn_info { unsigned int ident; unsigned int lineno_checksum; unsigned int cfg_checksum; - struct gcov_ctr_info ctrs[0]; + struct gcov_ctr_info ctrs[]; }; /** -- 2.25.0