Commit 1d700bf
Fix UB when calculating median of all-NaN values
The current code contains undefined behavior where all-NaN values
are passed to median. In that case we end up with final_elements==0
in the following branch:
else {
rpnstack->s[++stptr] =
0.5 * (element_ptr[final_elements / 2] +
element_ptr[final_elements / 2 - 1]);
}
and so we use 0 and -1 as element_ptr array indexes. The
latter is ill-formed and leads to a crash in my case. Move the
check which accounts for the last NaN earlier, so we could
push NaN and finish right away.1 parent bfe03f3 commit 1d700bf
1 file changed
+6
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1253 | 1253 | | |
1254 | 1254 | | |
1255 | 1255 | | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
1256 | 1262 | | |
1257 | 1263 | | |
1258 | 1264 | | |
1259 | 1265 | | |
1260 | 1266 | | |
1261 | | - | |
1262 | | - | |
1263 | | - | |
1264 | | - | |
1265 | | - | |
1266 | 1267 | | |
1267 | 1268 | | |
1268 | 1269 | | |
| |||
0 commit comments