Timeline for Shortest code to produce non-deterministic output
Current License: CC BY-SA 4.0
16 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
S Feb 7, 2023 at 20:53 | history | suggested | CommunityBot | CC BY-SA 4.0 |
Fixed grammar
|
Feb 7, 2023 at 19:34 | review | Suggested edits | |||
S Feb 7, 2023 at 20:53 | |||||
Apr 12, 2017 at 5:28 | history | edited | user58988 | CC BY-SA 3.0 |
added 63 characters in body
|
Dec 6, 2016 at 14:47 | comment | added | Peter Cordes |
@RosLuP: argv is on the stack, but not at the very top. Its address is affected by stack ASLR, though, so that works. This would work less well with -m32 . You'd probably always get zero, since main has to keep the stack aligned so the stack slot above the format string may be fresh stack memory that has never been touched (and is probably always zero, since the kernel avoids info leaks by zeroing pages instead of giving user-space pages full of old data).
|
|
Dec 6, 2016 at 14:42 | comment | added | Peter Cordes |
@RosLuP: It would just print whatever garbage was in stack memory (or in the second arg-passing register, for x86-64 and most RISC calling conventions that pass the first few args in registers). It would not print the address of the stack. In x86-64, it would be somewhat likely to print argv , since the compiler would probably call printf with main's second arg still in that register. That's exactly what happens with gcc6.2 targeting Linux: See the source+asm on the Godbolt compiler explorer: main doesn't touch RSI before call printf .
|
|
Dec 1, 2016 at 15:14 | comment | added | cat | Yeah, that also seems to work with GCC although a byte longer | |
Dec 1, 2016 at 15:08 | comment | added | user58988 | Thanks, for doing something better why not "main(){printf("%p");}" I count 20 characters; this would be portable and would print the top of the stack address (if I see right) | |
Dec 1, 2016 at 14:56 | comment | added | cat | I've edited your answer to include more information about the environment | |
Dec 1, 2016 at 14:56 | history | edited | cat | CC BY-SA 3.0 |
added 19 characters in body
|
Dec 1, 2016 at 14:53 | comment | added | user58988 | @cat it is one Borland C compiler + Windows7 Os. In how I see: above code gets the address top of stack (where in this case there is the address to return in function main() )and read from that address inside main space code... So it depend to compiler output. But I don't know 100% ... It is possible code space is not readable in your Os and from this => seg fault | |
Dec 1, 2016 at 14:35 | comment | added | cat | Alternatively, if you get something other than a segfault, what compiler ?? | |
Dec 1, 2016 at 14:26 | comment | added | cat | This doesn't give nondeterministic output, it just segfaults every time. | |
Dec 1, 2016 at 11:28 | history | edited | user58988 | CC BY-SA 3.0 |
added 67 characters in body
|
Dec 1, 2016 at 11:21 | history | edited | user58988 | CC BY-SA 3.0 |
added 67 characters in body
|
Dec 1, 2016 at 8:15 | review | Low quality posts | |||
Dec 1, 2016 at 8:45 | |||||
Dec 1, 2016 at 7:55 | history | answered | user58988 | CC BY-SA 3.0 |