desmume icon indicating copy to clipboard operation
desmume copied to clipboard

Drop superfluous check for negative value of unsigned types

Open janisozaur opened this issue 3 years ago • 2 comments

janisozaur avatar Jul 21 '22 10:07 janisozaur

I dont understand the significance of > sometimes and >= others. This code is gross. Unsigned numbers are horrible. Can you please change the parameters to be ints instead?

zeromus avatar Jul 21 '22 19:07 zeromus

From what I can tell, srcPos >= list.size() makes sure that the source is somewhere /inside/ the list (as expected), while dstPos > list.size() uses > instead of >= because an item can be moved to the end of the list (ie. dstPos == list.size()).

As for signedness: While I'd argue that something's gone /seriously/ wrong if either of those values are out of bounds (or even negative) by the time move() is invoked, I think it really would be better to use int instead. At least on Windows (I can't seem to find references to move() on other platforms), s32 draggedItem and s32 highlightedItem are the values passed to the function, both of which are signed values that store -1 when in an 'invalid' state.

Aikku93 avatar Jul 23 '22 05:07 Aikku93