-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace rand() and srand(). fix #390 #391
Conversation
@@ -343,16 +343,16 @@ void init_boe(int argc, char* argv[]) { | |||
Element& srand_element = pop_next_action("srand"); | |||
|
|||
std::string ts(srand_element.GetText()); | |||
srand(atoi(ts.c_str())); | |||
game_rand.seed(atoi(ts.c_str())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really related to the PR, but I think std::stoi
might be better than atoi
here. Also removes the need to call c_str()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do a PR after this one that replaces atoi throughout the codebase, here are all the places we're using it:
$ rg atoi
src/location.cpp
245: l.x = atoi(sstr.str().c_str());
249: l.y = atoi(sstr.str().c_str());
src/fileio/xml-parser/tinyxml.cpp
578: *i = atoi( s );
595: *i = atoi( s->c_str() );
1275: return atoi (value.c_str ());
src/fileio/xml-parser/tutorial_ticpp.txt
113:int attr = atoi( pszAttr );
src/dialogxml/dialogs/dialog.cpp
544: eKeyMod mods = static_cast<eKeyMod>(atoi(info["mods"].c_str()));
src/game/boe.main.cpp
267: eStartButton btn = static_cast<eStartButton>(atoi(next_action.GetText().c_str()));
346: srand(atoi(ts.c_str()));
the xml-parser uses will stay the same. Everywhere else we call atoi() it is a clunky c_str() round-trip conversion like you pointed out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xml-parser is an external library, so yeah, leaving it untouched makes sense. Looks like there aren't that many uses beside the xml-parser. It's likely they were added before 2011 so stoi
wasn't even available.
I'm a little surprised that this change is so small. |
Luckily most of the rand() calls were wrapped in get_ran() |
I guess not including |
No description provided.