From 004c5d7869f91ba1f0bc23f1e830922d1c91028c Mon Sep 17 00:00:00 2001 From: mmdolze Date: Mon, 24 Jan 2011 19:46:32 +0000 Subject: [PATCH] Better check for screen bounds. --- server/drivers/t6963.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/server/drivers/t6963.c b/server/drivers/t6963.c index 3c07858..9a238c7 100644 --- a/server/drivers/t6963.c +++ b/server/drivers/t6963.c @@ -324,25 +324,34 @@ t6963_flush(Driver * drvthis) /** * API: Prints a string on the lcd display, at position (x,y). The - * upper-left is (1,1), and the lower right should be (20,6). + * upper-left is (1,1), and the lower right should be (width,height). */ MODULE_EXPORT void t6963_string(Driver * drvthis, int x, int y, const char string[]) { PrivateData *p = drvthis->private_data; + int len; debug(RPT_DEBUG, "String out"); + /* Don't accept start coordinates outside the screen at all */ + if ((y < 1) || (y > p->height) || (x < 1) || (x > p->width)) + return; + x--; /* Convert 1-based coords to 0-based */ y--; - if ((y * p->width + x + strlen(string)) <= (p->width * p->height)) - memcpy(&p->display_buffer1[y * p->width + x], string, strlen(string)); + /* Restrict string length to screen width */ + len = strlen(string); + if (x + len > p->width) + len = p->width - x; + + memcpy(&p->display_buffer1[y * p->width + x], string, len); } /** * API: Prints a character on the lcd display, at position (x,y). The - * upper-left is (1,1), and the lower right should be (20,6). + * upper-left is (1,1), and the lower right should be (width,height). */ MODULE_EXPORT void t6963_chr(Driver * drvthis, int x, int y, char c) @@ -351,10 +360,14 @@ t6963_chr(Driver * drvthis, int x, int y, char c) debug(RPT_DEBUG, "Char out"); + /* Only copy if within screen bounds */ + if ((y < 1) || (y > p->height) || (x < 1) || (x > p->width)) + return; + y--; x--; - if ((y * p->width) + x <= (p->width * p->height)) - p->display_buffer1[(y * p->width) + x] = c; + + p->display_buffer1[(y * p->width) + x] = c; } /**