common/unit.c:2475:13: runtime error: index -1 out of bounds for type 'const struct unit_list_link *5'
So this is still happening after #47900?
what is the commit hash corresponding to #47900 ?
i did git pull --rebase on S3_1
I prefer my patch, which fixes the problem, instead of yours which only add an assert and let the wrong (-2) in the code.
Reply To alain_bkr
I prefer my patch, which fixes the problem, instead of yours which only add an assert and let the wrong (-2) in the code.
It didn't "only add an assert" (it didn't do that at all, on older branches), but turned "do {} while ()" to a "while() {}" so that there's no first iteration when there should be zero. So likely we need that fix anyway (or we rely on callers to do the right thing, like the assert on development branches dictates)
Need to check with more time, but I don't really see what's the crucial difference your patch does, if it's related to '-2' and not the earlier part
The '-2' is from the old value, and after your change there's '-1' from the new value. It's more readable than "var-- - 2"
i don't know how to explain better, it is a list traversal, check the lowest value, you will see.
Edited : it is not only better readability, it is different end
The 3rd case (old -2) may not happen with my patch , if it is stopped by the while check and thus do not try the equivalent (new -1).
Reply To alain_bkr
* before my patch the value could be -1 ( when var-- =1 , so we have 1 - 2 = -1 which is not valid)
I had just missed the line number 2483 in ticket details (different from line number on subject line). So yes, on that line there is access of index -1, just before the loop terminates as var-- makes var 0.
i rechecked , just to be sure :-)
The most recent game with the error was my Sz1-Ai001-Lm47-230506_170330-T00064-auto.sav.xz
game_version=3010000 revision="3.1.0-beta1+ (origin/S3_1 373049274 HEAD 7ef4e956f (+6) )"
and this 373049274 is more recent than previous patch (#47900, commit f9729eb0d23)
$ git rev-list --count f9729eb0d23..373049274 16
And since my patch i have no more encountered this error.
Apply also to S2_6
About 50% of test games i have :
Looking at the code it is a list traversal, with obvious off-by-one error.
Attached patch fixes it, and clarify the code.