Skip to content

Commit 27a7a4d

Browse files
committed
Use abort() instead of assert(false) for things that should never happen
assert() is compiled out for release builds, but we don't want to continue running in these impossible situations. This also resolves the "implicit fallthrough" warnings for the asserts in switch cases.
1 parent 035ee86 commit 27a7a4d

File tree

22 files changed

+44
-44
lines changed

22 files changed

+44
-44
lines changed

src/nvim/buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3270,7 +3270,7 @@ void maketitle(void)
32703270
case 6: buf_p = strappend(buf_p, " -"); break;
32713271
case 5:
32723272
case 7: buf_p = strappend(buf_p, " -+"); break;
3273-
default: assert(false);
3273+
default: abort();
32743274
}
32753275

32763276
if (curbuf->b_fname != NULL) {

src/nvim/charset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
17471747
goto vim_str2nr_dec;
17481748
}
17491749
default: {
1750-
assert(false);
1750+
abort();
17511751
}
17521752
}
17531753
} else if ((what & (STR2NR_HEX|STR2NR_OCT|STR2NR_BIN))
@@ -1788,7 +1788,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
17881788
}
17891789

17901790
// Do the string-to-numeric conversion "manually" to avoid sscanf quirks.
1791-
assert(false); // Should’ve used goto earlier.
1791+
abort(); // Should’ve used goto earlier.
17921792
#define PARSE_NUMBER(base, cond, conv) \
17931793
do { \
17941794
while (!STRING_ENDED(ptr) && (cond)) { \

src/nvim/eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void eval_init(void)
365365
eval_msgpack_type_lists[i] = type_list;
366366
if (tv_dict_add(msgpack_types_dict, di) == FAIL) {
367367
// There must not be duplicate items in this dictionary by definition.
368-
assert(false);
368+
abort();
369369
}
370370
}
371371
msgpack_types_dict->dv_lock = VAR_FIXED;

src/nvim/eval/decode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static inline int json_decoder_pop(ValuesStackItem obj,
147147
tv_clear(&key.val);
148148
if (tv_dict_add(last_container.container.vval.v_dict, obj_di)
149149
== FAIL) {
150-
assert(false);
150+
abort();
151151
}
152152
obj_di->di_tv = obj.val;
153153
} else {
@@ -480,7 +480,7 @@ static inline int parse_json_string(const char *const buf, const size_t buf_len,
480480
break;
481481
}
482482
default: {
483-
assert(false);
483+
abort();
484484
}
485485
}
486486
} else {

src/nvim/eval/encode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static int conv_error(const char *const msg, const MPConvStack *const mpstack,
174174
case kMPConvPartial: {
175175
switch (v.data.p.stage) {
176176
case kMPConvPartialArgs: {
177-
assert(false);
177+
abort();
178178
break;
179179
}
180180
case kMPConvPartialSelf: {
@@ -237,7 +237,7 @@ bool encode_vim_list_to_buf(const list_T *const list, size_t *const ret_len,
237237
char *const buf = xmalloc(len);
238238
size_t read_bytes;
239239
if (encode_read_from_list(&lrstate, buf, len, &read_bytes) != OK) {
240-
assert(false);
240+
abort();
241241
}
242242
assert(len == read_bytes);
243243
*ret_buf = buf;

src/nvim/eval/executor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int eexe_mod_op(typval_T *const tv1, const typval_T *const tv2,
118118
return OK;
119119
}
120120
case VAR_UNKNOWN: {
121-
assert(false);
121+
abort();
122122
}
123123
}
124124
}

src/nvim/eval/funcs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,7 +3307,7 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
33073307
}
33083308
break;
33093309
case kCdScopeInvalid: // We should never get here
3310-
assert(false);
3310+
abort();
33113311
}
33123312

33133313
if (from) {
@@ -4360,7 +4360,7 @@ static void f_haslocaldir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
43604360
break;
43614361
case kCdScopeInvalid:
43624362
// We should never get here
4363-
assert(false);
4363+
abort();
43644364
}
43654365
}
43664366

src/nvim/eval/typval.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,7 +2521,7 @@ void tv_item_lock(typval_T *const tv, const int deep, const bool lock)
25212521
break;
25222522
}
25232523
case VAR_UNKNOWN: {
2524-
assert(false);
2524+
abort();
25252525
}
25262526
}
25272527
#undef CHANGE_LOCK
@@ -2693,7 +2693,7 @@ bool tv_equal(typval_T *const tv1, typval_T *const tv2, const bool ic,
26932693
}
26942694
}
26952695

2696-
assert(false);
2696+
abort();
26972697
return false;
26982698
}
26992699

@@ -2746,7 +2746,7 @@ bool tv_check_str_or_nr(const typval_T *const tv)
27462746
return false;
27472747
}
27482748
}
2749-
assert(false);
2749+
abort();
27502750
return false;
27512751
}
27522752

@@ -2791,7 +2791,7 @@ bool tv_check_num(const typval_T *const tv)
27912791
return false;
27922792
}
27932793
}
2794-
assert(false);
2794+
abort();
27952795
return false;
27962796
}
27972797

@@ -2836,7 +2836,7 @@ bool tv_check_str(const typval_T *const tv)
28362836
return false;
28372837
}
28382838
}
2839-
assert(false);
2839+
abort();
28402840
return false;
28412841
}
28422842

src/nvim/ex_docmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7591,7 +7591,7 @@ void post_chdir(CdScope scope, bool trigger_dirchanged)
75917591
curwin->w_localdir = (char_u *)xstrdup(cwd);
75927592
break;
75937593
case kCdScopeInvalid:
7594-
assert(false);
7594+
abort();
75957595
}
75967596

75977597
shorten_fnames(true);

src/nvim/ex_getln.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6383,7 +6383,7 @@ int hist_type2char(int type)
63836383
return '>';
63846384
}
63856385
default: {
6386-
assert(false);
6386+
abort();
63876387
}
63886388
}
63896389
return NUL;

0 commit comments

Comments
 (0)