From patchwork Wed Jun 4 20:42:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 894012 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:430c:b0:3a4:ee3f:8f15 with SMTP id eq12csp24309wrb; Wed, 4 Jun 2025 13:45:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWfoQuSFslBKGx6z7E7Aq1LMMyiUeRTUOkKCtXLWbqcrbWMc7lAo9ccmty6D3JmkzZhAvzDxw==@linaro.org X-Google-Smtp-Source: AGHT+IHaetwVu2xL9EKv4aqtw13QqAQGqKo61pZN51/18lOjl3dEnJmLfMBssKHOzI0f+B3lRasM X-Received: by 2002:a05:622a:5a8c:b0:4a4:3825:8e12 with SMTP id d75a77b69052e-4a5a57d98f9mr75855801cf.28.1749069922692; Wed, 04 Jun 2025 13:45:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1749069922; cv=pass; d=google.com; s=arc-20240605; b=IhnCqTB/hZoMCdDT89m+OkAwbBwFd+sfQ3OAqLmkxTnI6xH3BSQc6hpaK5JaoDcaFM h4iXNX9w5o14HK1/K8Ru8Z2g43b0AF6c+uEjBa8Pd+I8uFMUuz28WqmSgDlBTFjY8NGl M35kugYTrqlutMI9r0VMEQQdEE35JDLxOK1y2QSc6cmzfHvy2WdBKrAkrPMFXdv5Yv+e hIlfrQGPbupRmY9EnrQxBRVHx4qZ2+Cclc3eXHM5KqllGocX1edDyqOQyq2rItXa9StM yQWYO0IvVtqdyE1QHLX8SDOE1TnZOiC6cO4hIW2DGOOlU5Y7tf2XoKTsIugNIRYCnyrd SG2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter:arc-filter:dmarc-filter :delivered-to:dkim-filter; bh=Bac6K/9hcy0Bb7f1kAOCbYB15zLWaam3vK69YV7duHU=; fh=15rxvXN7K0X9p6jPVVxe1y5/53BpC+bqjxiOTDwET+E=; b=DoOV1jo9tEtKyjQKtCMNqwgh8Wx/qULfLfcFAmgi4Hf3DZSRs29b4SxFpYYXXD0i+O 4gZUH1Ysqki4k+HzLONCQm56Si0d8p9p3QEcNgw91XKMxsUngQ9ZRPN4CsF5U6WgZhIP NHBekW8jnPSML1e/tGp9MsCW6xph5ZSIafuBK9KBFEJbPjL2d0FDBbuGHIzVA3SV6+lH rJ3dYLedbmoirjlLouP1SakuRHvPAOJ7L4ZSjcsDd2B0LoUBRWahCjzig7Zsu+sgNrJF cVan2r52VUhaQoN08tF2wqannJjHQc14PSaou6rc2gxiVlRFHfxMOS4zDHbCqX34WpDL KkFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OIuM9FCC; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d75a77b69052e-4a435a71c7asi162628161cf.514.2025.06.04.13.45.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 13:45:22 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OIuM9FCC; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 409043857839 for ; Wed, 4 Jun 2025 20:45:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 409043857839 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=OIuM9FCC X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ua1-x935.google.com (mail-ua1-x935.google.com [IPv6:2607:f8b0:4864:20::935]) by sourceware.org (Postfix) with ESMTPS id 87DE03858C48 for ; Wed, 4 Jun 2025 20:43:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87DE03858C48 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 87DE03858C48 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::935 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749069824; cv=none; b=EFV/NGwfRAvYXWm73+xLZoOs2qKBMxnrFzQ2E544J86R5jbIFlP3DoVl2edP6GaeLWlE37OG1G6/LMuiIz9qbe/48CJI+KeCPyFrtHThCC6QRXkPAXV0GgLh5q7NTQkItBsayoC62qZlYyhtPARVtwtaAQFUrBF4bkVhcE3eNZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749069824; c=relaxed/simple; bh=fwy8M8yLZpyqUAYrTaG3+lFkBfkgXvyALuCwR+eQjvw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dONC+3sk40sAzG10bq3cpBcbBy5W7UJawvnycXFDYDOQ8W+JGhV/wjISCyeVmY4EwY3XFWgK+aj268EZKnIK8gBuNobypxHnMKV8wp9QxvWPOQHiZVYuhR3XMdUYYE1Ne225ggDEJhcesE6k390ep3YVIKhI+p6O5MTJruAvkkQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 87DE03858C48 Received: by mail-ua1-x935.google.com with SMTP id a1e0cc1a2514c-87dfabe9272so92454241.3 for ; Wed, 04 Jun 2025 13:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1749069823; x=1749674623; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bac6K/9hcy0Bb7f1kAOCbYB15zLWaam3vK69YV7duHU=; b=OIuM9FCCuB2h8V/zzC4RS6CnLb+CVf2w+tOLt6YVC/LY/ezGJsOtodfct4mQ6g0kBs biLMKz0uqxzTYFysaMmFb/zvBK/yE3ecl8dSZmXMuAHwQQA2iBOeaf2USxco5y6Pld1c x6cZYabIjuxM0RcYRPe3bpYgx8BNkH5uueyD9Q+gCwC0amj4U3DLYYDUIWC/8Fp9mRQP kr74mBxVPQzDsQnwEP/ip5ynfEZXA9c+jlCVq0E0rNF14bpox6+StAk2Sk8+bPk/9/xs VnRhSYPGWOKE65hcsCAX4Kak7Q6Pmov9O3GvXSTX7lE2zp10JsGvgrSLE5blfxjWxx0+ fSHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749069823; x=1749674623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bac6K/9hcy0Bb7f1kAOCbYB15zLWaam3vK69YV7duHU=; b=JFhh2CHZIkHK5QdUvWJCCbI0LZ9eBXB33Polq3WxNCJcLdfoM8ewP1VkmkRy10ifWt BGUCv5unqLlsSSK2YBR29gX+UnUBmoQJp02gbRhZhleppe50MrVBMNixg45+x9F36zbp tHm/mFEtorEPFzx+SnN8K10H2ObSGxVldx2DUyTuKlESA/EgdsC6Jg35BaTbh3uheqA7 X0Pc5wRv7YFjVHQn8xd1rlDfzvlN7x0iHI7LyvXwTuqII4J9ezlUfYyDFq05FgkHC+RB SO20ai30/WbhZbIaHAgN0OpmlWDCbKS38zI9s7krjs86atizqF3LGEKp1DL8bhfvnGZF U4bg== X-Gm-Message-State: AOJu0Yyv7XS8yTunHhdsExsZMOErHLZrYcS9lIcQL7BjOGU0YXeYJCng dSKwjrnpmHPLZZbaoGuxVo5V1COyVWDwbuqRkLDdOdjJ61l5h+l7KaIqbh/H5iSKC3yhj52yqgh qA0HF X-Gm-Gg: ASbGnctWzWVTHuZYS5x2qGBE+Iv70/ho7G6bnqKHm4WiGRTByhRmyS+LPbL9k27QWEQ afYNABFW6ixQiIFphj/C/TdpG4ogJyCT/4kLio+d1JU/5T21VVPd2qXhEG4lI2T/GwQgQothL8i gXasiF3+0Exj8m/kGf9SajlF34ZlK9i+OlLPuogrqNO3MoGI/LphsemBAl7AGN8zTvqA8OWd+5Q XeTrMkwNB6FRjnMOO8lk0hWF/D4WH0BXMU+AkCu8uX29CmvKNprhzzlV6i27dL+nxoTB8QtiB9E wlh+2TSHEouk0zC6SGznLnxNe7JWNJQWQnLLBvqgHA9Jn3nwduuEqOxiZPoQfqb4wTSBALNN0z4 = X-Received: by 2002:a05:6102:3746:b0:4e5:a6ad:8fee with SMTP id ada2fe7eead31-4e746e68e3amr4135650137.19.1749069823391; Wed, 04 Jun 2025 13:43:43 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:8c5f:1160:8942:85f9:1203]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-87eaac49cdesm1020317241.2.2025.06.04.13.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 13:43:43 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Collin Funk , Paul Eggert , Florian Weimer Subject: [PATCH v2 3/5] resolve: Proper indent resolv/inet_ntop.c Date: Wed, 4 Jun 2025 17:42:42 -0300 Message-ID: <20250604204332.2090912-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250604204332.2090912-1-adhemerval.zanella@linaro.org> References: <20250604204332.2090912-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org --- resolv/inet_ntop.c | 207 ++++++++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 97 deletions(-) diff --git a/resolv/inet_ntop.c b/resolv/inet_ntop.c index acf5f3cb88..5c414373b7 100644 --- a/resolv/inet_ntop.c +++ b/resolv/inet_ntop.c @@ -28,9 +28,9 @@ #include #ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) +# define SPRINTF(x) strlen (sprintf /**/ x) #else -# define SPRINTF(x) ((size_t)sprintf x) +# define SPRINTF(x) ((size_t) sprintf x) #endif /* @@ -52,16 +52,17 @@ static const char *inet_ntop6 (const u_char *src, char *dst, socklen_t size); const char * __inet_ntop (int af, const void *src, char *dst, socklen_t size) { - switch (af) { - case AF_INET: - return (inet_ntop4(src, dst, size)); - case AF_INET6: - return (inet_ntop6(src, dst, size)); - default: - __set_errno (EAFNOSUPPORT); - return (NULL); - } - /* NOTREACHED */ + switch (af) + { + case AF_INET: + return (inet_ntop4 (src, dst, size)); + case AF_INET6: + return (inet_ntop6 (src, dst, size)); + default: + __set_errno (EAFNOSUPPORT); + return (NULL); + } + /* NOTREACHED */ } libc_hidden_def (__inet_ntop) weak_alias (__inet_ntop, inet_ntop) @@ -80,14 +81,15 @@ weak_alias (__inet_ntop, inet_ntop) static const char * inet_ntop4 (const u_char *src, char *dst, socklen_t size) { - static const char fmt[] = "%u.%u.%u.%u"; - char tmp[sizeof "255.255.255.255"]; + static const char fmt[] = "%u.%u.%u.%u"; + char tmp[sizeof "255.255.255.255"]; - if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) >= size) { - __set_errno (ENOSPC); - return (NULL); - } - return strcpy(dst, tmp); + if (SPRINTF ((tmp, fmt, src[0], src[1], src[2], src[3])) >= size) + { + __set_errno (ENOSPC); + return (NULL); + } + return strcpy (dst, tmp); } /* const char * @@ -99,88 +101,99 @@ inet_ntop4 (const u_char *src, char *dst, socklen_t size) static const char * inet_ntop6 (const u_char *src, char *dst, socklen_t size) { - /* - * Note that int32_t and int16_t need only be "at least" large enough - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; - struct { int base, len; } best, cur; - u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; - int i; + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; + struct + { + int base, len; + } best, cur; + u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; + int i; - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset(words, '\0', sizeof words); - for (i = 0; i < NS_IN6ADDRSZ; i += 2) - words[i / 2] = (src[i] << 8) | src[i + 1]; - best.base = -1; - cur.base = -1; - best.len = 0; - cur.len = 0; - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { - if (words[i] == 0) { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } else { - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + memset (words, '\0', sizeof words); + for (i = 0; i < NS_IN6ADDRSZ; i += 2) + words[i / 2] = (src[i] << 8) | src[i + 1]; + best.base = -1; + cur.base = -1; + best.len = 0; + cur.len = 0; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) + { + if (words[i] == 0) + { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; } - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; + else + { + if (cur.base != -1) + { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } } - if (best.base != -1 && best.len < 2) - best.base = -1; + } + if (cur.base != -1) + { + if (best.base == -1 || cur.len > best.len) + best = cur; + } + if (best.base != -1 && best.len < 2) + best.base = -1; - /* - * Format the result. - */ - tp = tmp; - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { - /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && - i < (best.base + best.len)) { - if (i == best.base) - *tp++ = ':'; - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) - *tp++ = ':'; - /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) - return (NULL); - tp += strlen(tp); - break; - } - tp += SPRINTF((tp, "%x", words[i])); + /* + * Format the result. + */ + tp = tmp; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) + { + /* Are we inside the best run of 0x00's? */ + if (best.base != -1 && i >= best.base && i < (best.base + best.len)) + { + if (i == best.base) + *tp++ = ':'; + continue; } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == - (NS_IN6ADDRSZ / NS_INT16SZ)) - *tp++ = ':'; - *tp++ = '\0'; + /* Are we following an initial run of 0x00s or any real hex? */ + if (i != 0) + *tp++ = ':'; + /* Is this address an encapsulated IPv4? */ + if (i == 6 && best.base == 0 + && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) + { + if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp))) + return (NULL); + tp += strlen (tp); + break; + } + tp += SPRINTF ((tp, "%x", words[i])); + } + /* Was it a trailing run of 0x00's? */ + if (best.base != -1 && (best.base + best.len) == (NS_IN6ADDRSZ / NS_INT16SZ)) + *tp++ = ':'; + *tp++ = '\0'; - /* - * Check for overflow, copy, and we're done. - */ - if ((socklen_t)(tp - tmp) > size) { - __set_errno (ENOSPC); - return (NULL); - } - return strcpy(dst, tmp); + /* + * Check for overflow, copy, and we're done. + */ + if ((socklen_t) (tp - tmp) > size) + { + __set_errno (ENOSPC); + return (NULL); + } + return strcpy (dst, tmp); }