X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Feval.c;h=4e2cb1095ca981c67a3c81e34341b78296102ac2;hb=f863cdef813e51d5850e2386618feafe197f06f4;hp=36cc76d3bf43dc3a8495f85bce76e44dfc10b20b;hpb=83f9bc8aeece0d7c5b1fadaf91118ee6a97a0390;p=ffmpeg diff --git a/libavutil/eval.c b/libavutil/eval.c index 36cc76d3bf4..4e2cb1095ca 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -28,6 +28,7 @@ #include "avutil.h" #include "eval.h" +#include "log.h" typedef struct Parser { const AVClass *class; @@ -76,7 +77,7 @@ double av_strtod(const char *numstr, char **tail) double d; char *next; if(numstr[0]=='0' && (numstr[1]|0x20)=='x') { - d = strtol(numstr, &next, 16); + d = strtoul(numstr, &next, 16); } else d = strtod(numstr, &next); /* if parsing succeeded, check for and interpret postfixes */ @@ -471,7 +472,7 @@ int av_expr_parse(AVExpr **expr, const char *s, const char * const *func2_names, double (* const *funcs2)(void *, double, double), int log_offset, void *log_ctx) { - Parser p; + Parser p = { 0 }; AVExpr *e = NULL; char *w = av_malloc(strlen(s) + 1); char *wp = w; @@ -499,6 +500,7 @@ int av_expr_parse(AVExpr **expr, const char *s, if ((ret = parse_expr(&e, &p)) < 0) goto end; if (*p.s) { + av_expr_free(e); av_log(&p, AV_LOG_ERROR, "Invalid chars '%s' at the end of expression '%s'\n", p.s, s0); ret = AVERROR(EINVAL); goto end; @@ -516,7 +518,7 @@ end: double av_expr_eval(AVExpr *e, const double *const_values, void *opaque) { - Parser p; + Parser p = { 0 }; p.const_values = const_values; p.opaque = opaque; @@ -575,6 +577,8 @@ void av_free_expr(AVExpr *e) #ifdef TEST #undef printf +#include + static double const_values[] = { M_PI, M_E, @@ -587,7 +591,7 @@ static const char *const_names[] = { 0 }; -int main(void) +int main(int argc, char **argv) { int i; double d; @@ -598,7 +602,7 @@ int main(void) "-PI", "+PI", "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", - "80G/80Gi" + "80G/80Gi", "1k", "1Gi", "1gi", @@ -656,7 +660,11 @@ int main(void) av_expr_parse_and_eval(&d, *expr, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, NULL); - printf("'%s' -> %f\n\n", *expr, d); + if(isnan(d)){ + printf("'%s' -> nan\n\n", *expr); + }else{ + printf("'%s' -> %f\n\n", *expr, d); + } } av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", @@ -668,13 +676,16 @@ int main(void) NULL, NULL, NULL, NULL, NULL, 0, NULL); printf("%f == 0.931322575\n", d); - for (i=0; i<1050; i++) { - START_TIMER + if (argc > 1 && !strcmp(argv[1], "-t")) { + for (i = 0; i < 1050; i++) { + START_TIMER; av_expr_parse_and_eval(&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); - STOP_TIMER("av_expr_parse_and_eval") + STOP_TIMER("av_expr_parse_and_eval"); + } } + return 0; } #endif