From 0333652fdc3e549aa0f23e4d529d671a9a2514b7 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Sun, 5 Sep 2021 12:29:12 +0200 Subject: [PATCH] C phone-number: more comments --- c/phone-number/phone_number.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/c/phone-number/phone_number.c b/c/phone-number/phone_number.c index e2c4ace..22c5773 100644 --- a/c/phone-number/phone_number.c +++ b/c/phone-number/phone_number.c @@ -17,7 +17,7 @@ static char *scan="%m[+(0-9]%*[()-. ]%m[0-9]%*[)-. ]%m[0-9]%*[-. ]%m[0-9]"; char *phone_number_clean(const char *input) { - char *sn[4] = { 0 }; + char *sn[4]; uint64_t num[4]; uint64_t *p = &*num; int nmatch; @@ -37,6 +37,8 @@ char *phone_number_clean(const char *input) switch (nmatch) { case 2: + /* maybe 2 could be valid, like 333 3334444 ? + */ case 0: return res; case 1: /* full number */ @@ -58,6 +60,9 @@ char *phone_number_clean(const char *input) return res; break; } + /* we don't care if some num has random value here (initialized), snprintf + * will consume only what is needed to fill the number + */ snprintf(res, LEN_NUM+1, "%ld%ld%ld", *p, *(p+1), *(p+2)); return res;