From 2ad2fea0bc53604f47e5b651425a6dfff463a2da Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 14 Feb 2015 13:46:21 +0100 Subject: [PATCH] Changed: Replaced atoi and atof by NLMISC::fromString --- code/nel/src/misc/config_file/cf_gramatical.cpp | 4 ++-- code/nel/src/misc/config_file/cf_gramatical.ypp | 4 ++-- code/nel/src/misc/config_file/cf_lexical.cpp | 2 +- code/nel/src/misc/config_file/config_file.cpp | 6 +++++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/code/nel/src/misc/config_file/cf_gramatical.cpp b/code/nel/src/misc/config_file/cf_gramatical.cpp index c6a50934f..bc51ef371 100644 --- a/code/nel/src/misc/config_file/cf_gramatical.cpp +++ b/code/nel/src/misc/config_file/cf_gramatical.cpp @@ -1499,7 +1499,7 @@ void cf_setVar (NLMISC::CConfigFile::CVar &Var, cf_value Val) switch (Val.Type) { case NLMISC::CConfigFile::CVar::T_REAL: Var.IntValues.push_back ((int)Val.Real); break; - case NLMISC::CConfigFile::CVar::T_STRING: Var.IntValues.push_back (atoi(Val.String)); break; + case NLMISC::CConfigFile::CVar::T_STRING: int val = 0; NLMISC::fromString(Val.String, val); Var.IntValues.push_back(val); break; default: break; } break; @@ -1507,7 +1507,7 @@ void cf_setVar (NLMISC::CConfigFile::CVar &Var, cf_value Val) switch (Val.Type) { case NLMISC::CConfigFile::CVar::T_INT: Var.RealValues.push_back ((double)Val.Int); break; - case NLMISC::CConfigFile::CVar::T_STRING: Var.RealValues.push_back (atof(Val.String)); break; + case NLMISC::CConfigFile::CVar::T_STRING: double val = 0.0; NLMISC::fromString(Val.String, val); Var.RealValues.push_back(val); break; default: break; } break; diff --git a/code/nel/src/misc/config_file/cf_gramatical.ypp b/code/nel/src/misc/config_file/cf_gramatical.ypp index 199f3df9a..0f4fd2405 100644 --- a/code/nel/src/misc/config_file/cf_gramatical.ypp +++ b/code/nel/src/misc/config_file/cf_gramatical.ypp @@ -517,7 +517,7 @@ void cf_setVar (NLMISC::CConfigFile::CVar &Var, cf_value Val) switch (Val.Type) { case NLMISC::CConfigFile::CVar::T_REAL: Var.IntValues.push_back ((int)Val.Real); break; - case NLMISC::CConfigFile::CVar::T_STRING: Var.IntValues.push_back (atoi(Val.String)); break; + case NLMISC::CConfigFile::CVar::T_STRING: int val = 0; NLMISC::fromString(Val.String, val); Var.RealValues.push_back(val); break; default: break; } break; @@ -525,7 +525,7 @@ void cf_setVar (NLMISC::CConfigFile::CVar &Var, cf_value Val) switch (Val.Type) { case NLMISC::CConfigFile::CVar::T_INT: Var.RealValues.push_back ((double)Val.Int); break; - case NLMISC::CConfigFile::CVar::T_STRING: Var.RealValues.push_back (atof(Val.String)); break; + case NLMISC::CConfigFile::CVar::T_STRING: double val = 0.0; NLMISC::fromString(Val.String, val); Var.RealValues.push_back(val); break; default: break; } break; diff --git a/code/nel/src/misc/config_file/cf_lexical.cpp b/code/nel/src/misc/config_file/cf_lexical.cpp index 80fd4fd36..8c39112a6 100644 --- a/code/nel/src/misc/config_file/cf_lexical.cpp +++ b/code/nel/src/misc/config_file/cf_lexical.cpp @@ -2337,7 +2337,7 @@ YY_RULE_SETUP if (!cf_Ignore) { cflval.Val.Type = T_REAL; - cflval.Val.Real = atof (yytext); + NLMISC::fromString(yytext, cflval.Val.Real); DEBUG_PRINTF("lex: real '%s' '%f\n", yytext, cflval.Val.Real); return REAL; } diff --git a/code/nel/src/misc/config_file/config_file.cpp b/code/nel/src/misc/config_file/config_file.cpp index 6113a7a2c..c969f614d 100644 --- a/code/nel/src/misc/config_file/config_file.cpp +++ b/code/nel/src/misc/config_file/config_file.cpp @@ -85,8 +85,12 @@ double CConfigFile::CVar::asDouble (int index) const if (index >= (int)IntValues.size () || index < 0) throw EBadSize (Name, (int)IntValues.size (), index); return (double)IntValues[index]; case T_STRING: + { if (index >= (int)StrValues.size () || index < 0) throw EBadSize (Name, (int)StrValues.size (), index); - return atof(StrValues[index].c_str()); + double val; + NLMISC::fromString(StrValues[index], val); + return val; + } default: if (index >= (int)RealValues.size () || index < 0) throw EBadSize (Name, (int)RealValues.size (), index); return RealValues[index];