mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] printf does not print anything (musl 1.2.3)
@ 2023-04-12 21:35 Detlef Riekenberg
  2023-04-12 22:29 ` Gabriel Ravier
  0 siblings, 1 reply; 2+ messages in thread
From: Detlef Riekenberg @ 2023-04-12 21:35 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1064 bytes --]

The attached test fails with musl 1.2.3 (does not print anything):


os: xubuntu 23.04
compiled with:  musl-gcc  -O0  -std=c99  -Wall  prog.c  -o  prog_musl-O0
gcc: 12.2.0-17ubuntu1


The programm is a tic-tac-toe game, but the source is stange:
* Filesize Original: 2745 byte (includes only <stdio.h>)
* Filesize after preprocess: with musl ~559k / with gnu libc ~571k
* After preprocess, the format string is ~100kb
* main() uses only one printf, and one arg has a scanf:

`
int main() {
    while(*d) printf(fmt, arg);
}
`

For testing, i removed the "while(*d)",
but the binary using musl still does not print anything.


Compiling the original source with the same gcc and using gnu libc works
and the gnu libc version with the removed "while (*d)" produces an output of 23592 byte.


ioccc page:  https://www.ioccc.org/2020/carlini/index.html
Also available on github:  https://github.com/carlini/printf-tac-toe


I tried to subscribe to the list, but i have no confirmation yet, so please cc me.


--
Bye bye ... Detlef

[-- Attachment #2: prog.c --]
[-- Type: text/plain, Size: 2795 bytes --]

#include <stdio.h>

#define N(a)       "%"#a"$hhn"
#define O(a,b)     "%10$"#a"d"N(b)
#define U          "%10$.*37$d"
#define G(a)       "%"#a"$s"
#define H(a,b)     G(a)G(b)
#define T(a)       a a
#define s(a)       T(a)T(a)
#define A(a)       s(a)T(a)a
#define n(a)       A(a)a
#define D(a)       n(a)A(a)
#define C(a)       D(a)a
#define R          C(C(N(12)G(12)))
#define o(a,b,c)   C(H(a,a))D(G(a))C(H(b,b)G(b))n(G(b))O(32,c)R
#define SS         O(78,55)R "\n\033[2J\n%26$s";
#define E(a,b,c,d) H(a,b)G(c)O(253,11)R G(11)O(255,11)R H(11,d)N(d)O(253,35)R
#define S(a,b)     O(254,11)H(a,b)N(68)R G(68)O(255,68)N(12)H(12,68)G(67)N(67)

char* fmt = O(10,39)N(40)N(41)N(42)N(43)N(66)N(69)N(24)O(22,65)O(5,70)O(8,44)N(
            45)N(46)N    (47)N(48)N(    49)N( 50)N(     51)N(52)N(53    )O( 28,
            54)O(5,        55) O(2,    56)O(3,57)O(      4,58 )O(13,    73)O(4,
            71 )N(   72)O   (20,59    )N(60)N(61)N(       62)N (63)N    (64)R R
            E(1,2,   3,13   )E(4,    5,6,13)E(7,8,9        ,13)E(1,4    ,7,13)E
            (2,5,8,        13)E(    3,6,9,13)E(1,5,         9,13)E(3    ,5,7,13
            )E(14,15,    16,23)    E(17,18,19,23)E(          20, 21,    22,23)E
            (14,17,20,23)E(15,    18,21,23)E(16,19,    22     ,23)E(    14, 18,
            22,23)E(16,18,20,    23)R U O(255 ,38)R    G (     38)O(    255,36)
            R H(13,23)O(255,    11)R H(11,36) O(254    ,36)     R G(    36 ) O(
            255,36)R S(1,14    )S(2,15)S(3, 16)S(4,    17 )S     (5,    18)S(6,
            19)S(7,20)S(8,    21)S(9    ,22)H(13,23    )H(36,     67    )N(11)R
            G(11)""O(255,    25 )R        s(C(G(11)    ))n (G(          11) )G(
            11)N(54)R C(    "aa")   s(A(   G(25)))T    (G(25))N         (69)R o
            (14,1,26)o(    15, 2,   27)o   (16,3,28    )o( 17,4,        29)o(18
            ,5,30)o(19    ,6,31)o(        20,7,32)o    (21,8,33)o       (22 ,9,
            34)n(C(U)    )N( 68)R H(    36,13)G(23)    N(11)R C(D(      G(11)))
            D(G(11))G(68)N(68)R G(68)O(49,35)R H(13,23)G(67)N(11)R C(H(11,11)G(
            11))A(G(11))C(H(36,36)G(36))s(G(36))O(32,58)R C(D(G(36)))A(G(36))SS

#define arg d+6,d+8,d+10,d+12,d+14,d+16,d+18,d+20,d+22,0,d+46,d+52,d+48,d+24,d\
            +26,d+28,d+30,d+32,d+34,d+36,d+38,d+40,d+50,(scanf(d+126,d+4),d+(6\
            -2)+18*(1-d[2]%2)+d[4]*2),d,d+66,d+68,d+70, d+78,d+80,d+82,d+90,d+\
            92,d+94,d+97,d+54,d[2],d+2,d+71,d+77,d+83,d+89,d+95,d+72,d+73,d+74\
            ,d+75,d+76,d+84,d+85,d+86,d+87,d+88,d+100,d+101,d+96,d+102,d+99,d+\
            67,d+69,d+79,d+81,d+91,d+93,d+98,d+103,d+58,d+60,d+98,d+126,d+127,\
            d+128,d+129

char d[538] = {1,0,10,0,10};

int main() {
    while(*d) printf(fmt, arg);
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [musl] printf does not print anything (musl 1.2.3)
  2023-04-12 21:35 [musl] printf does not print anything (musl 1.2.3) Detlef Riekenberg
@ 2023-04-12 22:29 ` Gabriel Ravier
  0 siblings, 0 replies; 2+ messages in thread
