Skip to content

int vs size_t conversion and comparison#22

Open
LukeHHA wants to merge 1 commit into
noahpop77:mainfrom
LukeHHA:intCompFix
Open

int vs size_t conversion and comparison#22
LukeHHA wants to merge 1 commit into
noahpop77:mainfrom
LukeHHA:intCompFix

Conversation

@LukeHHA

@LukeHHA LukeHHA commented Aug 5, 2025

Copy link
Copy Markdown

The int type within the loop and as the type for randomIndex stuck out to me due to the consistent use of size_t within the class. I would recommend the change to size_t for consistency but also because signed vs unsigned comparison can lead to wrapping. As mentioned in the comments, while it would seem extremely unlikely that the number of keys would exceed INT_MAX it would lead to conversion semantics. This could potentially cause an unsigned value to become signed leading to a negative index or just UB.

  • feel free to ignore the cmakelist. It was just added so I could build the project. you can also include it as a very simple way to build with cmake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant