[FFmpeg-devel] [PATCH] Make parse_primary() fails if the expression string is interpreted as a number and evaluated with av_strtod(), but only the first part of the string is parsed.
Stefano Sabatini
stefano.sabatini-lala
Wed Jun 9 23:49:24 CEST 2010
---
libavutil/eval.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 59ebd94..cd4ea26 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -191,6 +191,10 @@ static int parse_primary(AVExpr **e, Parser *p)
/* number */
d->value = av_strtod(p->s, &next);
if (next != p->s) {
+ if (*next) {
+ av_log(p, AV_LOG_ERROR, "Expected number but found '%s'\n", p->s);
+ return AVERROR(EINVAL);
+ }
d->type = e_value;
p->s= next;
*e = d;
@@ -526,6 +530,24 @@ int main(void)
{
int i;
double d;
+ const char **expr, *exprs[] = {
+ "",
+ "foo",
+ "1",
+ "1foo",
+ "foo1",
+ "1gi",
+ "1Gi",
+ NULL
+ };
+
+ for (expr = exprs; *expr; expr++) {
+ av_parse_and_eval_expr(&d, *expr,
+ const_names, const_values,
+ NULL, NULL, NULL, NULL, NULL, 0, NULL);
+ printf("'%s' -> %f\n", *expr, d);
+ }
+
av_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
--
1.7.1
More information about the ffmpeg-devel
mailing list