From: Gabriel Ravier @ 2023-04-12 22:29 UTC (permalink / raw)
  To: musl, Detlef Riekenberg

On 4/12/23 23:35, Detlef Riekenberg wrote:
> The attached test fails with musl 1.2.3 (does not print anything):
>
>
> os: xubuntu 23.04
> compiled with:  musl-gcc  -O0  -std=c99  -Wall  prog.c  -o  prog_musl-O0
> gcc: 12.2.0-17ubuntu1
>
>
> The programm is a tic-tac-toe game, but the source is stange:
> * Filesize Original: 2745 byte (includes only <stdio.h>)
> * Filesize after preprocess: with musl ~559k / with gnu libc ~571k
> * After preprocess, the format string is ~100kb
> * main() uses only one printf, and one arg has a scanf:
>
> `
> int main() {
>      while(*d) printf(fmt, arg);
> }
> `
>
> For testing, i removed the "while(*d)",
> but the binary using musl still does not print anything.
>
>
> Compiling the original source with the same gcc and using gnu libc works
> and the gnu libc version with the removed "while (*d)" produces an output of 23592 byte.
>
>
> ioccc page:  https://www.ioccc.org/2020/carlini/index.html
> Also available on github:  https://github.com/carlini/printf-tac-toe
>
>
> I tried to subscribe to the list, but i have no confirmation yet, so please cc me.
>
>
> --
> Bye bye ... Detlef

The printf call in the linked program attempts to use printf with 
numbered argument conversion specifications with a position larger than 
9 (such as 42). This is not portable to all POSIX systems, as POSIX 
specifies that the implementation need only support numbered argument 
conversion specifications with a position that is at most as large as 
the NL_ARGMAX macro (defined in limits.h), and POSIX's minimum 
requirement on the value of NL_ARGMAX is only of 9.


Thusly, musl defines NL_ARGMAX to 9 and errors on numbered argument 
conversion specifications with a position larger than it.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-12 22:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-12 21:35 [musl] printf does not print anything (musl 1.2.3) Detlef Riekenberg
2023-04-12 22:29 ` Gabriel Ravier

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).