aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-04-08 18:34:56 +0200
committerMattias Andrée <maandree@kth.se>2021-04-08 18:34:56 +0200
commit64b22791a20056bc652ec1c9808d786358117f88 (patch)
tree10ba7edc288c062cf49d53de715a68256db55a47
parentAdd with_me parameter to libcontacts_list_contacts and libcontacts_load_contacts (diff)
downloadlibcontacts-64b22791a20056bc652ec1c9808d786358117f88.tar.gz
libcontacts-64b22791a20056bc652ec1c9808d786358117f88.tar.bz2
libcontacts-64b22791a20056bc652ec1c9808d786358117f88.tar.xz
Reorder things in libcontacts_same_number and fix an error
Signed-off-by: Mattias Andrée <maandree@kth.se>
-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 {