NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/44097: humanize_number bugs
>Number: 44097
>Category: lib
>Synopsis: humanize_number bugs
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Nov 16 05:00:00 +0000 2010
>Originator: YAMAMOTO Takashi
>Release: NetBSD-current
>Organization:
>Environment:
>Description:
the following program yields unexpected outputs except for
the first one.
eg.
% ./a.out
5 '10000'
1 '0'
13 '0%d%s%d%s%s%s'
failed
%
besides that, the code and the man page seem assuming
strlen(localeconv()->decimal_point) == 1.
i wonder if it's correct for multibyte locales.
>How-To-Repeat:
>Fix:
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int
main()
{
char buf[1000];
int ret;
/*
* this seems to work
*/
ret = humanize_number(buf, 10, 10000, "", HN_AUTOSCALE, HN_NOSPACE);
if (ret == -1) {
printf("failed\n");
} else {
printf("%d '%s'\n", ret, buf);
}
/*
* large number
*/
ret = humanize_number(buf, 10, INT64_MAX, "", HN_AUTOSCALE, HN_NOSPACE);
if (ret == -1) {
printf("failed\n");
} else {
printf("%d '%s'\n", ret, buf);
}
/*
* large buffer with HN_AUTOSCALE
*/
ret = humanize_number(buf, sizeof(buf), 10000, "", HN_AUTOSCALE,
HN_NOSPACE);
if (ret == -1) {
printf("failed\n");
} else {
printf("%d '%s'\n", ret, buf);
}
/*
* tight buffer
* the man page says that len must be at least 4, but...
*/
ret = humanize_number(buf, 1, 1, "", HN_AUTOSCALE, HN_NOSPACE);
if (ret == -1) {
printf("failed\n");
} else {
printf("%d '%s'\n", ret, buf);
}
exit(0);
}
>Unformatted:
Home |
Main Index |
Thread Index |
Old Index