title: Coordinates passed to XDrawImageString()
body: <p>I was recently tracking down some strange behavior in a program I have been working on.</p>
  
  <p>The program has an X11 status window with a large amount of text written to it using</p>
  
  <pre><code> XDrawImageString(d, w, DefaultGC(d, s), x, y, str_to_draw, strlen(str_to_draw));
  </code></pre>
  
  <p>in a loop. There was no check on y going off the bottom of the window, I'd always assumed that stuff drawn off the edge of the window is simply ignored, however I discovered that if it is attempted to draw stuff too far off the bottom of the window, instead of being ignored, it can wrap around and start drawing at the top of the window again.</p>
  
  <p>This behaviour can be prevented by calling <code>XGetGeometry()</code> at the start of the loop and putting a check in that the coordinates don't overrun the dimensions of the window, what is more worrying is that it seems that this wrap around not only causes screen corruption but the occasional core dump. Not entirely sure on the core dump bit, but I encountered one that I am attributing to this for the moment.</p>
  
  <p>Questions:</p>
  
  <p>How careful does one need to be with the coordinates passed to <code>XDrawImageString()</code>  ?</p>
  
  <p>How careful does one need to be with the length of the string passed? If there is a problem with the bottom, it begs the question as to what happens if you go off the edge in a right hand direction.</p>
  
  <p>How dependent on the implementation of X11 is the answer to any of this?</p>