Skip to content

Commit 5058fb2

Browse files
committed
add explicit undef value to format string enums
This lead to uninitialized read of length_modifier and representation. While probably not critical, as the respective switches contain a default branch and the compiler seems to allow integral values outside the enum range.
1 parent da0b0d5 commit 5058fb2

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/goto-programs/format_strings.h

+22-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,29 @@ class format_tokent
3030
typedef enum { ALTERNATE, ZERO_PAD, LEFT_ADJUST,
3131
SIGNED_SPACE, SIGN, ASTERISK } flag_typet;
3232

33-
typedef enum { LEN_h, LEN_hh, LEN_l, LEN_ll, LEN_L, LEN_j, LEN_t } length_modifierst;
33+
typedef enum
34+
{
35+
LEN_undef, LEN_h, LEN_hh, LEN_l, LEN_ll,
36+
LEN_L, LEN_j, LEN_t
37+
} length_modifierst;
38+
39+
typedef enum
40+
{
41+
SIGNED_undef, SIGNED_DEC, UNSIGNED_DEC,
42+
UNSIGNED_OCT, UNSIGNED_HEX
43+
} representationt;
44+
45+
explicit format_tokent(token_typet _type)
46+
: type(_type),
47+
length_modifier(LEN_undef),
48+
representation(SIGNED_undef)
49+
{ }
50+
format_tokent():
51+
type(UNKNOWN),
52+
length_modifier(LEN_undef),
53+
representation(SIGNED_undef)
54+
{ }
3455

35-
typedef enum { SIGNED_DEC, UNSIGNED_DEC, UNSIGNED_OCT, UNSIGNED_HEX } representationt;
36-
37-
explicit format_tokent(token_typet _type) : type(_type) { }
38-
format_tokent(): type(UNKNOWN) { }
3956

4057
token_typet type;
4158
std::list<flag_typet> flags;

0 commit comments

Comments
 (0)