Page 1 of 1
Bug in script function cleararray, tmwAthena server code
Posted: 28 May 2025, 10:55
by quietlyquietly
I have been reading the script code to determine which functions are present.
I found a BUG in the function "builtin_cleararray", file src/map/script-fun.cpp.
It is obvious that the code was copied from "setarray", and they missed changing one line.
Code: Select all
if (name.startswith(".@"_s))
set_scope_reg(st, reg.iplus(i), $AARG(i));
That "$AARGIi)", should be "$AARG(1)" as in the lines that follow that. (It is hard to see that i should be a 1).
The "cleararray" function does not have a list of args like the "setarray" function, it has only the one value arg at (1).
I did not find any existing scripts that use "cleararray" with a ".@" var, so this should not affect any existing scripts.
Re: Bug in script function cleararray, tmwAthena server code
Posted: 28 May 2025, 11:08
by quietlyquietly
The number of array elements is limited to 256 values in "setarray", even though arrays are supposedly limited to 127 values.
The function "getarraysize" also seems to assume arrays can have 256 elements.
The function "cleararray" has no protection at all on the number of elements cleared. It should be limited to something reasonable, like 256 (to be consistent).
Re: Bug in script function cleararray, tmwAthena server code
Posted: 28 May 2025, 11:48
by Bjørn
Good observation! It seems this was broken from the introduction of scope variables in https://git.themanaworld.org/legacy/tmw ... ad5d082da0.
Would you like to submit a merge request for this at https://git.themanaworld.org/legacy/tmwa?
Judging by the SIR structure storing an unsigned 8-bit index, I does seem like array should be able to hold up to 256 values. Judging by the code, cleararray would just wrap around when passed a larger size, which is basically just wasted effort but should at least not manifest as a bug.
Where do you see the supposed limit of 127 values?
Re: Bug in script function cleararray, tmwAthena server code
Posted: 28 May 2025, 11:55
by quietlyquietly
The docs given to me were for eAthena, as that was the best available, and they mention array limit of 127 values.
Have been trying to write scripts using those docs and the tmwAthena does not conform to them very well.
Direct experimentation was revealing much, so had to inspect the actual code, Several days later ....
It looks like the array limit for tmwAthena is 256 array elements, so I should put that in my documentation.
I am not setup to access the tmwAthena repository, and this is one char change, so anyone can do it.
Please also put a limit on the <size> var in that function. I think just limiting it to 256 would be adequate.
Also kick out if size is negative.
Server time would used up with useless looping if it ever got a bad sz value.
Code: Select all
if( sz < 0 ) return;
if( sz > 255 ) sz = 255;
Perhaps eAthena is using a signed index ?
Re: Bug in script function cleararray, tmwAthena server code
Posted: 28 May 2025, 12:04
by Bjørn
quietlyquietly wrote: ↑28 May 2025, 11:55
The docs given to me were for eAthena, as that was the best available, and they mention array limit of 127 values.
Ah, since tmwAthena forked from eAthena a lot of functions were removed and a lot of others added. Maybe the following pages are more up to date?
https://wiki.themanaworld.org/wiki/Clas ... ing_Basics
https://wiki.themanaworld.org/wiki/Clas ... _Reference
https://wiki.themanaworld.org/wiki/Clas ... _Standards
quietlyquietly wrote: ↑28 May 2025, 11:55
Perhaps eAthena is using a signed index ?
Yes, it seems this index turned into strictly unsigned 8-bit along with fixes in https://git.themanaworld.org/legacy/tmw ... 71cb0cdfb1. Before that, we had:
Code: Select all
int num = AARGO2(2).u.num;
...
set_reg(sd, ByteCode::VARIABLE, num + (i << 24), conv_num(st, &AARGO2(3)));
Re: Bug in script function cleararray, tmwAthena server code
Posted: 28 May 2025, 13:54
by quietlyquietly
I will have to save those documents. A quick read of the first seems to be similar to eAthena, or was copied from it.
I will continue with my documentation effort, as it is more than half done, and it is documenting what the code actually does.
There are many details and gotchas that I am discovering. Some of the builtin functions are incomplete, lack protections.
Not that many people could possibly read this code.
Re: Bug in script function cleararray, tmwAthena server code
Posted: 03 Jun 2025, 09:11
by quietlyquietly
I have looked at the GIT repository, and like all GIT repositories that I have had to interact with, I cannot see how to do anything with it without having to totally invest in it. I do not use GIT for anything else and really did not want to have to adopt the GIT way of doing everything too.
Re: Bug in script function cleararray, tmwAthena server code
Posted: 03 Jun 2025, 18:38
by Bjørn
quietlyquietly wrote: ↑03 Jun 2025, 09:11
I do not use GIT for anything else and really did not want to have to adopt the GIT way of doing everything too.
I think it would pay off to learn more about git, at least enough to contribute patches. Did you ever contribute to another project and if so, how did you do it? Are you familiar with other version control systems?