From: oetiker Date: Mon, 29 Apr 2002 17:11:03 +0000 (+0000) Subject: badformat parser fixed ... for good this time I hope X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=947fd481664a9595d3595b1c447e1b836ea07cdf;p=rrdtool.git badformat parser fixed ... for good this time I hope git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@133 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 89a67c0..17ec03a 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -3243,36 +3243,41 @@ rrd_graph_legend(graph_desc_t *gdp, char *line) int bad_format(char *fmt) { - char *ptr; - int n=0; - - ptr = fmt; - while (*ptr != '\0') { - if (*ptr == '%') {ptr++; - if (*ptr == '\0') return 1; - while ((*ptr >= '0' && *ptr <= '9') || *ptr == '.') { - ptr++; - } - if (*ptr == '\0') return 1; - else if (*ptr == ' ') ptr++; - else if (*ptr == '-') ptr++; - else if (*ptr == '+') ptr++; - if (*ptr == 'l') { - ptr++; - n++; - if (*ptr == '\0') return 1; - if (*ptr == 'e' || *ptr == 'f') { - ptr++; - } else { return 1; } - } - else if (*ptr == 's' || *ptr == 'S' || *ptr == '%') { ++ptr; } - else { return 1; } - } else { - ++ptr; - } - } - return (n!=1); + char *ptr; + int n=0; + ptr = fmt; + while (*ptr != '\0') + if (*ptr++ == '%') { + + /* line cannot end with percent char */ + if (*ptr == '\0') return 1; + + /* '%s', '%S' and '%%' are allowed */ + if (*ptr == 's' || *ptr == 'S' || *ptr == '%') ptr++; + + /* or else '% 6.2lf' and such are allowed */ + else { + + /* optional padding character */ + if (*ptr == ' ' || *ptr == '+' || *ptr == '-') ptr++; + + /* This should take care of 'm.n' with all three optional */ + while (*ptr >= '0' && *ptr <= '9') ptr++; + if (*ptr == '.') ptr++; + while (*ptr >= '0' && *ptr <= '9') ptr++; + + /* Either 'le' or 'lf' must follow here */ + if (*ptr++ != 'l') return 1; + if (*ptr == 'e' || *ptr == 'f') ptr++; + else return 1; + n++; + } + } + + return (n!=1); } + + int vdef_parse(gdes,str) struct graph_desc_t *gdes; @@ -3359,6 +3364,8 @@ char *str; }; return 0; } + + int vdef_calc(im,gdi) image_desc_t *im;