unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8211: uninitialized variable in detect_coding_iso_2022's end-of-composition code
@ 2011-03-09 17:53 Paul Eggert
  2011-03-09 22:30 ` Andreas Schwab
  2019-06-19  0:19 ` Paul Eggert
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Eggert @ 2011-03-09 17:53 UTC (permalink / raw)
  To: 8211

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.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#8211: uninitialized variable in detect_coding_iso_2022's end-of-composition code
  2011-03-09 17:53 bug#8211: uninitialized variable in detect_coding_iso_2022's end-of-composition code Paul Eggert
@ 2011-03-09 22:30 ` Andreas Schwab
  2019-06-19  0:19 ` Paul Eggert
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2011-03-09 22:30 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 8211

Paul Eggert <eggert@cs.ucla.edu> writes:

> 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 think it just lacks a break.  ESC '1' is not a designation sequence.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#8211: uninitialized variable in detect_coding_iso_2022's end-of-composition code
  2011-03-09 17:53 bug#8211: uninitialized variable in detect_coding_iso_2022's end-of-composition code Paul Eggert
  2011-03-09 22:30 ` Andreas Schwab
@ 2019-06-19  0:19 ` Paul Eggert
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Eggert @ 2019-06-19  0:19 UTC (permalink / raw)
  To: 8211-done

Kenichi Handa evidently fixed this old bug in 2011 after I filed it, so I'm closing the bug report now.






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-19  0:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-09 17:53 bug#8211: uninitialized variable in detect_coding_iso_2022's end-of-composition code Paul Eggert
2011-03-09 22:30 ` Andreas Schwab
2019-06-19  0:19 ` Paul Eggert

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).