From ff050f9bf0de156d904fa17cd4bdc96b3592189e Mon Sep 17 00:00:00 2001 From: marschap Date: Fri, 7 Apr 2006 17:35:09 +0000 Subject: [PATCH] more checks in IOWarrior_chr and IOWarrior_string --- server/drivers/IOWarrior.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/server/drivers/IOWarrior.c b/server/drivers/IOWarrior.c index e9c2e28..bc7d0a5 100644 --- a/server/drivers/IOWarrior.c +++ b/server/drivers/IOWarrior.c @@ -45,9 +45,6 @@ #include "report.h" #include "lcd_lib.h" -#define ValidX(x) if ((x) > p->width) { (x) = p->width; } else (x) = (x) < 1 ? 1 : (x); -#define ValidY(y) if ((y) > p->height) { (y) = p->height; } else (y) = (y) < 1 ? 1 :(y); - /* ===================== IOWarrior low level routines ====================== */ @@ -562,15 +559,13 @@ IOWarrior_chr(Driver *drvthis, int x, int y, char c) { PrivateData *p = drvthis->private_data; - ValidX(x); - ValidY(y); - y--; x--; - p->framebuf[(y * p->width) + x] = c; + if ((x >= 0) && (y >= 0) && (x < p->width) && (y < p->height)) + p->framebuf[(y * p->width) + x] = c; - debug(RPT_DEBUG, "%s: writing char 0x%02hhX at (%d,%d)", + debug(RPT_DEBUG, "%s: writing char 0x%02X at (%d,%d)", drvthis->name, (unsigned) c, x, y); } @@ -582,21 +577,18 @@ MODULE_EXPORT void IOWarrior_string(Driver *drvthis, int x, int y, char *string) { PrivateData *p = drvthis->private_data; - -int offset, siz; - - ValidX(x); - ValidY(y); +int i; x--; y--; - offset =(y * p->width) + x; + if ((y < 0) || (y >= p->height)) + return; - siz = (p->width * p->height) - offset; - siz = siz > strlen(string) ? strlen(string) : siz; - - memcpy(p->framebuf + offset, string, siz); + for (i = 0; (string[i] != '\0') && (x < p->width); i++, x++) { + if (x >= 0) // no write left of left border + p->framebuf[(y * p->width) + x] = string[i]; + } debug(RPT_DEBUG, "%s: writing string \"%s\" at (%d,%d)", drvthis->name, string, x, y);