Quote:
Originally Posted by karthikb23
could be, but when i printed out contents of j, it was "" (obviously, as it is a dummy).
But maybe there could be some garbage in the 15 bytes allocated.
Like u mentioned, it should dump core both times.
Also, like porter mentioned it is up to the OS when/how much it should be strict.
|
You would say "obviously" but then "obviously" all the other pointers should be set to NULL as well. Write to NULL should cause SEGV.... However, if it is "" then that is part of why the existence of 'j' is stopping you from SEGV. Because while sprintf is traversing the string 'i' to dump its contents into 'k', it immediately hits the NULL terminator and limits the damage done. Quite possibly the "damage" done lies entirely within the allocated stack and never SEGVs. Either way, you're clobbering stuff you shouldn't.
Furthermore, I'm not sure that a SEGV (by definition) is ALWAYS due to writes. There is a text and data segment and I would suspect that an attempt to read the text segment could also cause a SEGV in some operating systems.