bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#8211: uninitialized variable in detect_coding_iso_2022's end-of-comp


From: Paul Eggert
Subject: bug#8211: uninitialized variable in detect_coding_iso_2022's end-of-composition code
Date: Wed, 09 Mar 2011 09:53:39 -0800
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Thunderbird/3.1.7

I found this problem by compiling Emacs with GCC's -Wuninitialized flag.

The following code in the Emacs trunk src/coding.c's
detect_coding_iso_2022 function apparently uses an uninitialized variable:

          ...
          else if (c == '1')
            {
              /* End of composition.  */
              if (composition_count < 0
                  || composition_count > MAX_COMPOSITION_COMPONENTS)
                /* Invalid */
                break;
              composition_count = -1;
              found |= CATEGORY_MASK_ISO;
            }
          else
            ...

          /* We found a valid designation sequence for CHARSET.  */
          rejected |= CATEGORY_MASK_ISO_8BIT;
          if (SAFE_CHARSET_P (&coding_categories[coding_category_iso_7],
                              id))
            found |= CATEGORY_MASK_ISO_7;

The problem is that the "else if (c == '1')" branch does not initialize
the local variable "id", but the second "if" test uses that variable.

I plan to work around the uninitialized-variable problem by initializing
"id" to zero.  This will replace undefined behavior with defined behavior,
so it shouldn't introduce a new bug, but it probably doesn't fix the
bug in question, assuming there is one.  Could an expert in this
area please review this and come up with a real fix?

I'm CC'ing this to Kenichi Handa, who committed the code in question.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]