SWITCH() doesn't handle default case properly
The SWITCH()
function doesn't handle the default value properly.
Experiment 1:
A | B | |
---|---|---|
1 | 3 | =SWITCH(A1, 1, "one", 2, "two", "many") |
Expected result in cell B1: many
Obtained result in cell B1: #N/A
Experiment 2:
A | B | |
---|---|---|
1 | many | =SWITCH(A1, 1, "one", 2, "two", "many") |
Expected result in cell B1: many
Obtained result: Gnumeric segfaults.
Thread 1 "gnumeric" received signal SIGSEGV, Segmentation fault.
0x00007ffff78f8c54 in ?? () from /usr/lib/libspreadsheet-1.12.35.so
(gdb)
Experiment 3:
Same as before but write many
FIRST and then the formula.
A | B | |
---|---|---|
1 | many | =SWITCH(A1, 1, "one", 2, "two", "many") |
Expected result in cell B1: many
Obtained result in cell B1: 0, and a critical warning is printed.
** (gnumeric:6123): CRITICAL **: 20:13:35.637: gnm_expr_eval: assertion 'expr != NULL' failed
Hypothesis:
If SWITCH()
has an even number of arguments, Gnumeric assumes the last one is another option and tries to return the argument after it, which is a no-value, instead of just treating it as a default value.