From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id D57A63846411; Thu, 4 Apr 2024 01:18:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D57A63846411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712193523; bh=EciKy34oglICNwkZpi/YSUQArC8ari/ycQWj6jZ49QY=; h=From:To:Subject:Date:From; b=pPda6ooA1P8uv89WTIcOujDTsgqXPS6Rmc3tPRBCwtYuBOI0eetmP1CF5J+I/Wq7q 6LvKlT0L9ScesRBayfmYlg7yNW3n78bnrWc/hTa1hdYZTjLM+CE03aYvju6xD7bOJV W5B5IZnpGVBt2n6ozDndeaAl1MW9C3USTSztBEB8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: binutils-cvs@sourceware.org Subject: [binutils-gdb] Fix uninitialised variable errors X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: b86d3af60ffc5a821aa54404f57ffe9476919135 X-Git-Newrev: 9fd82d9142d742c9e3efb16466019bd5fe86aef9 Message-Id: <20240404011843.D57A63846411@sourceware.org> Date: Thu, 4 Apr 2024 01:18:43 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D9fd82d9142d7= 42c9e3efb16466019bd5fe86aef9 commit 9fd82d9142d742c9e3efb16466019bd5fe86aef9 Author: Alan Modra Date: Thu Apr 4 11:23:32 2024 +1030 Fix uninitialised variable errors =20 Commit c6291d749aec introduced a number of errors, found by clang. =20 elf.c:456:7: error: variable 'alloc_ext_size' is used uninitialized whe= never '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 uninitialize= d whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (bfd_seek (ibfd, pos, SEEK_SET) !=3D 0 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ elflink.c:2837:11: error: variable 'alloc1_size' is used uninitialized = whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (internal_relocs =3D=3D NULL) ^~~~~~~~~~~~~~~~~~~~~~~ elflink.c:12595:16: error: variable 'ext_size' set but not used [-Werro= r,-Wunused-but-set-variable] size_t ext_size =3D 0; =20 * elf.c (bfd_elf_get_elf_syms): Fix use of uninitialised variab= les. * elflink.c (_bfd_elf_link_info_read_relocs): Likewise. (bfd_elf_final_link): Fix set but not used warning. Diff: --- bfd/elf.c | 20 ++++++++++---------- bfd/elflink.c | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) 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 =3D NULL; - goto out; + return NULL; } pos =3D symtab_hdr->sh_offset + symoffset * extsym_size; size_t alloc_ext_size =3D amt; @@ -466,7 +465,7 @@ bfd_elf_get_elf_syms (bfd *ibfd, &alloc_ext, ibfd, false)) { intsym_buf =3D NULL; - goto out; + goto out2; } =20 size_t alloc_extshndx_size =3D 0; @@ -478,7 +477,7 @@ bfd_elf_get_elf_syms (bfd *ibfd, { bfd_set_error (bfd_error_file_too_big); intsym_buf =3D NULL; - goto out; + goto out1; } alloc_extshndx_size =3D amt; pos =3D 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 =3D NULL; - goto out; + goto out1; } } =20 @@ -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 =3D (Elf_Internal_Sym *) bfd_malloc (amt); intsym_buf =3D alloc_intsym; if (intsym_buf =3D=3D NULL) - goto out; + goto out1; } =20 /* 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 =3D NULL; - goto out; + goto out1; } =20 - 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); =20 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 =3D alloc2 =3D (Elf_Internal_Rela *) bfd_malloc (size); if (internal_relocs =3D=3D NULL) - goto error_return; + return NULL; } =20 alloc1 =3D external_relocs; @@ -12592,6 +12592,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info= *info) =20 if ((sec->flags & SEC_RELOC) !=3D 0) { +#ifndef USE_MMAP size_t ext_size =3D 0; =20 if (esdi->rel.hdr !=3D NULL) @@ -12599,7 +12600,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info= *info) if (esdi->rela.hdr !=3D NULL) ext_size +=3D esdi->rela.hdr->sh_size; =20 -#ifndef USE_MMAP if (ext_size > max_external_reloc_size) max_external_reloc_size =3D ext_size; #endif