Message ID | 20241024090608.391906-1-mark@klomp.org |
---|---|
State | Committed |
Headers |
Return-Path: <elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E2AF3858D21 for <patchwork@sourceware.org>; Thu, 24 Oct 2024 09:08:05 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id D58123858D21 for <elfutils-devel@sourceware.org>; Thu, 24 Oct 2024 09:07:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D58123858D21 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D58123858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=45.83.234.184 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729760876; cv=none; b=VtKIPgIEaYXk0QwyVWFAkxUU/RnxAAJYth297XhwtmM9vzD2CIaqqyfrso6O1hwT3ffpStWLzmKZzKR3G61Qij/cPpCCaoi9meL2ZpuuUHoR4Dq6ZMcMnuC7hpK0z2S20N+9bJ5AB/x9eZm5lEq+vvW4fWd488H7U2BpvL2j5rc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729760876; c=relaxed/simple; bh=DXFBq5zCJflXVP8VDrwbnOg0G1Bxmc8RJ4RnbLkBfZw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=i0IrB+lnkHO1Rvafn4q1peHgVltRp5VQkKvZQQEnAmfwQSuHVh/GIbGbfAJiMqwKzIiNBJFRoINiIh1ZjePDmupn1PCGzEm1QfcepIOVuKCo63NAIoNDvgkYnQYUWqfOvYzE7A9tM0ieYIcl6sJqwrXwo0zCvLLNPCrkscJFEag= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mwielaar-thinkpadp1gen3.rmtnl.csb (deer0x08.wildebeest.org [172.31.17.138]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id B7BBA303C2A0; Thu, 24 Oct 2024 11:07:43 +0200 (CEST) Received: by mwielaar-thinkpadp1gen3.rmtnl.csb (Postfix, from userid 10916) id 5C8DE5EF8C0; Thu, 24 Oct 2024 11:07:43 +0200 (CEST) From: Mark Wielaard <mark@klomp.org> To: elfutils-devel@sourceware.org Cc: Serhei Makarov <serhei@serhei.io>, Mark Wielaard <mark@klomp.org> Subject: [PATCH] stacktrace: Init elf_fd in sysprof_init_dwfl Date: Thu, 24 Oct 2024 11:06:08 +0200 Message-ID: <20241024090608.391906-1-mark@klomp.org> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list <elfutils-devel.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/elfutils-devel>, <mailto:elfutils-devel-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/elfutils-devel/> List-Post: <mailto:elfutils-devel@sourceware.org> List-Help: <mailto:elfutils-devel-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/elfutils-devel>, <mailto:elfutils-devel-request@sourceware.org?subject=subscribe> Errors-To: elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org |
Series |
stacktrace: Init elf_fd in sysprof_init_dwfl
|
|
Commit Message
Mark Wielaard
Oct. 24, 2024, 9:06 a.m. UTC
When building with LTO gcc believes elf_fd can be used uninitialized:
In function ‘sysprof_init_dwfl’,
inlined from ‘sysprof_unwind_cb’ at stacktrace.c:1235:16:
stacktrace.c:1087:7: error: ‘elf_fd’ may be used uninitialized [-Werror=maybe-uninitialized]
1087 | close (elf_fd);
| ^
This code won't be reached because if find_procfile doesn't initialize
elf_fd, it will return an error. But help the compiler by initializing
elf_fd to -1.
* src/stacktrace.c (sysprof_init_dwfl): Init elf_fd to -1.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
src/stacktrace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, Oct 24, 2024 at 5:08 AM Mark Wielaard <mark@klomp.org> wrote: > > When building with LTO gcc believes elf_fd can be used uninitialized: > > In function ‘sysprof_init_dwfl’, > inlined from ‘sysprof_unwind_cb’ at stacktrace.c:1235:16: > stacktrace.c:1087:7: error: ‘elf_fd’ may be used uninitialized [-Werror=maybe-uninitialized] > 1087 | close (elf_fd); > | ^ > > This code won't be reached because if find_procfile doesn't initialize > elf_fd, it will return an error. But help the compiler by initializing > elf_fd to -1. > > * src/stacktrace.c (sysprof_init_dwfl): Init elf_fd to -1. > > Signed-off-by: Mark Wielaard <mark@klomp.org> > --- > src/stacktrace.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/stacktrace.c b/src/stacktrace.c > index 438cb1dd0d38..b912ca5de502 100644 > --- a/src/stacktrace.c > +++ b/src/stacktrace.c > @@ -1033,7 +1033,7 @@ sysprof_init_dwfl (struct sysprof_unwind_info *sui, > } > > Elf *elf = NULL; > - int elf_fd; > + int elf_fd = -1; > err = find_procfile (dwfl, &pid, &elf, &elf_fd); > if (err < 0) > { > -- > 2.47.0 > LGTM Thanks, Aaron
Hi Aaron, On Thu, 2024-10-24 at 10:22 -0400, Aaron Merey wrote: > On Thu, Oct 24, 2024 at 5:08 AM Mark Wielaard <mark@klomp.org> wrote: > > > > When building with LTO gcc believes elf_fd can be used uninitialized: > > LGTM Thanks, pushed. Cheers, Mark
diff --git a/src/stacktrace.c b/src/stacktrace.c index 438cb1dd0d38..b912ca5de502 100644 --- a/src/stacktrace.c +++ b/src/stacktrace.c @@ -1033,7 +1033,7 @@ sysprof_init_dwfl (struct sysprof_unwind_info *sui, } Elf *elf = NULL; - int elf_fd; + int elf_fd = -1; err = find_procfile (dwfl, &pid, &elf, &elf_fd); if (err < 0) {