Originally posted by [b]Ancyker[/b]
http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=4961
This bug originally manifested as people with
Book of the Dead having crazy amounts of attack. I quickly found out this was because the value was not being capped properly before being converted to an unsigned short.
I proceeded to check the code to discover that it was fine, and couldn't figure out why. After testing with others the only difference I could find was I was running 64bit BSD. The others I asked were using either 32bit or Windows 64bit. Didn't find anyone to test on Linux 64bit.
The function in utils.h seems to be the issue:
CODE
#define cap_value(a, min, max) ((a >= max) ? max : (a <= min) ? min : a)
When I dropped a line of debug code in status.c:
CODE
i = status->luk + sd->status.luk + sd->param_bonus[5] + sd->param_equip[5];
status->luk = cap_value(i,0,USHRT_MAX);
ShowDebug("LUK check: i: %d status: %d\n", i, status->luk);
This was the result:
QUOTE
[Debug]: LUK check: i: -17 status: 65535
So I added this to utils.c:
CODE
int cap_value2(int a, int min, int max) {
return ((a >= max) ? max : (a <= min) ? min : a);
}
And changed this:
CODE
i = status->luk + sd->status.luk + sd->param_bonus[5] + sd->param_equip[5];
status->luk = cap_value2(i,0,USHRT_MAX);
ShowDebug("LUK check: i: %d status: %d\n", i, status->luk);
The new result was:
QUOTE
[Debug]: LUK check: i: -16 status: 0
So I've left this change in for now until a permanent solution can be found.