in reply to Re: sprintf and arrays of unknown (in advance) length
in thread sprintf and arrays of unknown (in advance) length

> What happens when perl ... "runs out" of parameters

Note that C behaves the same, but bash doesn't:

$ printf '[%s]' two strings [two][strings]

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^3: sprintf and arrays of unknown (in advance) length
by Anonymous Monk on Oct 12, 2018 at 11:34 UTC

    Curious: I couldn't get an example C program calling printf("%s\n", "two", "strings"); to crash or display any errors under Valgrind or -fsanitize=address -fsanitize=undefined even with full optimization and with omitted frame pointers, despite it being undefined behaviour.

    Not passing enough arguments in C for %s, though, causes a crash pretty quickly, because printf tries to interpret as a pointer something that was left on the stack from a previous function call, whatever it was. I got a lucky (null) a few times (stack had been filled with zeroes, and some C libraries handle NULL for %s as a special case, which is not required by the standard), then crashed on a different run when it tried to dereference address 0x1.