Skip to content

Commit

Permalink
Spreadsheet: Added code to throw under/overflow exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindkv authored and wwmayer committed Mar 8, 2016
1 parent ec7e920 commit 08044fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/Mod/Spreadsheet/App/ExpressionParser.l
Expand Up @@ -242,7 +242,14 @@ EXPO [eE][-+]?[0-9]+
{DIGIT}*"."{DIGIT}+{EXPO}? yylval.fvalue = num_change(yytext,'.',','); return yylval.fvalue == 1 ? ONE : NUM;
{DIGIT}*","{DIGIT}+{EXPO}? yylval.fvalue = num_change(yytext,',','.'); return yylval.fvalue == 1 ? ONE : NUM;
{DIGIT}+{EXPO} yylval.fvalue = num_change(yytext,',','.'); return yylval.fvalue == 1 ? ONE : NUM;
{DIGIT}+ yylval.ivalue = strtoll( yytext, NULL, 0 ); if (yylval.ivalue == 1) { yylval.fvalue = 1; return ONE; } else return INTEGER;
{DIGIT}+ {
yylval.ivalue = strtoll( yytext, NULL, 0 );
if (yylval.ivalue == LLONG_MIN)
throw Base::Exception("Integer underflow");
else if (yylval.ivalue == LLONG_MAX)
throw Base::Exception("Integer overflow");
if (yylval.ivalue == 1) { yylval.fvalue = 1; return ONE; } else return INTEGER;
}

"pi" yylval.constant.fvalue = M_PI; yylval.constant.name = "pi"; return CONSTANT; // constant pi
"e" yylval.constant.fvalue = M_E; yylval.constant.name = "e"; return CONSTANT; // constant e
Expand Down
8 changes: 7 additions & 1 deletion src/Mod/Spreadsheet/App/SpreadsheetExpression.cpp
Expand Up @@ -319,7 +319,13 @@ double num_change(char* yytext,char dez_delim,char grp_delim)
}
temp[i] = '\0';

ret_val = atof( temp );
errno = 0;
ret_val = strtod( temp, NULL );
if (ret_val == 0 && errno == ERANGE)
throw Base::Exception("Number underflow.");
if (ret_val == HUGE_VAL || ret_val == -HUGE_VAL)
throw Base::Exception("Number overflow.");

return ret_val;
}

Expand Down
29 changes: 18 additions & 11 deletions src/Mod/Spreadsheet/App/lex.ExpressionParser.c
Expand Up @@ -6299,36 +6299,43 @@ yylval.fvalue = num_change(ExpressionParsertext,',','.'); return yylval.fv
case 83:
YY_RULE_SETUP
#line 245 "ExpressionParser.l"
yylval.ivalue = strtoll( ExpressionParsertext, NULL, 0 ); if (yylval.ivalue == 1) { yylval.fvalue = 1; return ONE; } else return INTEGER;
{
yylval.ivalue = strtoll( ExpressionParsertext, NULL, 0 );
if (yylval.ivalue == LLONG_MIN)
throw Base::Exception("Integer underflow");
else if (yylval.ivalue == LLONG_MAX)
throw Base::Exception("Integer overflow");
if (yylval.ivalue == 1) { yylval.fvalue = 1; return ONE; } else return INTEGER;
}
YY_BREAK
case 84:
YY_RULE_SETUP
#line 247 "ExpressionParser.l"
#line 254 "ExpressionParser.l"
yylval.constant.fvalue = M_PI; yylval.constant.name = "pi"; return CONSTANT; // constant pi
YY_BREAK
case 85:
YY_RULE_SETUP
#line 248 "ExpressionParser.l"
#line 255 "ExpressionParser.l"
yylval.constant.fvalue = M_E; yylval.constant.name = "e"; return CONSTANT; // constant e
YY_BREAK
case 86:
YY_RULE_SETUP
#line 250 "ExpressionParser.l"
#line 257 "ExpressionParser.l"
yylval.string = ExpressionParsertext; return CELLADDRESS;
YY_BREAK
case 87:
YY_RULE_SETUP
#line 251 "ExpressionParser.l"
#line 258 "ExpressionParser.l"
yylval.string = ExpressionParsertext; return CELLADDRESS;
YY_BREAK
case 88:
YY_RULE_SETUP
#line 252 "ExpressionParser.l"
#line 259 "ExpressionParser.l"
yylval.string = ExpressionParsertext; return CELLADDRESS;
YY_BREAK
case 89:
YY_RULE_SETUP
#line 254 "ExpressionParser.l"
#line 261 "ExpressionParser.l"
{
std::string s = ExpressionParsertext;
size_t i = s.size() - 2;
Expand All @@ -6345,15 +6352,15 @@ YY_RULE_SETUP
YY_BREAK
case 90:
YY_RULE_SETUP
#line 268 "ExpressionParser.l"
#line 275 "ExpressionParser.l"
yylval.string = ExpressionParsertext; return IDENTIFIER;
YY_BREAK
case 91:
YY_RULE_SETUP
#line 269 "ExpressionParser.l"
#line 276 "ExpressionParser.l"
ECHO;
YY_BREAK
#line 6357 "lex.ExpressionParser.c"
#line 6364 "lex.ExpressionParser.c"
case YY_STATE_EOF(INITIAL):
yyterminate();

Expand Down Expand Up @@ -7311,4 +7318,4 @@ void ExpressionParserfree (void * ptr )

#define YYTABLES_NAME "yytables"

#line 269 "ExpressionParser.l"
#line 276 "ExpressionParser.l"

0 comments on commit 08044fb

Please sign in to comment.