From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id C15D0385801A for ; Fri, 19 Mar 2021 16:43:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C15D0385801A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 99BF7AC17; Fri, 19 Mar 2021 16:43:14 +0000 (UTC) Subject: [committed] Change files var in main to char ** To: Florian Weimer Cc: Jakub Jelinek , mark@klomp.org, dwz@sourceware.org References: <20210317131444.GA11885@delia> <20210317131802.GG231854@tucnak> <20210317172818.GI231854@tucnak> <87czvwpa4f.fsf@oldenburg.str.redhat.com> From: Tom de Vries Message-ID: <6743f221-68bc-9ce6-113a-bffa46d912b6@suse.de> Date: Fri, 19 Mar 2021 17:43:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <87czvwpa4f.fsf@oldenburg.str.redhat.com> Content-Type: multipart/mixed; boundary="------------4E8414A0C4390CA2C673628D" Content-Language: en-US X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Mar 2021 16:43:17 -0000 This is a multi-part message in MIME format. --------------4E8414A0C4390CA2C673628D Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit [ was: Re: [committed] Make main more readable ] On 3/18/21 7:52 PM, Florian Weimer wrote: > * Tom de Vries: > >> I've prepared a patch implementing that suggestion. Does that address >> your concerns? >> >> [ FWIW, I've read through a C99 draft pdf to refresh my memory on this >> topic. Looking at the effective type of **argv, AFAIU it falls into the >> catagory "For all other accesses to an object having no declared type, >> the effective type of the object is simply the type of the lvalue used >> for the access". In other words, the effective type is char. >> >> Then I read: >> ... >> An object shall have its stored value accessed only by an lvalue >> expression that has one of the following types: >> — a qualified version of a type compatible with the effective type of >> the object, >> ... >> >> So, const char is a qualified version of a type char compatible with the >> effective type of the object (char). >> >> So I still don't see the problem. ] > > I think the issue is about the char * array elements, not the individual > bytes in the strings themselves. I see, that explains, I somehow managed to miss that. I've updated the log message, and committed. Thanks, - Tom --------------4E8414A0C4390CA2C673628D Content-Type: text/x-patch; charset=UTF-8; name="0001-Change-files-var-in-main-to-char.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-Change-files-var-in-main-to-char.patch" Change files var in main to char ** The cast on &argv[optind] to const char **: ... main (int argc, char *argv[]) { ... const char **files; ... files = (const char **)&argv[optind]; ... violates the aliasing rules. The array element argv[i] aliases with the array element files[i], but the types of the elements (char * vs. const char *) are not compatible types. Since we access the elements using both types (const char * in dwz_files/dwz, char * in getopt_long), there's a violation. Fix this by changing the type of files to char **. 2021-03-18 Tom de Vries * dwz.c (dwz): Make files param a char **. (dwz_files): Make files param char *[]. (main): Make files var a char **. --- dwz.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dwz.c b/dwz.c index 7b67960..a7aa23b 100644 --- a/dwz.c +++ b/dwz.c @@ -15267,7 +15267,7 @@ struct file_result over FILE. */ static int dwz (const char *file, const char *outfile, struct file_result *res, - struct file_result *resa, const char **files) + struct file_result *resa, char **files) { DSO *dso; int ret = 0, fd; @@ -16285,7 +16285,7 @@ dwz_one_file (const char *file, const char *outfile) /* Dwarf-compress FILES. If HARDLINK, detect if some files are hardlinks and if so, dwarf-compress just one, and relink the others. */ static int -dwz_files (int nr_files, const char *files[], bool hardlink) +dwz_files (int nr_files, char *files[], bool hardlink) { int ret = 0; int i; @@ -16413,7 +16413,7 @@ main (int argc, char *argv[]) const char *outfile; bool hardlink; int nr_files; - const char **files; + char **files; if (elf_version (EV_CURRENT) == EV_NONE) error (1, 0, "library out of date"); @@ -16422,7 +16422,7 @@ main (int argc, char *argv[]) hardlink = false; parse_args (argc, argv, &hardlink, &outfile); nr_files = argc - optind; - files = (const char **)&argv[optind]; + files = &argv[optind]; if (nr_files <= 1) { --------------4E8414A0C4390CA2C673628D--