Project

General

Profile

Bug #10350

printf: * refers to maximum number of bytes not characters

Added by Michal Nowak 8 months ago. Updated 8 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
lib - userland libraries
Start date:
2019-02-06
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage

Description

On OpenIndiana (illumos-f482e26cbe) line of the interactive git rebase text after a particular name (Gergő Mihály Doma) is broken:

pick 1ea94c756c 10202 loader: use screen-#rows to find bottom left 
co-ordinates Reviewed by: Toomas Soome <tsoome@me.com> Reviewed by: 
Gergő Mihály Doma <domag02@gmail.com> Approved by: Robert Mustacchi 
<rm@joyent.com>
p
pick cadd68ea00 10078 smatch fixes for UCB Reviewed by: Andy Fiddaman 
<omnios@citrus-it.net> Reviewed by: Toomas Soome <tsoome@me.com> 
Reviewed by: Peter Tribble <peter.tribble@gmail.com> Approved by: Robert 
Mustacchi <rm@joyent.com>

While discussing this issue with git upstream (https://public-inbox.org/git/a50734d9-4d30-5847-b5df-67a8458a36cb@startmail.com/) it turned out that this likely illumos libc bug. See the attached test case.

On Linux:

Before setting locale:
Expected output:
áaaa
Actual output:
áaaa

After setting locale:
Expected output:
áaaa
Actual output:
áaaa

On illumos:

Before setting locale:
Expected output:
áaaa
Actual output:
áaaa

After setting locale:
Expected output:
áaaa
Actual output:
áaaaa

According to https://public-inbox.org/git/2cbb5818-643d-bafd-6721-91e0d291a5fd@talktalk.net/:

The C standard and POSIX both say that the * refers to the maximum 
number of bytes to print but it looks like it is being treated as the 
maximum number of characters on OpenIndiana.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html
[2] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf page 309


Files

test-case.c (650 Bytes) test-case.c Michal Nowak, 2019-02-06 02:30 PM

History

#1

Updated by Gergő Mihály Doma 8 months ago

It's amazing!

#2

Updated by Toomas Soome 8 months ago

Michal Nowak wrote:

On OpenIndiana (illumos-f482e26cbe) line of the interactive git rebase text after a particular name (Gergő Mihály Doma) is broken:

[...]

While discussing this issue with git upstream (https://public-inbox.org/git/a50734d9-4d30-5847-b5df-67a8458a36cb@startmail.com/) it turned out that this likely illumos libc bug. See the attached test case.

On Linux:

[...]

On illumos:

[...]

According to https://public-inbox.org/git/2cbb5818-643d-bafd-6721-91e0d291a5fd@talktalk.net/:
[...]

The problem is there:

                                /*
                                 * sec_display only needed if width
                                 * is specified (ie, "%<width>s")
                                 * Solaris behavior counts <width> in
                                 * screen column width.  (If XPG4 behavior,
                                 * <width> is counted in bytes.)
                                 */

and indeed:

$ gcc -D_XOPEN_SOURCE -D_XOPEN_VERSION=4 /usr/lib/values-xpg4.o test-case.c 
$ ./a.out 
Before setting locale:
Expected output:
áaaa
Actual output:
áaaa

After setting locale:
Expected output:
áaaa
Actual output:
áaaa

So we do have two options - either build git with XPG4 or change illumos default.

#3

Updated by Michal Nowak 8 months ago

With -D_XOPEN_SOURCE -D_XOPEN_VERSION=4 following git test case from t0021-conversion.sh fails:

test_expect_success 'filter that does not read is fine' '
        test-tool genrandom foo $((128 * 1024 + 1)) >big &&
        echo "big filter=epipe" >.gitattributes &&
        test_config filter.epipe.clean "echo xyzzy" &&
        git add big &&
        git cat-file blob :big >actual &&
        echo xyzzy >expect && sleep 300 &&
        test_cmp expect actual
'

Files "big" and "actual" are the same, containing 128 KB of random data.

The test case passes without those difines.

Also available in: Atom PDF