viml/parser/expressions,klee: Fix some problems found by KLEE run

This commit is contained in:
ZyX 2017-10-15 21:11:00 +03:00
parent bc386c4882
commit 3aa2c0d63a
5 changed files with 20 additions and 14 deletions

View File

@ -69,7 +69,7 @@ typedef enum {
} ExprOptScope;
#define EXPR_OPT_SCOPE_LIST \
((char *)(char[]){ kExprOptScopeGlobal, kExprOptScopeLocal })
((char[]){ kExprOptScopeGlobal, kExprOptScopeLocal })
/// All possible variable scopes
typedef enum {

View File

@ -38,20 +38,21 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
}
// Recognize hex, octal and bin.
if ((ptr[0] == '0') && (ptr[1] != '8') && (ptr[1] != '9')
&& (maxlen == 0 || maxlen > 1)) {
if ((what & (STR2NR_HEX|STR2NR_OCT|STR2NR_BIN))
&& (maxlen == 0 || maxlen > 1)
&& (ptr[0] == '0') && (ptr[1] != '8') && (ptr[1] != '9')) {
pre = ptr[1];
if ((what & STR2NR_HEX)
&& (maxlen == 0 || maxlen > 2)
&& ((pre == 'X') || (pre == 'x'))
&& ascii_isxdigit(ptr[2])
&& (maxlen == 0 || maxlen > 2)) {
&& ascii_isxdigit(ptr[2])) {
// hexadecimal
ptr += 2;
} else if ((what & STR2NR_BIN)
&& (maxlen == 0 || maxlen > 2)
&& ((pre == 'B') || (pre == 'b'))
&& ascii_isbdigit(ptr[2])
&& (maxlen == 0 || maxlen > 2)) {
&& ascii_isbdigit(ptr[2])) {
// binary
ptr += 2;
} else {
@ -80,7 +81,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
// Do the string-to-numeric conversion "manually" to avoid sscanf quirks.
int n = 1;
if ((pre == 'B') || (pre == 'b') || what == STR2NR_BIN + STR2NR_FORCE) {
if (pre == 'B' || pre == 'b' || what == (STR2NR_BIN|STR2NR_FORCE)) {
// bin
if (pre != 0) {
n += 2; // skip over "0b"
@ -97,7 +98,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
break;
}
}
} else if ((pre == '0') || what == STR2NR_OCT + STR2NR_FORCE) {
} else if (pre == '0' || what == (STR2NR_OCT|STR2NR_FORCE)) {
// octal
while ('0' <= *ptr && *ptr <= '7') {
// avoid ubsan error for overflow
@ -111,8 +112,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
break;
}
}
} else if ((pre == 'X') || (pre == 'x')
|| what == STR2NR_HEX + STR2NR_FORCE) {
} else if (pre == 'X' || pre == 'x' || what == (STR2NR_HEX|STR2NR_FORCE)) {
// hex
if (pre != 0) {
n += 2; // skip over "0x"

View File

@ -46,7 +46,7 @@ main() {
line1="$line1 '--output-dir=$KLEE_OUT_DIR' '$KLEE_BIN_DIR/a.bc'"
local line2="for t in '$KLEE_OUT_DIR'/*.err"
line2="$line2 ; do ktest-tool --write-ints"
line2="$line2 \"\$(printf '%s' \"\$t\" | sed -e 's@.[^/]*\$@.out@')\""
line2="$line2 \"\$(printf '%s' \"\$t\" | sed -e 's@\\.[^/]*\$@.ktest@')\""
line2="$line2 ; done"
printf '%s\n%s\n' "$line1" "$line2" | \
docker run \

View File

@ -89,8 +89,6 @@ int main(const int argc, const char *const *const argv,
kvi_init(pstate.reader.lines);
const ExprAST ast = viml_pexpr_parse(&pstate, flags);
assert(ast.root != NULL
|| plines[0].size == 0);
assert(ast.root != NULL || ast.err.msg);
viml_pexpr_free_ast(ast);
assert(allocated_memory == 0);

View File

@ -6867,5 +6867,13 @@ describe('Expressions parser', function()
},
}, {
})
check_parsing('0', 0, {
-- 0
ast = {
'Integer(val=0):0:0:0',
},
}, {
hl('Number', '0'),
})
end)
end)