Duke3D: `redefinequote` inside a switch statement leads to the string being allocated twice
Assume we have the following code:
var temp 0 0
onevent EVENT_ALTFIRE
switch temp
case 0
qputs 1 hello world
break
endswitch
endevent
When the qputs
command is contained inside the switch statement, the string "hello world" will be allocated twice in memory, with 2 pointers being stored inside the apXStrings
array. This also leads to the maximum limit of redefined quotes being reached more quickly than is apparent from the code itself.
In addition, there are no safeguards to prevent redefining more than 16384 quotes, meaning that the user will only notice that the limit has been exceeded once an out-of-bounds array access occurs and the game crashes due to a segmentation fault.