Harder investigation of a really strange unexpected result <p>I posted before about that problem.. but the problem couldn't be solved. So i can honestly say that is the weirdest, unexplained complication i ever had in my programming experience.</p> <p>The problem is when i draw a bmp from buffer. <img src="https://i.stack.imgur.com/f3134.png" alt="enter image description here"></p> <p>If i change the image's dimension for example if i make width > height or height > width, the images goes rendered normally. Take a look at the code:</p> <pre><code>void bmp_bdraw (BYTE* BUFF) { word WIDTH, HEIGHT, W, H; // word - unsigned short BYTE R, G, B; // BYTE - unsigned char (!BUFF || !BUFF[COUNT-1]) ? // debug1 (error("Error in function 'bmp_bdraw'. There is no data to read from.")) : ; WIDTH = BUFF[18] + BUFF[19] * 256; HEIGHT = BUFF[22] + BUFF[23] * 256; ofs = 54; if(BUFF[0] != 'B' | BUFF[1] != 'M') error // debug2 ("Warning: Data identifier error in function 'bmp_bdraw' occurred. Invalid BMP file loaded."); for(H=HEIGHT-1; H&gt;=1; H--) { for(W=0; W&lt;WIDTH; W++) { B = sgetc(BUFF); // fgetc-like function but from buff G = sgetc(BUFF); R = sgetc(BUFF); setpen(R, G, B, 0, 1); // sets the color, transparancy and size of the pen putpixel(W, H); // and puts the pixel at the right location } } if(W != WIDTH || H &gt; 1) // debug3 error("Error in function 'bmp_bdraw'. Rendering failed. The file might be damaged."); if(real_fps &lt; 11) error("Too low fps rate."); // debug4 </code></pre> <p>What i have noticed in the line: <code>for(H=HEIGHT-1; H&gt;=1; H--)</code> is the <code>H&gt;=1</code> In the direct draw (bmp to render) function (that works 100% and uses the same method) it is <code>H&gt;=0</code> However.. if i change the <code>H&gt;=1</code> to <code>H&gt;=0</code> it returns an error for buffer overflow, returned by the <code>sgetc</code> function.</p>