diff options
| author | Ramsay Jones <ramsay@ramsay1.demon.co.uk> | 2013-05-16 20:41:24 +0100 |
|---|---|---|
| committer | Christopher Li <sparse@chrisli.org> | 2013-05-17 10:53:08 -0700 |
| commit | 0edb7edecdd571c2663eb12acac1b27b9acac657 (patch) | |
| tree | 68bebe8beb001786e1d3691c667d4e2fc48e04af /validation | |
| parent | 9f97967a950c4a81e071c0f191e59cd8c2c89ed7 (diff) | |
| download | sparse-dev-0edb7edecdd571c2663eb12acac1b27b9acac657.tar.gz | |
char.c: Fix parsing of escapes
When parsing a string or character constant, the parse_escape()
function returns a pointer to the character at which to resume
parsing. However, in the case of an hex or octal escape, it was
returning a one-past-the-end pointer. Thus, a string like:
char str[3] = "\x61\x62\x63";
was being parsed as:
'\x61', 'x', '6', '2', '\x63'
which, in turn, provokes an 'too long initializer' warning.
Also, fix an off-by-one error in get_char_constant() when setting
the 'end' pointer for a TOKEN_CHAR or TOKEN_WIDE_CHAR. Despite the
name, the string->length of the token is actually the size of the
allocated memory (ie len+1), so we need to compensate by using
'token->string->length - 1'.
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/escapes.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/validation/escapes.c b/validation/escapes.c index 4a1b030e..5f526b9c 100644 --- a/validation/escapes.c +++ b/validation/escapes.c @@ -4,6 +4,16 @@ static int e[] = { '\'', '\"', '\?', '\\', static char *s = "\'\"\?\\ \a\b\f\n\r\t\v \377\xcafe"; static int bad_e[] = { '\c', '\0123', '\789', '\xdefg' }; + +static char a_hex[3] = "\x61\x62\x63"; +static char b_hex[3] = "\x61\x62\x63\x64"; +static char c_hex[3] = "\x61\x62"; +static char d_hex[3] = "\x61"; + +static char a_oct[3] = "\141\142\143"; +static char b_oct[3] = "\141\142\143\144"; +static char c_oct[3] = "\141\142"; +static char d_oct[3] = "\141"; /* * check-name: Character escape sequences * @@ -16,5 +26,7 @@ escapes.c:6:30: warning: multi-character character constant escapes.c:6:39: warning: multi-character character constant escapes.c:6:47: warning: hex escape sequence out of range escapes.c:6:47: warning: multi-character character constant +escapes.c:9:24: warning: too long initializer-string for array of char +escapes.c:14:24: warning: too long initializer-string for array of char * check-error-end */ |
