Update CScriptNetPropManager#541
Conversation
| @@ -1249,19 +1289,21 @@ class CScriptNetPropManager | |||
| if ( pInfo->datatype == types::_VEC3 ) | |||
| arraysize *= 3; | |||
|
|
|||
| if ( index < 0 || (unsigned int)index >= arraysize ) | |||
| if ( (unsigned int)index >= arraysize ) | |||
There was a problem hiding this comment.
is there a particular reason for removing these lower bound checks? index is provided by the user so this seems scary
There was a problem hiding this comment.
Unsigned cast of all negative numbers ([-1, -2147483648] -> [2147483648, 4294967295]) is always larger than the limit. It compiles into same code with less instructions (0-test) because arraysize is always non-zero.
If, on 64-bit, this function were to take a 64-bit signed index and this unsigned cast stayed 32-bit, values in the range [0x8000000000000000, 0x800000007fffffff] would truncate the sign bit and access out of bounds, but that's a lot of unlikely ifs.
I added some more assertions and a comment to inform future editors. This isn't a super important change though, impact of these 2 instructions is negligible
974f53e to
56c4502
Compare
The warning message is quite important, it's easy to make typos and not be aware of it ever.
PR Checklist
developbranch OR targets another branch with a specific goal in mind