mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-27 12:42:41 +00:00
Try to make $if_match better handle stranger inputs
This should fix sf.net #2953283
This commit is contained in:
parent
93d8b01f48
commit
3b7454fd9b
@ -126,11 +126,9 @@ enum arg_type get_arg_type(const char *arg)
|
|||||||
const char *p, *e;
|
const char *p, *e;
|
||||||
|
|
||||||
p = arg;
|
p = arg;
|
||||||
e = arg + strlen(arg);
|
e = arg + strlen(arg)-1;
|
||||||
|
|
||||||
if (*(e - 1) == ' ')
|
while (p != e && *e && *e == ' ')
|
||||||
e--;
|
|
||||||
while (*e && *e == ' ')
|
|
||||||
e--;
|
e--;
|
||||||
while (p != e && *p == ' ')
|
while (p != e && *p == ' ')
|
||||||
p++;
|
p++;
|
||||||
@ -140,23 +138,23 @@ enum arg_type get_arg_type(const char *arg)
|
|||||||
|
|
||||||
if (*p == '-') //allow negative values
|
if (*p == '-') //allow negative values
|
||||||
p++;
|
p++;
|
||||||
while (p != e) {
|
while (p <= e) {
|
||||||
if (!isdigit(*p))
|
if (!isdigit(*p))
|
||||||
break;
|
break;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if (p == e)
|
if (p == e+1)
|
||||||
return ARG_LONG;
|
return ARG_LONG;
|
||||||
if (*p == '.') {
|
if (*p == '.') {
|
||||||
p++;
|
p++;
|
||||||
while (p != e) {
|
while (p <= e) {
|
||||||
if (!isdigit(*p))
|
if (!isdigit(*p))
|
||||||
return ARG_STRING;
|
return ARG_BAD;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
return ARG_DOUBLE;
|
return ARG_DOUBLE;
|
||||||
}
|
}
|
||||||
return ARG_STRING;
|
return ARG_BAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *arg_to_string(const char *arg)
|
char *arg_to_string(const char *arg)
|
||||||
@ -213,6 +211,10 @@ int compare(const char *expr)
|
|||||||
|
|
||||||
type1 = get_arg_type(expr_dup);
|
type1 = get_arg_type(expr_dup);
|
||||||
type2 = get_arg_type(expr_dup + idx + 1);
|
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)
|
if (type1 == ARG_LONG && type2 == ARG_DOUBLE)
|
||||||
type1 = ARG_DOUBLE;
|
type1 = ARG_DOUBLE;
|
||||||
if (type1 == ARG_DOUBLE && type2 == ARG_LONG)
|
if (type1 == ARG_DOUBLE && type2 == ARG_LONG)
|
||||||
@ -239,6 +241,7 @@ int compare(const char *expr)
|
|||||||
case ARG_DOUBLE:
|
case ARG_DOUBLE:
|
||||||
return dcompare(arg_to_double(expr_dup), mtype,
|
return dcompare(arg_to_double(expr_dup), mtype,
|
||||||
arg_to_double(expr_dup + idx + 1));
|
arg_to_double(expr_dup + idx + 1));
|
||||||
|
case ARG_BAD: /* make_gcc_happy() */;
|
||||||
}
|
}
|
||||||
/* not reached */
|
/* not reached */
|
||||||
return -2;
|
return -2;
|
||||||
|
@ -40,6 +40,7 @@ enum match_type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum arg_type {
|
enum arg_type {
|
||||||
|
ARG_BAD = 0, /* something strange */
|
||||||
ARG_STRING = 1, /* "asdf" */
|
ARG_STRING = 1, /* "asdf" */
|
||||||
ARG_LONG = 2, /* 123456 */
|
ARG_LONG = 2, /* 123456 */
|
||||||
ARG_DOUBLE = 3, /* 12.456 */
|
ARG_DOUBLE = 3, /* 12.456 */
|
||||||
|
Loading…
Reference in New Issue
Block a user