unsigned char *dst = buf + dsty * 800*4 + (x + xpos + slot->bitmap_left)*4;
unsigned char *src = bm->buffer + y * bm->width;
- for (xx = 0; xx < bm->width; xx++) {
+
+ int width = (x + xpos + slot->bitmap_left + bm->width >= 800) ? (799 - x - xpos - slot->bitmap_left) : bm->width;
+ for (xx = 0; xx < width; xx++) {
*dst = (*dst * (256-*src) + r * *src) >> 8;
*dst++;
*dst = (*dst * (256-*src) + g * *src) >> 8;