robustness: avoid adding offset to NULL pointer

UBSAN with clang 10.0 is checking for adding offsets to a `NULL` pointer
which is not allowed. This is not yet checked in the version of clang
used in CI (7.0.0). I will work on cases of this so that tests passes
locally for me.

This could be tested in CI by either upgrading the clang of the
ASAN/UBSAN to 10.0, or add yet another CI target which builds with
clang 10.0.
This commit is contained in:
Björn Linse
2020-08-25 12:40:50 +02:00
parent 7593c8012b
commit b33e375b2b
3 changed files with 4 additions and 3 deletions

View File

@@ -586,7 +586,7 @@ parse_json_number_check:
if (p == ints) { if (p == ints) {
emsgf(_("E474: Missing number after minus sign: %.*s"), LENP(s, e)); emsgf(_("E474: Missing number after minus sign: %.*s"), LENP(s, e));
goto parse_json_number_fail; goto parse_json_number_fail;
} else if (p == fracs || exps_s == fracs + 1) { } else if (p == fracs || (fracs != NULL && exps_s == fracs + 1)) {
emsgf(_("E474: Missing number after decimal dot: %.*s"), LENP(s, e)); emsgf(_("E474: Missing number after decimal dot: %.*s"), LENP(s, e));
goto parse_json_number_fail; goto parse_json_number_fail;
} else if (p == exps) { } else if (p == exps) {

View File

@@ -2681,7 +2681,8 @@ static void foldRemove(
fold_changed = true; fold_changed = true;
continue; continue;
} }
if (fp >= (fold_T *)(gap->ga_data) + gap->ga_len if (gap->ga_data == NULL
|| fp >= (fold_T *)(gap->ga_data) + gap->ga_len
|| fp->fd_top > bot) { || fp->fd_top > bot) {
// 6: Found a fold below bot, can stop looking. // 6: Found a fold below bot, can stop looking.
break; break;

View File

@@ -1431,7 +1431,7 @@ static inline void east_set_error(const ParserState *const pstate,
const ParserLine pline = pstate->reader.lines.items[start.line]; const ParserLine pline = pstate->reader.lines.items[start.line];
ret_ast_err->msg = msg; ret_ast_err->msg = msg;
ret_ast_err->arg_len = (int)(pline.size - start.col); ret_ast_err->arg_len = (int)(pline.size - start.col);
ret_ast_err->arg = pline.data + start.col; ret_ast_err->arg = pline.data ? pline.data + start.col : NULL;
} }
/// Set error from the given token and given message /// Set error from the given token and given message