From nobody Sat Dec 16 04:19:23 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SsXsm34NKz54X8g; Sat, 16 Dec 2023 04:19:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SsXsm1qFxz3Cy3; Sat, 16 Dec 2023 04:19:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702700364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uyrBcYr1rne00skap+DZ5TCktsJaVhDnEHE8gVd6ujU=; b=VKgNQ2qELlPU65QUiPhlu6rs/tDRPrVgD3UVESJQeA5JyPf4S8VD5Oxmh4xaTxfIFmj3Wj o+kYfSJ8WXvLzGZAnZWjY1uPntS6A9UvdI/uK8yEcxH3DBb+Lb09IYI5zwxln4uSmbuQRL /xVmxPfy+2tiIgpxB/E89UjUYgUdaxgQhQsNeg0WSWMUB+jKVRvLkFXAQHYnBLkxqheVNS +0ZG58y31BMEDH+XXUpdF+fT/85lKGugAGy9OWKvK7CFKA5gtYq10576MaVJC162X8l2bJ nzZ0wx9zCXFx9d7qgxyrh3bFbMKwqmTkTg4/WXO5mw04QOhvI8soPwv+qjtakQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702700364; a=rsa-sha256; cv=none; b=VHLNN1KX2HlkKDAqljzjYGX6l1NTEi5fgZRUt92Jafh8gv9RNcCPDpJUoddrVRT5nRHOBU Aufqfzc4mALc2rOn+MCSJjUod2p10YY51qvC4n/gpgbXOdoxunRD2zdo9bP1Xa3TAFmP/k 29kYBSBZyYG8J5BhK1AvIzK2GYJdfjaJz6FuEHJCoy3HyR7U8unLPsva512Fdmye0WJFL+ vDPjuTSnazmkNYOT+yKAqYRmXDIJBgYqOAnA4dCJ9Q2SYcbSb4MwfXIiPn0GWO0V+y95BO LiR7jiYkRsDuwL9DuZxe/o1Wqituzm31pferaW34N8xLLZmdSxfzEiJADV3fxg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702700364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uyrBcYr1rne00skap+DZ5TCktsJaVhDnEHE8gVd6ujU=; b=ugBQNJY0oBsileBept3a0Wo99jysxSGYvNZOIsNFSb6BpvEGQQ4KhAcqey0WfeMmQ5iw+A 8+Mln5G/7Pomw7XQ2kYihLkfB+OLpfYrljBO1LQkL2rpp+hRVzjXRYU23bVOGB3Z4l29cJ 7iIyR6eockUxre0KDLdhJsN4U6hFjUF+NoJF7fiMpDy3Z0Ma++7ovsm39IVlZ53kDEv5bl 2TbkAK3V6dacmowPtOHP1Km5WLigK79o9S5hdxYPRGBVNcsAansrSYhVwoxp3NEq83Zh1T v/SYmAfV+h/EAClSZJg67w4lgee2Xr/hkCRZb9l+FLMTami2Eb8KJKlt3pCTJg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SsXsm0R0DzfcW; Sat, 16 Dec 2023 04:19:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BG4JNl9059462; Sat, 16 Dec 2023 04:19:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BG4JNX7059459; Sat, 16 Dec 2023 04:19:23 GMT (envelope-from git) Date: Sat, 16 Dec 2023 04:19:23 GMT Message-Id: <202312160419.3BG4JNX7059459@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: fff086cfeafc - stable/13 - strfmon: style fixes List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: fff086cfeafc110f94a40eb340ddc8b13d8df0cd Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=fff086cfeafc110f94a40eb340ddc8b13d8df0cd commit fff086cfeafc110f94a40eb340ddc8b13d8df0cd Author: Jose Luis Duran AuthorDate: 2023-11-30 23:28:21 +0000 Commit: Konstantin Belousov CommitDate: 2023-12-16 04:18:48 +0000 strfmon: style fixes (cherry picked from commit 56a0d5444d6f39302f3476b61c1b81ed39abe589) --- lib/libc/stdlib/strfmon.c | 197 +++++++++++++++++++++++----------------------- 1 file changed, 99 insertions(+), 98 deletions(-) diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c index d770b6f32bd1..1c9eb3f45d74 100644 --- a/lib/libc/stdlib/strfmon.c +++ b/lib/libc/stdlib/strfmon.c @@ -34,6 +34,7 @@ #include #include + #include #include #include @@ -58,7 +59,7 @@ /* internal macros */ #define PRINT(CH) do { \ - if (dst >= s + maxsize) \ + if (dst >= s + maxsize) \ goto e2big_error; \ *dst++ = CH; \ } while (0) @@ -69,9 +70,9 @@ PRINT(*tmps++); \ } while (0) -#define GET_NUMBER(VAR, LOC) do { \ +#define GET_NUMBER(VAR, LOC) do { \ VAR = 0; \ - while (isdigit_l((unsigned char)*fmt, LOC)) { \ + while (isdigit_l((unsigned char)*fmt, LOC)) { \ if (VAR > INT_MAX / 10) \ goto e2big_error; \ VAR *= 10; \ @@ -102,22 +103,22 @@ static char *__format_grouped_double(double, int *, int, int, int, struct lconv *, locale_t); static ssize_t -vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, - const char * __restrict format, va_list ap) +vstrfmon_l(char *__restrict s, size_t maxsize, locale_t loc, + const char *__restrict format, va_list ap) { char *dst; /* output destination pointer */ const char *fmt; /* current format poistion pointer */ struct lconv *lc; /* pointer to lconv structure */ char *asciivalue; /* formatted double pointer */ - int flags; /* formatting options */ - int pad_char; /* padding character */ - int pad_size; /* pad size */ - int width; /* field width */ - int left_prec; /* left precision */ - int right_prec; /* right precision */ - double value; /* just value */ - char space_char = ' '; /* space after currency */ + int flags; /* formatting options */ + int pad_char; /* padding character */ + int pad_size; /* pad size */ + int width; /* field width */ + int left_prec; /* left precision */ + int right_prec; /* right precision */ + double value; /* just value */ + char space_char = ' '; /* space after currency */ char cs_precedes, /* values gathered from struct lconv */ sep_by_space, @@ -127,6 +128,7 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, char *tmpptr; /* temporary vars */ int sverrno; + FIX_LOCALE(loc); lc = localeconv_l(loc); @@ -135,7 +137,7 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, asciivalue = NULL; currency_symbol = NULL; - while (*fmt) { + while (*fmt != 0) { /* pass nonformating characters AS IS */ if (*fmt != '%') goto literal; @@ -145,13 +147,13 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, /* "%%" mean just '%' */ if (*(fmt + 1) == '%') { fmt++; - literal: +literal: PRINT(*fmt++); continue; } /* set up initial values */ - flags = (NEED_GROUPING|LOCALE_POSN); + flags = NEED_GROUPING | LOCALE_POSN; pad_char = ' '; /* padding character is "space" */ pad_size = 0; /* no padding initially */ left_prec = -1; /* no left precision specified */ @@ -161,32 +163,32 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, /* Flags */ while (1) { switch (*++fmt) { - case '=': /* fill character */ - pad_char = *++fmt; - if (pad_char == '\0') - goto format_error; - continue; - case '^': /* not group currency */ - flags &= ~(NEED_GROUPING); - continue; - case '+': /* use locale defined signs */ - if (flags & SIGN_POSN_USED) - goto format_error; - flags |= (SIGN_POSN_USED|LOCALE_POSN); - continue; - case '(': /* enclose negatives with () */ - if (flags & SIGN_POSN_USED) - goto format_error; - flags |= (SIGN_POSN_USED|PARENTH_POSN); - continue; - case '!': /* suppress currency symbol */ - flags |= SUPPRESS_CURR_SYMBOL; - continue; - case '-': /* alignment (left) */ - flags |= LEFT_JUSTIFY; - continue; - default: - break; + case '=': /* fill character */ + pad_char = *++fmt; + if (pad_char == '\0') + goto format_error; + continue; + case '^': /* not group currency */ + flags &= ~(NEED_GROUPING); + continue; + case '+': /* use locale defined signs */ + if (flags & SIGN_POSN_USED) + goto format_error; + flags |= (SIGN_POSN_USED | LOCALE_POSN); + continue; + case '(': /* enclose negatives with () */ + if (flags & SIGN_POSN_USED) + goto format_error; + flags |= (SIGN_POSN_USED | PARENTH_POSN); + continue; + case '!': /* suppress currency symbol */ + flags |= SUPPRESS_CURR_SYMBOL; + continue; + case '-': /* alignment (left) */ + flags |= LEFT_JUSTIFY; + continue; + default: + break; } break; } @@ -194,7 +196,8 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, /* field Width */ if (isdigit_l((unsigned char)*fmt, loc)) { GET_NUMBER(width, loc); - /* Do we have enough space to put number with + /* + * Do we have enough space to put number with * required width ? */ if ((unsigned int)width >= maxsize - (dst - s)) @@ -215,22 +218,24 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, if (!isdigit_l((unsigned char)*++fmt, loc)) goto format_error; GET_NUMBER(right_prec, loc); - if ((unsigned int)right_prec >= maxsize - (dst - s) - - left_prec) + if ((unsigned int)right_prec >= + maxsize - (dst - s) - left_prec) goto e2big_error; } /* Conversion Characters */ switch (*fmt++) { - case 'i': /* use international currency format */ - flags |= USE_INTL_CURRENCY; - break; - case 'n': /* use national currency format */ - flags &= ~(USE_INTL_CURRENCY); - break; - default: /* required character is missing or - premature EOS */ - goto format_error; + case 'i': /* use international currency format */ + flags |= USE_INTL_CURRENCY; + break; + case 'n': /* use national currency format */ + flags &= ~(USE_INTL_CURRENCY); + break; + default: /* + * required character is missing or + * premature EOS + */ + goto format_error; } if (currency_symbol != NULL) @@ -246,7 +251,7 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, currency_symbol = strdup(lc->currency_symbol); if (currency_symbol == NULL) - goto end_error; /* ENOMEM. */ + goto end_error; /* ENOMEM. */ /* value itself */ value = va_arg(ap, double); @@ -268,15 +273,17 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, if (asciivalue != NULL) free(asciivalue); - asciivalue = __format_grouped_double(value, &flags, - left_prec, right_prec, pad_char, lc, loc); + asciivalue = __format_grouped_double(value, &flags, left_prec, + right_prec, pad_char, lc, loc); if (asciivalue == NULL) - goto end_error; /* errno already set */ - /* to ENOMEM by malloc() */ + goto end_error; /* + * errno already set to ENOMEM by + * malloc() + */ /* set some variables for later use */ - __setup_vars(flags, &cs_precedes, &sep_by_space, - &sign_posn, &signstr, lc); + __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, + &signstr, lc); /* * Description of some LC_MONETARY's values: @@ -307,7 +314,6 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, * $currency_symbol * = 3 - the sign string precedes the $currency_symbol * = 4 - the sign string succeeds the $currency_symbol - * */ tmpptr = dst; @@ -353,12 +359,10 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, } if (!(flags & SUPPRESS_CURR_SYMBOL)) { - if ((sign_posn == 3 && sep_by_space == 2) - || (sep_by_space == 1 - && (sign_posn == 0 - || sign_posn == 1 - || sign_posn == 2 - || sign_posn == 4))) + if ((sign_posn == 3 && sep_by_space == 2) || + (sep_by_space == 1 && + (sign_posn == 0 || sign_posn == 1 || + sign_posn == 2 || sign_posn == 4))) PRINT(space_char); PRINTS(currency_symbol); if (sign_posn == 4) { @@ -399,7 +403,7 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, PRINT('\0'); free(asciivalue); free(currency_symbol); - return (dst - s - 1); /* return size of put data except trailing '\0' */ + return (dst - s - 1); /* size of put data except trailing '\0' */ e2big_error: errno = E2BIG; @@ -419,15 +423,15 @@ end_error: } static void -__setup_vars(int flags, char *cs_precedes, char *sep_by_space, - char *sign_posn, char **signstr, struct lconv *lc) +__setup_vars(int flags, char *cs_precedes, char *sep_by_space, char *sign_posn, + char **signstr, struct lconv *lc) { if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) { *cs_precedes = lc->int_n_cs_precedes; *sep_by_space = lc->int_n_sep_by_space; *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_n_sign_posn; - *signstr = (lc->negative_sign[0] == '\0') ? "-" - : lc->negative_sign; + *signstr = (lc->negative_sign[0] == '\0') ? "-" : + lc->negative_sign; } else if (flags & USE_INTL_CURRENCY) { *cs_precedes = lc->int_p_cs_precedes; *sep_by_space = lc->int_p_sep_by_space; @@ -437,8 +441,8 @@ __setup_vars(int flags, char *cs_precedes, char *sep_by_space, *cs_precedes = lc->n_cs_precedes; *sep_by_space = lc->n_sep_by_space; *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->n_sign_posn; - *signstr = (lc->negative_sign[0] == '\0') ? "-" - : lc->negative_sign; + *signstr = (lc->negative_sign[0] == '\0') ? "-" : + lc->negative_sign; } else { *cs_precedes = lc->p_cs_precedes; *sep_by_space = lc->p_sep_by_space; @@ -461,8 +465,8 @@ __calc_left_pad(int flags, char *cur_symb, struct lconv *lc) char cs_precedes, sep_by_space, sign_posn, *signstr; int left_chars = 0; - __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, - &signstr, lc); + __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr, + lc); if (cs_precedes != 0) { left_chars += strlen(cur_symb); @@ -471,17 +475,17 @@ __calc_left_pad(int flags, char *cur_symb, struct lconv *lc) } switch (sign_posn) { - case 0: - if (flags & IS_NEGATIVE) - left_chars++; - break; - case 1: + case 0: + if (flags & IS_NEGATIVE) + left_chars++; + break; + case 1: + left_chars += strlen(signstr); + break; + case 3: + case 4: + if (cs_precedes != 0) left_chars += strlen(signstr); - break; - case 3: - case 4: - if (cs_precedes != 0) - left_chars += strlen(signstr); } return (left_chars); } @@ -511,8 +515,8 @@ get_groups(int size, char *grouping) /* convert double to locale-encoded string */ static char * -__format_grouped_double(double value, int *flags, - int left_prec, int right_prec, int pad_char, struct lconv *lc, locale_t loc) +__format_grouped_double(double value, int *flags, int left_prec, int right_prec, + int pad_char, struct lconv *lc, locale_t loc) { char *rslt; @@ -530,7 +534,7 @@ __format_grouped_double(double value, int *flags, size_t decimal_point_size; size_t thousands_sep_size; - int groups = 0; + int groups = 0; grouping = lc->mon_grouping; decimal_point = lc->mon_decimal_point; @@ -593,10 +597,8 @@ __format_grouped_double(double value, int *flags, avalue_size -= (right_prec + 1); } - if ((*flags & NEED_GROUPING) && - thousands_sep_size > 0 && - *grouping != CHAR_MAX && - *grouping > 0) { + if ((*flags & NEED_GROUPING) && thousands_sep_size > 0 && + *grouping != CHAR_MAX && *grouping > 0) { while (avalue_size > (int)*grouping) { GRPCPY(*grouping); GRPSEP; @@ -639,8 +641,7 @@ __format_grouped_double(double value, int *flags, } ssize_t -strfmon(char * __restrict s, size_t maxsize, const char * __restrict format, - ...) +strfmon(char *__restrict s, size_t maxsize, const char *__restrict format, ...) { ssize_t ret; va_list ap; @@ -653,8 +654,8 @@ strfmon(char * __restrict s, size_t maxsize, const char * __restrict format, } ssize_t -strfmon_l(char * __restrict s, size_t maxsize, locale_t loc, - const char * __restrict format, ...) +strfmon_l(char *__restrict s, size_t maxsize, locale_t loc, + const char *__restrict format, ...) { ssize_t ret; va_list ap;