[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Technical question about glibc

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 11
Thread images: 1

why the output of
#include <stdio.h>

int main()
{
printf("%s", NULL);
return 0;
}

is
(null)%


but the output of
#include <stdio.h>

int main()
{
printf("%s\n", NULL);
return 0;
}

is a segfault ?
>>
>>57202778
Why don't you check the source, you lazy assed faggot.
>>
>>57203091
>check the warning, you lazy assed faggot.
>>
>>57202778
Both are undefined behavior.
The actual reason though is that the latter is optimized to puts() which does just crash on null whereas the former uses printf and glibc decided to print out (null) (which it didn't need to)
>>
>>57202778
Because you touch yourself at night
>>
>>57203091
>>57203302
>>57203377
Kill yourself you fucking cancer
>>
>>57202778
My guess would be printf handles a straight up null pointer by doing nothing, so no memory is accessed and thus no segfault.

In the second case you'd get a char[] containing null and a line break character. But the actual array pointer wouldn't be null so printf would try to print the string. So then you'll try to access a null pointer and segfault?
>>
>>57203401
No you, fucking nigger jew cancerous bastard fuckwit mongoloid child prick
>>
>>57202778

Hello, this is the actual answer :

gcc replace call to printf with the "%s\n" format string by a call to the puts function.

printf default implementation check null pointers, puts doesnt.

You're welcome.
>>
>>57204260
with clang you don't get a segfault
>>
>>57204479

because clang doesnt has this behavior and will call printf instead of puts.
Thread posts: 11
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.