The separator char can be an utf-8 encoded symbol thus the length
of the string is necessarly one.
The check if we have to issue an separator needs to a fixed modulo of 3
or 4 (without or with l10n enabled) to place the symbol at the right
position in the string.
The copy loop needs to copy the all bytes from the back of the separator
byte sequence to the front, the same order we print the number.
Signed-off-by: Daniel Wagner <dwagner@suse.de>
int idx = 60;
__u64 div, rem;
char *sep = NULL;
- int i, len = 0;
+ int i, len = 0, cl = 0;
if (l10n) {
sep = localeconv()->thousands_sep;
len = strlen(sep);
+ cl = 1;
}
/* terminate at the end, and build up from the ones */
str[--idx] = '\0';
do {
- if (len && !((sizeof(str) - idx) % (3 + len))) {
+ if (len && !((sizeof(str) - idx) % (3 + cl))) {
for (i = 0; i < len; i++)
- str[--idx] = sep[i];
+ str[--idx] = sep[len - i - 1];
}
rem = val.words[0];