History log of /src/lib/libc/tests/stdlib/strfmon_test.c (Results 1 – 25 of 48)
Revision Date Author Comments
# cf85e703 26-Nov-2025 Jose Luis Duran <jlduran@FreeBSD.org>

strfmon: Fix negative sign handling for C locale

If the locale's positive_sign and negative_sign values would both be
returned by localeconv() as empty strings, strfmon() shall behave as if
the nega

strfmon: Fix negative sign handling for C locale

If the locale's positive_sign and negative_sign values would both be
returned by localeconv() as empty strings, strfmon() shall behave as if
the negative_sign value was the string "-".

This occurs with the C locale. The implementation previously assigned
"0" to sign_posn (parentheses around the entire string); now it assigns
it to "1" (sign before the string) when it is undefined (CHAR_MAX).

Austin Group Defect 1199[1] is applied, changing the requirements for
the '+' and '(' flags.

[1]: https://www.austingroupbugs.net/view.php?id=1199

Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D53913

show more ...


# 1fd01897 26-Nov-2025 Jose Luis Duran <jlduran@FreeBSD.org>

strfmon: EINVAL if the '+' flag and both signs are empty

According to the Open Group Base Specifications Issue 8[1], strfmon(3)
should return EINVAL when the '+' flag was included in a conversion
sp

strfmon: EINVAL if the '+' flag and both signs are empty

According to the Open Group Base Specifications Issue 8[1], strfmon(3)
should return EINVAL when the '+' flag was included in a conversion
specification and the locale's positive_sign and negative_sign values
would both be returned by localeconv(3) as empty strings.

Austin Group Defect 1199[2] is applied, adding the [EINVAL] error.

