Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
SPOP optional count argument. (issue #1793, supersedes pull request #1803) #2215
Added parameter to SPOP:
Cleaned up code a bit to match with required Redis coding style
added a commit
this pull request
Dec 17, 2014
This introduced a warning:
t_set.c:548:35: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] redisAssert(elements_returned == count); ~~~~~~~~~~~~~~~~~ ^ ~~~~~ ./redis.h:402:27: note: expanded from macro 'redisAssert' #define redisAssert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1)))
Sorry, I didn't get the warning, since the default Makefile uses gcc with the flag -Wall and the warning only appears using -Wextra (which enables -Wsign-compare). Maybe the default warning flag should change?
The warning actually exposed an interesting issue: I used int instead of unsigned long in setTypeRandomElements(), and so in the extreme case of SPOP being called with COUNT>MAXINT, an unsigned->signed conversion could have caused an issue (negative COUNT argument).
I doubt there's a use case which would ever need such a large COUNT, but still - it is an issue.
I created a fix, found in Pull Request #2224.