[Spice-devel] [usbredir PATCH 6/6] usbredirfilter: fix filter parsing for windows (mingw)
Uri Lublin
uril at redhat.com
Thu May 3 08:04:39 PDT 2012
From: Arnon Gilboa <agilboa at redhat.com>
no strtok_r (reentrent) available, so use strtok instead.
Modified-by: Uri Lublin <uril at redhat.com>
---
usbredirparser/usbredirfilter.c | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/usbredirparser/usbredirfilter.c b/usbredirparser/usbredirfilter.c
index b74c921..a1213cc 100644
--- a/usbredirparser/usbredirfilter.c
+++ b/usbredirparser/usbredirfilter.c
@@ -29,7 +29,7 @@ int usbredirfilter_string_to_rules(
const char *filter_str, const char *token_sep, const char *rule_sep,
struct usbredirfilter_rule **rules_ret, int *rules_count_ret)
{
- char *rule, *rule_saveptr, *token, *token_saveptr, *ep;
+ char *rule, *token, *ep, *buf_end, *rule_end;
struct usbredirfilter_rule *rules = NULL;
int i, rules_count, *values, ret = 0;
char *buf = NULL;
@@ -63,17 +63,19 @@ int usbredirfilter_string_to_rules(
}
/* And actually parse the string */
+ buf_end = buf + strlen(buf);
rules_count = 0;
- rule = strtok_r(buf, rule_sep, &rule_saveptr);
+ rule = strtok(buf, rule_sep);
while (rule) {
+ rule_end = rule + strlen(rule);
/* We treat the filter rule as an array of ints for easier parsing */
values = (int *)&rules[rules_count];
- token = strtok_r(rule, token_sep, &token_saveptr);
+ token = strtok(rule, token_sep);
for (i = 0; i < 5 && token; i++) {
values[i] = strtol(token, &ep, 0);
if (*ep)
break;
- token = strtok_r(NULL, token_sep, &token_saveptr);
+ token = strtok(NULL, token_sep);
}
if (i != 5 || token != NULL ||
usbredirfilter_verify(&rules[rules_count], 1)) {
@@ -81,7 +83,11 @@ int usbredirfilter_string_to_rules(
goto leave;
}
rules_count++;
- rule = strtok_r(NULL, rule_sep, &rule_saveptr);
+ if (rule_end < buf_end) {
+ rule = strtok(rule_end + 1, rule_sep);
+ } else {
+ rule = NULL;
+ }
}
*rules_ret = rules;
--
1.7.7.6
More information about the Spice-devel
mailing list