NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/57633: strfmon: Invalid output format



>Number:         57633
>Category:       lib
>Synopsis:       strfmon: Invalid output format
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 27 21:20:00 +0000 2023
>Originator:     Jose Luis Duran
>Release:        trunk
>Organization:
>Environment:
>Description:
While porting back some strfmon(3) fixes from NetBSD to FreeBSD, I accidentally stumbled upon this issue (see MWE).

Every other time, the format may be wrong:

  Format: [%8n] [%8n]
Expected: [ $123.45] [ $123.45]
  Actual: [ $123.45] [       $123.45]

>How-To-Repeat:
Take the following MWE:

#include <stdio.h>
#include <locale.h>
#include <monetary.h>

int
main(void)
{
	char string[100];

	if (setlocale(LC_MONETARY, "en_US.UTF-8") == NULL) {
		fprintf(stderr, "Unable to setlocale().\n");
		return (1);
	}

	strfmon(string, sizeof(string) - 1, "[%8n] [%8n]", 123.45, 123.45);
	printf("  Format: [%%8n] [%%8n]\n");
	printf("Expected: %s\n", "[ $123.45] [ $123.45]");
	printf("  Actual: %s\n\n", string);

	return (0);
}

>Fix:
The fix was to change where pad_size is zeroed. It should be zeroed on every iteration, not every other time:

https://github.com/freebsd/freebsd-src/commit/34f88528edba44b2703ba8c772bef077eca33dab



Home | Main Index | Thread Index | Old Index