Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2709240ybh; Mon, 9 Mar 2020 11:22:13 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu99oIC4uQp5cfRxscMmHdGez412Wdd8rHaRq8kInPYOAVn3BA/aotXt60Gi/ex5MfYqE7o X-Received: by 2002:a9d:53c4:: with SMTP id i4mr14667730oth.48.1583778133092; Mon, 09 Mar 2020 11:22:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583778133; cv=none; d=google.com; s=arc-20160816; b=xFSeViHBFmPGp8kBXWmtS4lAvPX8CNUXrhkp/xxha9s9Zv1hkCQwbQN/PIRiyU4/98 ocPGadd3CoZSGEeprL9WkZmxvVc1WX3SvWwS65fpXmfDxgyPUUNOdidFo6WD2PqQ8pKK dbVzyPnnkhDHEPt/jNKreWDbOUtuVTgYftNTCrmRocmHY8igXjKuKDydFRD9ijIZJ2Sb d1piNsm6RbZxvm5ZYV/nRTskOu4N/angIZO3XnO65XtMrBYEmLS22YASaBoseka9i1Z0 yKNF1VBtLji2EjwGdHx5NoUL1pgiXqA62etllt/7iCR+JQqwCuZgym2k2V7cD9J32aUF AL6A== 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=63jw/prEVJock7mXqnT82GLzheK/ipgQZ6xG7DJdzt8=; b=qeSAWK3UdxSiUCCyraYalUbTgCL2NN3FWxInClxINQKwWciQtT1DejNT3v/ZAebEaS KWPCIOj3TcXXY/auyA5093mYjvjg1ktlrL22UBmwFcStkXz0+EnHa5lsidSiNbL1kxpd 6f2SdqMSgBOlMJ/P+H02WkwoGfRJMLzENPO0dh4+jxnmT/vZ/3AopwuKMygKL67rL5Ho 2YMUCG1BC75d37uaMTpkFb8NvfkxIZT2B6w+lH/pXz2A3sFN9VdGBbkNPZIauPnmUXdh sSMgyfjcYZH4eJbGTvkGLb3AHpXavuR1lGaGPpLrzjcFFXsSzwVQbl6RAhtwoef3SVTJ B/ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=U3mVtLLU; 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 l65si1788197oig.156.2020.03.09.11.22.01; Mon, 09 Mar 2020 11:22:13 -0700 (PDT) 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=U3mVtLLU; 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 S1727460AbgCISVl (ORCPT + 99 others); Mon, 9 Mar 2020 14:21:41 -0400 Received: from gateway34.websitewelcome.com ([192.185.148.142]:33734 "EHLO gateway34.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727323AbgCISVk (ORCPT ); Mon, 9 Mar 2020 14:21:40 -0400 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 7F633532C7 for ; Mon, 9 Mar 2020 13:19:58 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id BN0QjRLHPRP4zBN0QjnpbW; Mon, 09 Mar 2020 13:19:58 -0500 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=63jw/prEVJock7mXqnT82GLzheK/ipgQZ6xG7DJdzt8=; b=U3mVtLLU9t4qqmh6bUX4Q6KiKe 3GfIRllL3lkcjyiAQ+3noBaZOHMAk+aOZ+xFRJsiVRKhoICwsZq0eQ9FZ4sSdGbro6fCjwOCcpW8a i1TcWMcAcXTaTQo0VX6oDDlU3vIjQbiSLNn9SSdi2HGfvW51EC7H5NrGQpaT28ETmxJ/TQRl8uRU0 9lfipkv0hyLKfdznBPfdQSPznKUz2xvZJEIVF7HYoSZCwRQxCYycI0ky/dLpGyH5lKKNedneJLG+J yrbPqxq9PMmufQ+iObTvRfR57cU5oZci0LfDlGZtqnQxcuOL5OTpHB9ZRKnbkFKjdVpVc01Eq88lv H82vd/1w==; Received: from [201.162.240.150] (port=1609 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.92) (envelope-from ) id 1jBN0O-004KYO-Ii; Mon, 09 Mar 2020 13:19:57 -0500 Date: Mon, 9 Mar 2020 13:23:08 -0500 From: "Gustavo A. R. Silva" To: Dave Kleikamp Cc: jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] jfs: Replace zero-length array with flexible-array member Message-ID: <20200309182308.GA5087@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: 201.162.240.150 X-Source-L: No X-Exim-ID: 1jBN0O-004KYO-Ii X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [201.162.240.150]:1609 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 27 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 --- fs/jfs/jfs_dtree.c | 2 +- fs/jfs/jfs_xattr.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c index 3acc954f7c04..837d42f61464 100644 --- a/fs/jfs/jfs_dtree.c +++ b/fs/jfs/jfs_dtree.c @@ -2964,7 +2964,7 @@ struct jfs_dirent { loff_t position; int ino; u16 name_len; - char name[0]; + char name[]; }; /* diff --git a/fs/jfs/jfs_xattr.h b/fs/jfs/jfs_xattr.h index f0558b3348da..c50167a7bc50 100644 --- a/fs/jfs/jfs_xattr.h +++ b/fs/jfs/jfs_xattr.h @@ -17,12 +17,12 @@ struct jfs_ea { u8 flag; /* Unused? */ u8 namelen; /* Length of name */ __le16 valuelen; /* Length of value */ - char name[0]; /* Attribute name (includes null-terminator) */ + char name[]; /* Attribute name (includes null-terminator) */ }; /* Value immediately follows name */ struct jfs_ea_list { __le32 size; /* overall size */ - struct jfs_ea ea[0]; /* Variable length list */ + struct jfs_ea ea[]; /* Variable length list */ }; /* Macros for defining maxiumum number of bytes supported for EAs */ -- 2.25.0