From 64b22791a20056bc652ec1c9808d786358117f88 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 8 Apr 2021 18:34:56 +0200 Subject: Reorder things in libcontacts_same_number and fix an error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libcontacts_same_number.c | 16 ++++++++-------- 1 file 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 { -- cgit v1.2.3-70-g09d2