Skip to content

Commit

Permalink
script parsing: if (non-int) not any longer an error
Browse files Browse the repository at this point in the history
An if expression that does not evaluate to int is not any longer
considered a parse error. It will generate a warning, but sr will
start.
This allows backward compatible if (@select) or if($avp).
  • Loading branch information
poandrei committed May 5, 2009
1 parent dae8ea8 commit 7f2853a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cfg.y
Original file line number Diff line number Diff line change
Expand Up @@ -1858,13 +1858,13 @@ action:
;
if_cmd:
IF rval_expr stm {
if (rval_expr_int_check($2)==0){
if (rval_expr_int_check($2)>=0){
warn_ct_rve($2, "if");
}
$$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, NOSUBTYPE, 0);
}
| IF rval_expr stm ELSE stm {
if (rval_expr_int_check($2)==0){
if (rval_expr_int_check($2)>=0){
warn_ct_rve($2, "if");
}
$$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, ACTIONS_ST, $5);
Expand Down Expand Up @@ -2806,7 +2806,8 @@ static void warn_at(struct cfg_pos* p, char* format, ...)
vsnprintf(s, sizeof(s), format, ap);
va_end(ap);
if (p->e_line!=p->s_line)
LOG(L_WARN, "warning in config file, from line %d, column %d to line %d, column %d: %s\n",
LOG(L_WARN, "warning in config file, from line %d, column %d to"
" line %d, column %d: %s\n",
p->s_line, p->s_col, p->e_line, p->e_col, s);
else if (p->s_col!=p->e_col)
LOG(L_WARN, "warning in config file, line %d, column %d-%d: %s\n",
Expand All @@ -2828,7 +2829,8 @@ static void yyerror_at(struct cfg_pos* p, char* format, ...)
vsnprintf(s, sizeof(s), format, ap);
va_end(ap);
if (p->e_line!=p->s_line)
LOG(L_CRIT, "parse error in config file, from line %d, column %d to line %d, column %d: %s\n",
LOG(L_CRIT, "parse error in config file, from line %d, column %d"
" to line %d, column %d: %s\n",
p->s_line, p->s_col, p->e_line, p->e_col, s);
else if (p->s_col!=p->e_col)
LOG(L_CRIT, "parse error in config file, line %d, column %d-%d: %s\n",
Expand Down Expand Up @@ -2948,7 +2950,7 @@ static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
/** check if the expression is an int.
* if the expression does not evaluate to an int return -1 and
* log an error.
* @return 0 on success, -1 on error */
* @return 0 success, no warnings; 1 success but warnings; -1 on error */
static int rval_expr_int_check(struct rval_expr *rve)
{
struct rval_expr* bad_rve;
Expand All @@ -2967,8 +2969,9 @@ static int rval_expr_int_check(struct rval_expr *rve)
yyerror("BUG: unexpected null \"bad\" expression\n");
return -1;
}else if (type!=RV_INT && type!=RV_NONE){
yyerror_at(&rve->fpos, "invalid expression type, int expected\n");
return -1;
warn_at(&rve->fpos, "non-int expression (you might want to use"
" casts)\n");
return 1;
}
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions route.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,12 +712,16 @@ int fix_actions(struct action* a)
rve->fpos.s_line, rve->fpos.s_col);
return E_UNSPEC;
}
/* it's not an error anymore to have non-int in an if,
only a script warning (to allow backward compat. stuff
like if (@ruri)
if (rve_type!=RV_INT && rve_type!=RV_NONE){
LOG(L_ERR, "fix_actions: invalid expression (%d,%d):"
" bad type, integer expected\n",
rve->fpos.s_line, rve->fpos.s_col);
return E_UNSPEC;
}
*/
if ((ret=fix_rval_expr((void**)&rve))<0)
return ret;
}
Expand Down

0 comments on commit 7f2853a

Please sign in to comment.