Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Things that can go wrong when pointers are misused:</p> <ol> <li><p><b>Memory leaks</b> - You allocate a pointer in a method and then let it go out of scope without properly deallocating it. The pointer to the memory on the heap is now lost, but the memory remains allocated. Freeing this memory is now extremely difficult. <a href="http://en.wikipedia.org/wiki/Memory_leak" rel="noreferrer">More info from Wikipedia.</a></p></li> <li><p><b>Access violations</b> - You create a pointer that points at a memory address that you do not have access to, or that does not exist. Pointers are just integers afterall, and can be manipulated like any other number. When you attempt to dereference your invalid pointer, your program will halt. <a href="http://en.wikipedia.org/wiki/Segmentation_fault" rel="noreferrer">More info from Wikipedia.</a></p></li> <li><p><b>Null pointer errors</b> - This is a special case of an access violation. The proper way to "park" a pointer, so that it doesn't point at anything in particular, is to set its value to zero or null. Attempting to dereference a null pointer will halt your program. <a href="http://en.wikipedia.org/wiki/Pointer_(computing)#The_null_pointer" rel="noreferrer">More info from Wikipedia.</a></p></li> <li><p><b>Buffer overflows</b> - You allocate a pointer for a character buffer of 30 characters. You then proceed to stream user input (from a socket, file, console, etc.) into this buffer. If you fail to properly implement buffer bounding checks, then your program could potentially put more than 30 characters into the buffer. This will corrupt any data stored adjacent to the buffer in memory and possibly expose you to a malicious code attack. <a href="http://en.wikipedia.org/wiki/Buffer_overflow" rel="noreferrer">More info from Wikipedia.</a></p></li> <li><p><b>Memory corruption</b> - A pointer is just an integer that contains the memory address of something it points to. As an integer, <a href="http://c-faq.com/~scs/cclass/notes/sx10b.html" rel="noreferrer">pointer arithmetic</a> can be used to manipulate the pointer's value in all sorts of interesting ways. Subtle bugs can develop if the pointer calculations go wrong. The pointer will now point to some unknown location in memory, and anything could happen when it is dereferenced.</p></li> <li><p><b>Null-terminated string problems</b> - These bugs occur when string library functions that expect null-terminated strings are fed character pointers that are not null terminated. The string library functions will continue to process characters, one at a time, until a null is found -- wherever that may be. <a href="http://winterstorm.ca/string_joke" rel="noreferrer">A joke best illustrates this bug.</a></p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload