public inbox for bzip2-devel@sourceware.org
 help / color / mirror / Atom feed
From: "mark at klomp dot org" <sourceware-bugzilla@sourceware.org>
To: bzip2-devel@sourceware.org
Subject: [Bug bzip2/28904] libbzip2: ‘cost[3]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
Date: Tue, 19 Apr 2022 22:23:49 +0000	[thread overview]
Message-ID: <bug-28904-11876-0TmK0J9aLg@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-28904-11876@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=28904

--- Comment #2 from Mark Wielaard <mark at klomp dot org> ---
A different solution might be to use the constant BZ_N_GROUPS instead of the
variable nGroups when resetting the arrays:

diff --git a/compress.c b/compress.c
index 5dfa002..2dc5dc1 100644
--- a/compress.c
+++ b/compress.c
@@ -321,7 +321,7 @@ void sendMTFValues ( EState* s )
    ---*/
    for (iter = 0; iter < BZ_N_ITERS; iter++) {

-      for (t = 0; t < nGroups; t++) fave[t] = 0;
+      for (t = 0; t < BZ_N_GROUPS; t++) fave[t] = 0;

       for (t = 0; t < nGroups; t++)
          for (v = 0; v < alphaSize; v++)
@@ -353,7 +353,7 @@ void sendMTFValues ( EState* s )
             Calculate the cost of this group as coded
             by each of the coding tables.
          --*/
-         for (t = 0; t < nGroups; t++) cost[t] = 0;
+         for (t = 0; t < BZ_N_GROUPS; t++) cost[t] = 0;

          if (nGroups == 6 && 50 == ge-gs+1) {
             /*--- fast track the common case ---*/

Which might also help the compiler to simply zero the whole (6 element) arrays
in one go (the common case), instead of having to check whether nGroups is
smaller in this particular case.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2022-04-19 22:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18  3:18 [Bug bzip2/28904] New: " demerphq at gmail dot com
2022-04-19 22:04 ` [Bug bzip2/28904] " mark at klomp dot org
2022-04-19 22:23 ` mark at klomp dot org [this message]
2022-04-20  1:57 ` demerphq at gmail dot com
2022-05-26 20:53 ` mark at klomp dot org
2022-05-31 19:06 ` email at arsoftware dot net.br

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-28904-11876-0TmK0J9aLg@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=bzip2-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).