From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id A341C3846062 for ; Thu, 4 Apr 2024 01:18:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A341C3846062 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A341C3846062 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712193483; cv=none; b=D2z6XQgGD9zZgo9NDiKB4FBxrqxq7ch2WwSmZ4pgJSh+8p9O/SRb/EHl3CF2EyRXSAG1g5DZZ3w3TmRTkMmEcTCJRY1WMll//P2fL/2wO3GcJs6NR8FLOZtyqqKT042zT1DC3g92CTOusoBXQf+Ww2E9MlLqG3X8hqTyemzKj5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712193483; c=relaxed/simple; bh=RGT2uI9UGU+4LW5JV1JcmvflgtCP7gwBjNQFBegs9e0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=gfuS3LlTHcyvFdBJj7TDA0c5HsrHIyAq8swojmqLLDrFzv6BsDMG3Zz2L7U9SgnPFLHNTzpyy2zmqvHP5l1Qj3UzbuA1nvxLJOjkZKFZxwFzDq/82N2t8dSzjUs8NABuTGtZcJisT/UCCFkwDcRnzOTlQ+E0U8kYbE0z8De17iY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6e6a1d24770so292598a34.0 for ; Wed, 03 Apr 2024 18:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712193480; x=1712798280; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=juWyqaHKHpxdN/erRvTg6yIl12FEfgcWM92sa9yA9PI=; b=aW1jxdt7VXrOIepm04wvZdaGDm99fsmStS9eE6H+SzrB/z/4r692mMDbYgChVWU2WI cF5muWe8hwVydDN5Bl+MFT9ctZw95NsAhZJ4I7hphazhvg3Aru5RPQq9SiIVPgvWbxvn vCGywkXnkbbmZ7YrLfvvZxap8SsqCcIZN0XBUraakLGOiQZyGL8vn4vsNCE8QCMaEkDf QzwNlqFvCEVSVtHx1yejG/tsf89wlujCZRwzEQgV8IaiUh4Y5v7iGIFK1b4QTJJfNsIC xZO6H4Gi+/1SJxcIhWM9qgFE+LEz5T+nL7uBrzH4GvSMdTy+QQzp8D5WcjksHUs5LFvA 5SOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712193480; x=1712798280; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=juWyqaHKHpxdN/erRvTg6yIl12FEfgcWM92sa9yA9PI=; b=umkXZRNWmgrDCvtFeDOM4r3Ts5hqvSJA83v7KPSnnyN2RbhUqUNRRRqFpLHh7j3oR6 1n/oEtw9v2wKLiBZIfgSqSEtmfpib6zTTM5VNsknog88kcacvel9ghRmwaMRwRvhgOJ2 I1k4TkaF3sumdYL0xBD4YvlwaTXz7uLn9qTBFezvCAzlVK5hOEKI6O0a0eztlGXjcIzf zoWLopRsnErdNAHtHfHmw0+icKGrewzRgUaGGeIBu71WJCFMTfOPydHotksgbd7liDFl YfHpv8/su324G7bxSLHf/JL0YsuqEE+oqwcwKZ3utxuVP2kiMfIuZ2FpKucVHv0aiTIG W4KA== X-Gm-Message-State: AOJu0YzLjQd4sfzhqmWaWMB5JgoW28OQWPpLztZdfaNTmAXstiLAS5tY hrMcVfxIUEkl2U78bYfiIiH6/wISbCgMCkt9Na8jAY9tBHpeYqsqBl4DvSYz X-Google-Smtp-Source: AGHT+IE7G9InuVT2xs3Ju3MLmUPY1qJBm+KgIn7Mr009rU8EQIi5ViPvcW0CE9LnlpN8Y5qxlL6e1A== X-Received: by 2002:a05:6870:958f:b0:22e:8415:53ba with SMTP id k15-20020a056870958f00b0022e841553bamr1130032oao.35.1712193479714; Wed, 03 Apr 2024 18:17:59 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id i22-20020aa78b56000000b006e6795932a4sm12435267pfd.80.2024.04.03.18.17.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 18:17:59 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id B5F3A114031D; Thu, 4 Apr 2024 11:47:56 +1030 (ACDT) Date: Thu, 4 Apr 2024 11:47:56 +1030 From: Alan Modra To: binutils@sourceware.org Subject: Fix uninitialised variable errors Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3033.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,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 List-Id: Commit c6291d749aec introduced a number of errors, found by clang. elf.c:456:7: error: variable 'alloc_ext_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (_bfd_mul_overflow (symcount, extsym_size, &amt)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ elf.c:464:7: error: variable 'alloc_extshndx_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (bfd_seek (ibfd, pos, SEEK_SET) != 0 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ elflink.c:2837:11: error: variable 'alloc1_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (internal_relocs == NULL) ^~~~~~~~~~~~~~~~~~~~~~~ elflink.c:12595:16: error: variable 'ext_size' set but not used [-Werror,-Wunused-but-set-variable] size_t ext_size = 0; * elf.c (bfd_elf_get_elf_syms): Fix use of uninitialised variables. * elflink.c (_bfd_elf_link_info_read_relocs): Likewise. (bfd_elf_final_link): Fix set but not used warning. diff --git a/bfd/elf.c b/bfd/elf.c index 9b98d3b8b2b..c305b40eca3 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -456,8 +456,7 @@ bfd_elf_get_elf_syms (bfd *ibfd, if (_bfd_mul_overflow (symcount, extsym_size, &amt)) { bfd_set_error (bfd_error_file_too_big); - intsym_buf = NULL; - goto out; + return NULL; } pos = symtab_hdr->sh_offset + symoffset * extsym_size; size_t alloc_ext_size = amt; @@ -466,7 +465,7 @@ bfd_elf_get_elf_syms (bfd *ibfd, &alloc_ext, ibfd, false)) { intsym_buf = NULL; - goto out; + goto out2; } size_t alloc_extshndx_size = 0; @@ -478,7 +477,7 @@ bfd_elf_get_elf_syms (bfd *ibfd, { bfd_set_error (bfd_error_file_too_big); intsym_buf = NULL; - goto out; + goto out1; } alloc_extshndx_size = amt; pos = shndx_hdr->sh_offset + symoffset * sizeof (Elf_External_Sym_Shndx); @@ -489,7 +488,7 @@ bfd_elf_get_elf_syms (bfd *ibfd, ibfd, false)) { intsym_buf = NULL; - goto out; + goto out1; } } @@ -498,12 +497,12 @@ bfd_elf_get_elf_syms (bfd *ibfd, if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt)) { bfd_set_error (bfd_error_file_too_big); - goto out; + goto out1; } alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt); intsym_buf = alloc_intsym; if (intsym_buf == NULL) - goto out; + goto out1; } /* Convert the symbols to internal form. */ @@ -521,12 +520,13 @@ bfd_elf_get_elf_syms (bfd *ibfd, ibfd, (unsigned long) symoffset); free (alloc_intsym); intsym_buf = NULL; - goto out; + goto out1; } - out: - _bfd_munmap_readonly_temporary (alloc_ext, alloc_ext_size); + out1: _bfd_munmap_readonly_temporary (alloc_extshndx, alloc_extshndx_size); + out2: + _bfd_munmap_readonly_temporary (alloc_ext, alloc_ext_size); return intsym_buf; } diff --git a/bfd/elflink.c b/bfd/elflink.c index 2a05299b24d..dd7ae1705b6 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -2835,7 +2835,7 @@ _bfd_elf_link_info_read_relocs (bfd *abfd, else internal_relocs = alloc2 = (Elf_Internal_Rela *) bfd_malloc (size); if (internal_relocs == NULL) - goto error_return; + return NULL; } alloc1 = external_relocs; @@ -12592,6 +12592,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) if ((sec->flags & SEC_RELOC) != 0) { +#ifndef USE_MMAP size_t ext_size = 0; if (esdi->rel.hdr != NULL) @@ -12599,7 +12600,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) if (esdi->rela.hdr != NULL) ext_size += esdi->rela.hdr->sh_size; -#ifndef USE_MMAP if (ext_size > max_external_reloc_size) max_external_reloc_size = ext_size; #endif -- Alan Modra Australia Development Lab, IBM