don't modify input string in parsedomains - surf-adblock - Surf adblock web ext… | |
git clone git://git.codemadness.org/surf-adblock | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 362d380c606bf80d11d59682ec33bbe64534b50f | |
parent ab4d1e8f7ed4eafd6d1a7a99bc183944c1dc7e41 | |
Author: Quentin Rameau <[email protected]> | |
Date: Mon, 18 Jul 2016 01:06:05 +0200 | |
don't modify input string in parsedomains | |
Diffstat: | |
M surf-adblock.c | 18 ++++++++---------- | |
1 file changed, 8 insertions(+), 10 deletions(-) | |
--- | |
diff --git a/surf-adblock.c b/surf-adblock.c | |
@@ -416,7 +416,7 @@ domain=... if domain is prefixed with ~, ignore. | |
multiple domains can be separated with | | |
*/ | |
static int | |
-parsedomains(char *s, int sep, struct filterdomain **head) | |
+parsedomains(const char *s, int sep, struct filterdomain **head) | |
{ | |
struct filterdomain *d, *last = *head = NULL; | |
char *p; | |
@@ -431,12 +431,15 @@ parsedomains(char *s, int sep, struct filterdomain **head) | |
if (!*s || *s == sep) | |
break; | |
- if ((p = strchr(s, sep))) /* TODO: should not contain , */ | |
- *p = '\0'; | |
- | |
if (!(d = wecalloc(1, sizeof(struct filterdomain)))) | |
return -1; | |
- if (!(d->domain = westrdup(s))) | |
+ if (p = strchr(s, sep)) { /* TODO: should not contain ',' */ | |
+ d->domain = westrndup(s, p - s); | |
+ s = p + 1; | |
+ } else { | |
+ d->domain = westrdup(s); | |
+ } | |
+ if (!d->domain) | |
return -1; | |
d->inverse = inverse; | |
@@ -444,11 +447,6 @@ parsedomains(char *s, int sep, struct filterdomain **head) | |
*head = last = d; | |
else | |
last = last->next = d; | |
- | |
- if (p) { | |
- *p = sep; | |
- s = p + 1; | |
- } | |
} while (p); | |
return (*head != NULL); |