1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 09:44:04 +00:00

Try to make $if_match better handle stranger inputs

This should fix sf.net #2953283
This commit is contained in:
Pavel Labath 2010-02-17 19:43:16 +01:00
parent edaf742295
commit 7bec4e0be8
2 changed files with 13 additions and 9 deletions

View File

@ -126,11 +126,9 @@ enum arg_type get_arg_type(const char *arg)
const char *p, *e;
p = arg;
e = arg + strlen(arg);
e = arg + strlen(arg)-1;
if (*(e - 1) == ' ')
e--;
while (*e && *e == ' ')
while (p != e && *e && *e == ' ')
e--;
while (p != e && *p == ' ')
p++;
@ -140,23 +138,23 @@ enum arg_type get_arg_type(const char *arg)
if (*p == '-') //allow negative values
p++;
while (p != e) {
while (p <= e) {
if (!isdigit(*p))
break;
p++;
}
if (p == e)
if (p == e+1)
return ARG_LONG;
if (*p == '.') {
p++;
while (p != e) {
while (p <= e) {
if (!isdigit(*p))
return ARG_STRING;
return ARG_BAD;
p++;
}
return ARG_DOUBLE;
}
return ARG_STRING;
return ARG_BAD;
}
char *arg_to_string(const char *arg)
@ -213,6 +211,10 @@ int compare(const char *expr)
type1 = get_arg_type(expr_dup);
type2 = get_arg_type(expr_dup + idx + 1);
if (type1 == ARG_BAD || type2 == ARG_BAD) {
NORM_ERR("Bad arguments: '%s' and '%s'", expr_dup, (expr_dup + idx + 1));
return -2;
}
if (type1 == ARG_LONG && type2 == ARG_DOUBLE)
type1 = ARG_DOUBLE;
if (type1 == ARG_DOUBLE && type2 == ARG_LONG)
@ -239,6 +241,7 @@ int compare(const char *expr)
case ARG_DOUBLE:
return dcompare(arg_to_double(expr_dup), mtype,
arg_to_double(expr_dup + idx + 1));
case ARG_BAD: /* make_gcc_happy() */;
}
/* not reached */
return -2;

View File

@ -40,6 +40,7 @@ enum match_type {
};
enum arg_type {
ARG_BAD = 0, /* something strange */
ARG_STRING = 1, /* "asdf" */
ARG_LONG = 2, /* 123456 */
ARG_DOUBLE = 3, /* 12.456 */