Incidencia #47982

common/unit.c:2475:13: runtime error: index -1 out of bounds for type 'const struct unit_list_link *5'

Abrir Fecha: 2023-05-05 16:02 Última actualización: 2023-05-11 18:12

Informador:
Propietario:
Tipo:
Estado:
Cerrado
Componente:
Prioridad:
5 - Medium
Gravedad:
5 - Medium
Resolución:
Fixed
Fichero:
1

Details

About 50% of test games i have :

../../common/unit.c:2483:13: runtime error: index -1 out of bounds for type 'const struct unit_list_link *[5]'

Looking at the code it is a list traversal, with obvious off-by-one error.

Attached patch fixes it, and clarify the code.

Ticket History (3/12 Histories)

2023-05-05 16:02 Updated by: alain_bkr
  • New Ticket "common/unit.c:2475:13: runtime error: index -1 out of bounds for type 'const struct unit_list_link *5'" created
2023-05-05 16:11 Updated by: cazfi
Comentario

So this is still happening after #47900?

2023-05-05 21:10 Updated by: alain_bkr
Comentario

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.

2023-05-05 21:18 Updated by: alain_bkr
Comentario

i guess i did found the commit related to #47900

commit f9729eb0d23, it was already included in my branch S3_1

So yes, the bug still happened after f9729eb0d23, but is fixed with my patch

(Edited, 2023-05-05 21:18 Updated by: alain_bkr)
2023-05-05 21:45 Updated by: cazfi
Comentario

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"

2023-05-07 00:24 Updated by: alain_bkr
Comentario
  • before my patch the value could be -1 ( when var-- =1 , so we have 1 - 2 = -1 which is not valid)
  • after my patch it cannot be -1, so there is no more error

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).

(Edited, 2023-05-07 00:51 Updated by: alain_bkr)
2023-05-07 00:56 Updated by: cazfi
Comentario

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.

2023-05-07 20:31 Updated by: alain_bkr
Comentario

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.

2023-05-08 06:29 Updated by: cazfi
  • Propietario Update from (Ninguno) to cazfi
  • Resolución Update from Ninguno to Accepted
  • Hito Update from 3.1.0-beta2 (cerrado) to 3.0.8 (cerrado)
  • Componente Update from Server to General
2023-05-08 06:29 Updated by: cazfi
Comentario

Apply also to S2_6

2023-05-11 18:12 Updated by: cazfi
  • Estado Update from Open to Cerrado
  • Resolución Update from Accepted to Fixed

Attachment File List

Editar

Please login to add comment to this ticket » Entrar