The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #17 (permalink)  
Old 11-16-2007
DreamWarrior DreamWarrior is offline
Registered User
  
 

Join Date: Oct 2003
Posts: 70
Quote:
Originally Posted by karthikb23 View Post
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.