aboutsummaryrefslogtreecommitdiffstats
path: root/libcontacts_same_number.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libcontacts_same_number.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/libcontacts_same_number.c b/libcontacts_same_number.c
index cfdcc7c..25e19e0 100644
--- a/libcontacts_same_number.c
+++ b/libcontacts_same_number.c
@@ -27,31 +27,31 @@ canonicalise(const char *number, const char *country, char **post_cccp)
*post_cccp = NULL;
- for (p = number, skip = 0; *p; p++) {
+ for (p = country, skip = 0; *p; p++) {
digit = digits[*p & 255];
if (digit) {
if (*digit == '(')
skip += 1;
else if (*digit == ')')
skip -= !!skip;
- else
- nlen += digit[1] ? 2 : 1;
+ else if (!skip)
+ clen += digit[1] ? 2 : 1;
}
}
- for (p = country, skip = 0; *p; p++) {
+ for (p = number, skip = 0; *p; p++) {
digit = digits[*p & 255];
if (digit) {
if (*digit == '(')
skip += 1;
else if (*digit == ')')
skip -= !!skip;
- else
- clen += digit[1] ? 2 : 1;
+ else if (!skip)
+ nlen += digit[1] ? 2 : 1;
}
}
- r = ret = malloc(nlen + clen + 3);
+ r = ret = malloc(clen + nlen + 3);
if (!ret)
return NULL;
@@ -95,7 +95,7 @@ canonicalise(const char *number, const char *country, char **post_cccp)
}
*r = '\0';
- if (r[clen] != '0') {
+ if (ret[clen] != '0') {
*post_cccp = NULL;
memmove(ret, &ret[clen], nlen + 1);
} else {