Commit e2adce1b by Corentin Wallez

Workaround for some STLs not parsing floats with a suffix

BUG=angleproject:1046 BUG=angleproject:891 Change-Id: I01c3f024142e573385a5f40d721171ad752ffd19 Reviewed-on: https://chromium-review.googlesource.com/278210Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 52445286
......@@ -504,7 +504,9 @@ int floatsuffix_check(TParseContext* context)
return 0;
}
if (!atof_clamp(yytext, &(yylval->lex.f)))
std::string text = yytext;
text.resize(text.size() - 1);
if (!strtof_clamp(text, &(yylval->lex.f)))
yyextra->warning(*yylloc, "Float overflow", yytext, "");
return(FLOATCONSTANT);
......@@ -526,7 +528,7 @@ int int_constant(yyscan_t yyscanner) {
int float_constant(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
if (!atof_clamp(yytext, &(yylval->lex.f)))
if (!strtof_clamp(yytext, &(yylval->lex.f)))
yyextra->warning(*yylloc, "Float overflow", yytext, "");
return FLOATCONSTANT;
}
......
......@@ -3339,7 +3339,9 @@ int floatsuffix_check(TParseContext* context)
return 0;
}
if (!atof_clamp(yytext, &(yylval->lex.f)))
std::string text = yytext;
text.resize(text.size() - 1);
if (!strtof_clamp(text, &(yylval->lex.f)))
yyextra->warning(*yylloc, "Float overflow", yytext, "");
return(FLOATCONSTANT);
......@@ -3361,7 +3363,7 @@ int int_constant(yyscan_t yyscanner) {
int float_constant(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
if (!atof_clamp(yytext, &(yylval->lex.f)))
if (!strtof_clamp(yytext, &(yylval->lex.f)))
yyextra->warning(*yylloc, "Float overflow", yytext, "");
return FLOATCONSTANT;
}
......
......@@ -12,7 +12,7 @@
#include "compiler/translator/SymbolTable.h"
#include "common/utilities.h"
bool atof_clamp(const char *str, float *value)
bool strtof_clamp(const std::string &str, float *value)
{
bool success = pp::numeric_lex_float(str, value);
if (!success)
......
......@@ -14,15 +14,15 @@
#include "compiler/translator/Types.h"
// atof_clamp is like atof but
// strtof_clamp is like strtof but
// 1. it forces C locale, i.e. forcing '.' as decimal point.
// 2. it clamps the value to -FLT_MAX or FLT_MAX if overflow happens.
// Return false if overflow happens.
extern bool atof_clamp(const char *str, float *value);
bool strtof_clamp(const std::string &str, float *value);
// If overflow happens, clamp the value to INT_MIN or INT_MAX.
// Return false if overflow happens.
extern bool atoi_clamp(const char *str, int *value);
bool atoi_clamp(const char *str, int *value);
class TSymbolTable;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment