gcc and printf/puts optimizationsTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
If I understand the above correctly, the only case that is changed/optimized by certain gcc versions is the printf("%s\n", (char*)) case. This is certainly because if the format string is different, or an int arg follows, it can not be replaced by puts. That logic appears consistent to me.
Furthermore, your statement "even in the generated assembler the code dereferences a NULL pointer and therefore results in a segfault" is not true, as there is only "mov $0x0,%edi" which means loading a value into a register. The dereferencing and segfault happens within the puts function. Ciao Bernhard M.
it is not consistent from a users perspective and it's not documented either, at least i don't know of any documentation. it is confusing. I am not saying it doesn't make sense. Consistency to me would mean to use puts whenever there's a (char *) or not using it at all. Of course you're right with the null ptr dereference, it happens of course in puts, the original text was a bit misleading regarding that.
Btw in the meantime I found another intersting document exploring this: http://www.ciselant.de/projects/gcc_printf/gcc_printf.html
Maybe the best fix would be to teach puts to handle NULL, too (string written as array below to avoid comment escaping bug).
Add Comment
|
Calendar
QuicksearchSupportRecent Entries
CategoriesTag cloud23c3 acpi advertising annouce announce april argh art awards bash blogging bugs c cli code conferences config configuration data mining debconf debian dell dns documentation email errm? events exploit fail fail2ban filesharing films flame fun gcc google graphs grml gsm hacking hacks hardware heise images information installation internet irc knowledge libacpi links linux mobile phones network news newsbeuter omg open source opera passwords php power privacy programming qa random blurb rant release releases rss scripts security service setup shell sms software spam ssh stfl stuff terminal tests text mode tip tips tools troubleshooting unix user video vim.editing web web 2.0 websites wordpress wtf www youtube zsh
|