[1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html
[2]: https://www.austingroupbugs.net/view.php?id=1199

Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D53912

show more ...


# 19e15300 26-Nov-2025 Jose Luis Duran <jlduran@FreeBSD.org>

strfmon: Add tests for Austin Group Defect 1199

Add tests for The Open Group Base Specifications Issue 8[1], Austin
Group Defect 1199[2].

Items marked with XXX represent an invalid output. These i

strfmon: Add tests for Austin Group Defect 1199

Add tests for The Open Group Base Specifications Issue 8[1], Austin
Group Defect 1199[2].

Items marked with XXX represent an invalid output. These items will be
fixed in subsequent commits.

Notice that an existing test is now considered invalid.

Our locale definitions do not include int_p_sep_by_space nor
int_n_sep_by_space[3]. Those will be addressed in a subsequent commit.
However, the CLDR project defines them as "0", which causes the output
to appear as "USD123.45". If our locale definitions were to set the
international {n,p}_sep_by_space to "1", the output would display as the
expected "USD 123.45".

While here, use the SPDX license identifier and add my name to the
file.

[1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html
[2]: https://www.austingroupbugs.net/view.php?id=1199
[3]: https://unicode-org.atlassian.net/browse/CLDR-237

Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D53911

show more ...


# 559a218c 01-Nov-2023 Warner Losh <imp@FreeBSD.org>

libc: Purge unneeded cdefs.h

These sys/cdefs.h are not needed. Purge them. They are mostly left-over
from the $FreeBSD$ removal. A few in libc are still required for macros
that cdefs.h defines. Kee

libc: Purge unneeded cdefs.h

These sys/cdefs.h are not needed. Purge them. They are mostly left-over
from the $FreeBSD$ removal. A few in libc are still required for macros
that cdefs.h defines. Keep those.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D42385

show more ...


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 621bf918 28-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon_l: Use specified locale for number formatting

strfmon_l does not take fully into consideration the explicitly passed
locale to perform the formatting.

Parallel universe bug report: https://

strfmon_l: Use specified locale for number formatting

strfmon_l does not take fully into consideration the explicitly passed
locale to perform the formatting.

Parallel universe bug report: https://sourceware.org/bugzilla/show_bug.cgi?id=19633

Obtained from: Darwin
Reviewed by: kib
PR: 267410
Github PR: #620
MFC after: 1 week

show more ...


# 29972f06 28-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon_test: Add a test for strfmon_l

Attempt to test the correctness of strfmon_l(3).

Items marked with XXX represent an invalid output.

Obtained from: https://github.com/NetBSD/src/commit/e7eba

strfmon_test: Add a test for strfmon_l

Attempt to test the correctness of strfmon_l(3).

Items marked with XXX represent an invalid output.

Obtained from: https://github.com/NetBSD/src/commit/e7eba0044fe6128291cbb7e5923c7cf7d87318cc

Reviewed by: kib
PR: 267410
Github PR: #620
MFC after: 1 week

show more ...


# edcee003 27-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon_test: Reserve space for the null terminator

Otherwise strfmon(3) could overflow the buffer.

Here is mostly done for correctness and illustrative purposes, as there
is no chance it could act

strfmon_test: Reserve space for the null terminator

Otherwise strfmon(3) could overflow the buffer.

Here is mostly done for correctness and illustrative purposes, as there
is no chance it could actually happen.

Reviewed by: kib
PR: 267410
Github PR: #620
MFC after: 1 week

show more ...


# 34f88528 21-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon: Fix formatting of a second fixed-width value

There is a bug when formatting two consecutive values using fixed-widths
and the values need padding. This was because the value of pad_size
wa

strfmon: Fix formatting of a second fixed-width value

There is a bug when formatting two consecutive values using fixed-widths
and the values need padding. This was because the value of pad_size
was zeroed only every other time.

Format Before After
[%8n] [%8n] [ $123.45] [ $123.45] [ $123.45] [ $123.45]

Reviewed by: kib
PR: 267282
Github PR: #619
MFC after: 1 week

show more ...


# 750fe3e6 18-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon: Fix an edge case when sep_by_space is 2

Fix an edge case by printing the required space when, the currency
symbol succeeds the value, a space separates the sign from the value and
the sign

strfmon: Fix an edge case when sep_by_space is 2

Fix an edge case by printing the required space when, the currency
symbol succeeds the value, a space separates the sign from the value and
the sign position precedes the quantity and the currency symbol.

In other words:

n_cs_precedes = 0
n_sep_by_space = 2
n_sign_posn = 1

From The Open Group's localeconv[1]:

> When {p,n,int_p,int_n}_sep_by_space is 2:
> If the currency symbol and sign string are adjacent, a space separates
> them; otherwise, a space separates the sign string from the value.

Format Before After
[%n] [-123.45¤] [- 123.45¤]

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/localeconv.html

Obtained from: Darwin
Reviewed by: kib
PR: 267282
Github PR: #619
MFC after: 1 week

show more ...


# 947efadc 14-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon: Fix alignment when enclosed by parentheses

Take into consideration the possibility of quantities enclosed by
parentheses when aligning.

Matches the examples from The Open Group's:

Format

strfmon: Fix alignment when enclosed by parentheses

Take into consideration the possibility of quantities enclosed by
parentheses when aligning.

Matches the examples from The Open Group's:

Format Before After
%(#5n [$ 123.45] [ $ 123.45 ] Use an alternative pos/neg style
[($ 123.45)] [($ 123.45)]
[$ 3,456.78] [ $ 3,456.78 ]

%!(#5n [ 123.45] [ 123.45 ] Disable the currency symbol
[( 123.45)] [( 123.45)]
[ 3,456.78] [ 3,456.78 ]

https://pubs.opengroup.org/onlinepubs/9699919799/functions/strfmon.html

SD5-XSH-ERN-29 is applied, updating the examples for %(#5n and %!(#5n.

Obtained from: Darwin
Reviewed by: kib
PR: 267282
Github PR: #619
MFC after: 1 week

show more ...


# 6da51e19 21-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon: Trim the SPACE from international currency symbol

The international currency symbol (int_curr_symbol) has a mandatory
SPACE character as the last character.

Trim this space after reading i

strfmon: Trim the SPACE from international currency symbol

The international currency symbol (int_curr_symbol) has a mandatory
SPACE character as the last character.

Trim this space after reading it, otherwise this extra space will always
be printed when displaying the int_curr_symbol.

Fixes the output when the international currency format is selected
(%i).

Locale Format Before After
en_US.UTF-8 [%i] [USD 123.45] [USD123.45]
fr_FR.UTF-8 [%i] [123,45 EUR ] [123,45 EUR]

Note that the en_US.UTF-8 locale states that no space should be printed
between the currency symbol and the value (sep_by_space = 0).

Reviewed by: kib
PR: 267282
Github PR: #619
MFC after: 1 week

show more ...


# 9e03b903 13-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon: Avoid an out-of-bounds access

Avoid an out-of-bounds access when trying to set the space_char using an
international currency format (%i) and the C/POSIX locale.

The current code tries to

strfmon: Avoid an out-of-bounds access

Avoid an out-of-bounds access when trying to set the space_char using an
international currency format (%i) and the C/POSIX locale.

The current code tries to read the SPACE from int_curr_symbol[3]:

currency_symbol = strdup(lc->int_curr_symbol);
space_char = *(currency_symbol+3);

But on C/POSIX locales, int_curr_symbol is empty.

Three implementations have been examined: NetBSD[1], Darwin[2], and
Illumos[3]. Only NetBSD has fixed it[4].

Darwin and NetBSD also trim the mandatory final SPACE character after
reading it.

Locale Format Darwin/NetBSD FreeBSD/Illumos
en_US.UTF-8 [%i] [USD123.45] [USD 123.45]
fr_FR.UTF-8 [%i] [123,45 EUR] [123,45 EUR ]

This commit only fixes the out-of-bounds access.

[1]: https://github.com/NetBSD/src/blob/trunk/lib/libc/stdlib/strfmon.c
[2]: https://opensource.apple.com/source/Libc/Libc-1439.141.1/stdlib/NetBSD/strfmon.c.auto.html
[3]: https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/port/locale/strfmon.c
[4]: https://github.com/NetBSD/src/commit/3d7b5d498aa9609f2bc9ece9c734c5f493a8e239

Reviewed by: kib
PR: 267282
Github PR: #619
MFC after: 1 week

show more ...


# 3f97d37a 16-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon_test: Add some tests

Attempt to test the correctness of strfmon(3).

Some of them were inspired from the examples section at:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/strfm

strfmon_test: Add some tests

Attempt to test the correctness of strfmon(3).

Some of them were inspired from the examples section at:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/strfmon.html

Items marked with XXX represent an invalid output.

Reviewed by: kib
PR: 267282
Github PR: #619
MFC after: 1 week

show more ...


# f91301cc 16-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon_test: Fix typo and remove extra space

Reviewed by: kib
PR: 267282
Github PR: #619
MFC after: 1 week


# 8c1c50ff 19-Dec-2018 Conrad Meyer <cem@FreeBSD.org>

Allow multi-byte thousands separators in strfmon(3)

PR: 234010
Reported by: Jon Tejnung <jon AT herrskogen.se>
Reviewed by: yuripv
Differential Revision: https://reviews.freebsd.org/D18605


# cf85e703 26-Nov-2025 Jose Luis Duran <jlduran@FreeBSD.org>

strfmon: Fix negative sign handling for C locale

If the locale's positive_sign and negative_sign values would both be
returned by localeconv() as empty strings, strfmon() shall behave as if
the nega

strfmon: Fix negative sign handling for C locale

If the locale's positive_sign and negative_sign values would both be
returned by localeconv() as empty strings, strfmon() shall behave as if
the negative_sign value was the string "-".

This occurs with the C locale. The implementation previously assigned
"0" to sign_posn (parentheses around the entire string); now it assigns
it to "1" (sign before the string) when it is undefined (CHAR_MAX).

Austin Group Defect 1199[1] is applied, changing the requirements for
the '+' and '(' flags.

[1]: https://www.austingroupbugs.net/view.php?id=1199

Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D53913

show more ...


# 1fd01897 26-Nov-2025 Jose Luis Duran <jlduran@FreeBSD.org>

strfmon: EINVAL if the '+' flag and both signs are empty

According to the Open Group Base Specifications Issue 8[1], strfmon(3)
should return EINVAL when the '+' flag was included in a conversion
sp

strfmon: EINVAL if the '+' flag and both signs are empty

According to the Open Group Base Specifications Issue 8[1], strfmon(3)
should return EINVAL when the '+' flag was included in a conversion
specification and the locale's positive_sign and negative_sign values
would both be returned by localeconv(3) as empty strings.

Austin Group Defect 1199[2] is applied, adding the [EINVAL] error.

[1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html
[2]: https://www.austingroupbugs.net/view.php?id=1199

Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D53912

show more ...


# 19e15300 26-Nov-2025 Jose Luis Duran <jlduran@FreeBSD.org>

strfmon: Add tests for Austin Group Defect 1199

Add tests for The Open Group Base Specifications Issue 8[1], Austin
Group Defect 1199[2].

Items marked with XXX represent an invalid output. These i

strfmon: Add tests for Austin Group Defect 1199

Add tests for The Open Group Base Specifications Issue 8[1], Austin
Group Defect 1199[2].

Items marked with XXX represent an invalid output. These items will be
fixed in subsequent commits.

Notice that an existing test is now considered invalid.

Our locale definitions do not include int_p_sep_by_space nor
int_n_sep_by_space[3]. Those will be addressed in a subsequent commit.
However, the CLDR project defines them as "0", which causes the output
to appear as "USD123.45". If our locale definitions were to set the
international {n,p}_sep_by_space to "1", the output would display as the
expected "USD 123.45".

While here, use the SPDX license identifier and add my name to the
file.

[1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html
[2]: https://www.austingroupbugs.net/view.php?id=1199
[3]: https://unicode-org.atlassian.net/browse/CLDR-237

Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D53911

show more ...


# 559a218c 01-Nov-2023 Warner Losh <imp@FreeBSD.org>

libc: Purge unneeded cdefs.h

These sys/cdefs.h are not needed. Purge them. They are mostly left-over
from the $FreeBSD$ removal. A few in libc are still required for macros
that cdefs.h defines. Kee

libc: Purge unneeded cdefs.h

These sys/cdefs.h are not needed. Purge them. They are mostly left-over
from the $FreeBSD$ removal. A few in libc are still required for macros
that cdefs.h defines. Keep those.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D42385

show more ...


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 621bf918 28-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon_l: Use specified locale for number formatting

strfmon_l does not take fully into consideration the explicitly passed
locale to perform the formatting.

Parallel universe bug report: https://

strfmon_l: Use specified locale for number formatting

strfmon_l does not take fully into consideration the explicitly passed
locale to perform the formatting.

Parallel universe bug report: https://sourceware.org/bugzilla/show_bug.cgi?id=19633

Obtained from: Darwin
Reviewed by: kib
PR: 267410
Github PR: #620
MFC after: 1 week

show more ...


# 29972f06 28-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon_test: Add a test for strfmon_l

Attempt to test the correctness of strfmon_l(3).

Items marked with XXX represent an invalid output.

Obtained from: https://github.com/NetBSD/src/commit/e7eba

strfmon_test: Add a test for strfmon_l

Attempt to test the correctness of strfmon_l(3).

Items marked with XXX represent an invalid output.

Obtained from: https://github.com/NetBSD/src/commit/e7eba0044fe6128291cbb7e5923c7cf7d87318cc

Reviewed by: kib
PR: 267410
Github PR: #620
MFC after: 1 week

show more ...


# edcee003 27-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon_test: Reserve space for the null terminator

Otherwise strfmon(3) could overflow the buffer.

Here is mostly done for correctness and illustrative purposes, as there
is no chance it could act

strfmon_test: Reserve space for the null terminator

Otherwise strfmon(3) could overflow the buffer.

Here is mostly done for correctness and illustrative purposes, as there
is no chance it could actually happen.

Reviewed by: kib
PR: 267410
Github PR: #620
MFC after: 1 week

show more ...


# 34f88528 21-Oct-2022 Jose Luis Duran <jlduran@gmail.com>

strfmon: Fix formatting of a second fixed-width value

There is a bug when formatting two consecutive values using fixed-widths
and the values need padding. This was because the value of pad_size
wa

strfmon: Fix formatting of a second fixed-width value

There is a bug when formatting two consecutive values using fixed-widths
and the values need padding. This was because the value of pad_size
was zeroed only every other time.

Format Before After
[%8n] [%8n] [ $123.45] [ $123.45] [ $123.45] [ $123.45]

Reviewed by: kib
PR: 267282
Github PR: #619
MFC after: 1 week

show more ...


12