Better HN
topnewbestaskshowjobs
Log inSign up

tgos

3 karma · joined Mar 10, 2009 (17y ago) · 1 submissions

Submissions

comment 17y ago · link · parent

Sorry for asking such a stupid question, but isn't that code horribly broken? It assumes that the next 3 byte after a string are readable. What if I malloc'ed memory for the string in such a way, that the \0 is the last byte of the memory page and the next byte after \0 is on the next page, which is not mapped into my VM space? In such a case the CPU will throw a page-fault and the process will die because of SIGSERV or SIGBUS. Or is the glibc version of malloc padding all memory to have at least 3 byte beyond its last byte?