Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp978959ybj; Thu, 7 May 2020 11:53:53 -0700 (PDT) X-Google-Smtp-Source: APiQypLaUfZ283GrQ7O5MJ7BpWQQLqS9xHwihT46m0zkSumeyppf/WmL8ZAdi2tobDG3EzkQKIM4 X-Received: by 2002:a17:906:f106:: with SMTP id gv6mr13799242ejb.271.1588877633260; Thu, 07 May 2020 11:53:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588877633; cv=none; d=google.com; s=arc-20160816; b=vFjITYCcAJ0aswNAfB4TGJGDIf1BGNyYumUrWq8yTTOuB7AYwiOJz6ou3W0iFxhE08 b9gAn82HtsEjRz1bnEiRFW/XGkOchDim3h/hGa608xIee4AqDdBopjvkaxkPSQY1CwjE 72evxv3GRWWZ6UMNcjR3d+4IOvd8kYkyBT2XjnXlncvIOQ6QRroUoutpxn6+GdodLcdD BOxFhnQtnYEQkBUKhwbAGxCR7pY7s6XjYFGkzMGSSE1sUNFNIOHrbI0sLMJYgUGfQVxh 3GniFAJoI7WYUi9r8nv5gN6ikXTxacJjtHKJl8r4MvRELc0bY85ChwcoUgW5TB5OCf6x rR8w== 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=jtypifITs4jz30YSDwn730jf/jq8oxYXcUXFUR1cG8I=; b=nYW1yiqxPgkdpXY3BaTgzO2V1bpJUeeiTzVuW+TpcPQPN+6uq9uXXonCTU9jQQuRgL 3yZeD87rkxommbNQ8rHvuA2ti9rxzcEZpx+eGUwr7DDzU7/spjdaiY6tsKQ1F473J1l9 t9NJlecvQujxv1eW+eai3h7JVAjisdSGjn+wkA7Gmdc2lWkyvsf6BV0X2qdA2tpkqmAO 3ohepvNGOGaY/FtW1mA7KE0y8fv8XzIuCxlA1uAGZ4ODOZNzZDlN44yUnT+J8xLfNEjy rzdDYVlXCNvnMuRafXFjPNAYKzVYnfZXc/5MPZPbwxoqhtAUWz7ZFliG4deaDymriwMr I6og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JCrk0uww; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pv20si3930327ejb.295.2020.05.07.11.53.29; Thu, 07 May 2020 11:53:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JCrk0uww; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728267AbgEGSvZ (ORCPT + 99 others); Thu, 7 May 2020 14:51:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:52192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727964AbgEGSvY (ORCPT ); Thu, 7 May 2020 14:51:24 -0400 Received: from embeddedor (unknown [189.207.59.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9977A2495D; Thu, 7 May 2020 18:51:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588877483; bh=kMFA0b6aS1twModq1yHlIZlHwtdzbcyRe3/MvSJiG0s=; h=Date:From:To:Cc:Subject:From; b=JCrk0uwwkhfkTLux/mgp5WxUeHMtQt5a6q0bHSOxYvZT8vyTogP0sJafOoEk4JRXW PIZOaa/Q+GYFBzbxJk0/szjg53/lf2XEHowx2S/TdV4GAH2+FlRSOj6KMgpcKOOm5s BsUeOg5xzmGksQMqfqO+76ntwhcL9D3rLq42GPKE= Date: Thu, 7 May 2020 13:55:50 -0500 From: "Gustavo A. R. Silva" To: Dave Kleikamp Cc: jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH] JFS: Replace zero-length array with flexible-array Message-ID: <20200507185550.GA14715@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) 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] sizeof(flexible-array-member) triggers a warning because flexible array members have incomplete type[1]. There are some instances of code in which the sizeof operator is being incorrectly/erroneously applied to zero-length arrays and the result is zero. Such instances may be hiding some bugs. So, this work (flexible-array member conversions) will also help to get completely rid of those sorts of issues. 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 */