mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 06:28:19 +00:00
Replace atof
usages with strtod
(str_tofloat
wrapper)
As `atof` does not provide any way to detect errors and can cause undefined behavior on errors, i.e. when the result cannot be represented as a `float`. References: - https://wiki.sei.cmu.edu/confluence/display/c/ERR07-C.+Prefer+functions+that+support+error+checking+over+equivalent+functions+that+don%27t - https://pubs.opengroup.org/onlinepubs/9699919799/functions/atof.html
This commit is contained in:
parent
6b043bf3b2
commit
1469e88a79
|
@ -3402,7 +3402,7 @@ int str_isallnum(const char *str)
|
|||
int str_toint(const char *str) { return str_toint_base(str, 10); }
|
||||
int str_toint_base(const char *str, int base) { return strtol(str, NULL, base); }
|
||||
unsigned long str_toulong_base(const char *str, int base) { return strtoul(str, NULL, base); }
|
||||
float str_tofloat(const char *str) { return atof(str); }
|
||||
float str_tofloat(const char *str) { return strtod(str, NULL); }
|
||||
|
||||
int str_utf8_comp_nocase(const char *a, const char *b)
|
||||
{
|
||||
|
|
|
@ -80,10 +80,10 @@ int main(int argc, const char *argv[])
|
|||
|
||||
for(int i = 0; i < 2; i++)
|
||||
{
|
||||
aaaGameAreas[i][0][0] = atof(argv[2 + i * 3]) * 32; //x
|
||||
aaaGameAreas[i][1][0] = atof(argv[3 + i * 3]) * 32; //y
|
||||
aaaGameAreas[i][0][1] = aaaGameAreas[i][0][0] + atof(argv[7]) * 32; //x + width
|
||||
aaaGameAreas[i][1][1] = aaaGameAreas[i][1][0] + atof(argv[8]) * 32; //y + height
|
||||
aaaGameAreas[i][0][0] = str_tofloat(argv[2 + i * 3]) * 32; //x
|
||||
aaaGameAreas[i][1][0] = str_tofloat(argv[3 + i * 3]) * 32; //y
|
||||
aaaGameAreas[i][0][1] = aaaGameAreas[i][0][0] + str_tofloat(argv[7]) * 32; //x + width
|
||||
aaaGameAreas[i][1][1] = aaaGameAreas[i][1][0] + str_tofloat(argv[8]) * 32; //y + height
|
||||
}
|
||||
|
||||
cmdline_free(argc, argv);
|
||||
|
|
Loading…
Reference in a new issue