From 44e7f83dfd052053ae3cecc21bfd5a4a9638b646 Mon Sep 17 00:00:00 2001 From: ddouthitt Date: Tue, 25 Sep 2001 15:02:33 +0000 Subject: [PATCH] Removed all traces of sprintf() from all server code and from all drivers. All drivers compile without warnings. --- server/client_functions.c | 4 ++-- server/drivers/CFontz.c | 4 ++-- server/drivers/MtxOrb.c | 24 ++++++++++++------------ server/drivers/bayrad.c | 2 +- server/drivers/hd44780.c | 4 ++-- server/drivers/lb216.c | 22 +++++++++++----------- server/drivers/wirz-sli.c | 4 ++-- server/main.c | 2 +- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/server/client_functions.c b/server/client_functions.c index e19a49c..2345dbf 100644 --- a/server/client_functions.c +++ b/server/client_functions.c @@ -110,7 +110,7 @@ hello_func (client * c, int argc, char **argv) debug ("Hello!\n"); memset(str, '\0', sizeof(str)); - sprintf (str, "connect LCDproc %s protocol %s lcd wid %i hgt %i cellwid %i cellhgt %i\n", + snprintf (str, sizeof(str), "connect LCDproc %s protocol %s lcd wid %i hgt %i cellwid %i cellhgt %i\n", version, protocol_version, lcd.wid, lcd.hgt, lcd.cellwid, lcd.cellhgt); // lcdproc (client) depends on the above format... @@ -1433,7 +1433,7 @@ sleep_func (client * c, int argc, char **argv) // Repeat until no more remains - should normally be zero // on exit the first time... - sprintf(str, "sleeping %d seconds\n", secs); + snprintf(str, sizeof(str), "sleeping %d seconds\n", secs); sock_send_string (c->sock, str); // whoops.... if this takes place as planned, ALL screens diff --git a/server/drivers/CFontz.c b/server/drivers/CFontz.c index b1354b4..4e15dc5 100644 --- a/server/drivers/CFontz.c +++ b/server/drivers/CFontz.c @@ -306,7 +306,7 @@ CFontz_backlight (int on) char out[4]; if (on) { snprintf (out, sizeof(out), "%c%c", 14, (unsigned char) (on * 100 / 255)); - //sprintf(out, "%c%c", 14, 100); + //snprintf(out, sizeof(out), "%c%c", 14, 100); } else { snprintf (out, sizeof(out), "%c%c", 14, 0); } @@ -694,7 +694,7 @@ CFontz_draw_frame (char *dat) write (fd, dat + (CFontz->wid * i), CFontz->wid); } /* - sprintf(out, "%c", 1); + snprintf(out, sizeof(out), "%c", 1); write(fd, out, 1); write(fd, dat, CFontz->wid*CFontz->hgt); */ diff --git a/server/drivers/MtxOrb.c b/server/drivers/MtxOrb.c index 78173c0..ac9e0a3 100644 --- a/server/drivers/MtxOrb.c +++ b/server/drivers/MtxOrb.c @@ -421,7 +421,7 @@ MtxOrb_flush_box (int lft, int top, int rgt, int bot) char out[LCD_MAX_WIDTH]; for (y = top; y <= bot; y++) { - sprintf (out, "\x0FEG%c%c", lft, y); + snprintf (out, sizeof(out), "\x0FEG%c%c", lft, y); write (fd, out, 4); write (fd, MtxOrb->framebuf + (y * MtxOrb->wid) + lft, rgt - lft + 1); @@ -447,7 +447,7 @@ MtxOrb_chr (int x, int y, char c) // write immediately to screen... this code was taken // from the LK202-25; should work for others, yes? - // sprintf(out, "\x0FEG%c%c%c", x, y, c); + // snprintf(out, sizeof(out), "\x0FEG%c%c%c", x, y, c); // write (fd, out, 4); // write to frame buffer @@ -479,7 +479,7 @@ MtxOrb_contrast (int contrast) contrast = 0; if (IS_LCD_DISPLAY || IS_LKD_DISPLAY) { - sprintf (out, "\x0FEP%c", contrast); + snprintf (out, sizeof(out), "\x0FEP%c", contrast); write (fd, out, 3); } return contrast; @@ -541,8 +541,8 @@ MtxOrb_output (int on) on = on & 077; // strip to six bits for(i = 0; i < 6; i++) { (on & (1 << i)) ? - sprintf (out, "\x0FEW%c", i + 1) : - sprintf (out, "\x0FEV%c", i + 1); + snprintf (out, sizeof(out), "\x0FEW%c", i + 1) : + snprintf (out, sizeof(out), "\x0FEV%c", i + 1); write (fd, out, 3); } } @@ -664,7 +664,7 @@ MtxOrb_getinfo (void) case '\x33': strcat(info, "LK402-12 "); break; case '\x34': strcat(info, "LK162-12 "); break; case '\x35': strcat(info, "LK204-25PC "); break; - default: //sprintf(tmp, "Unknown (%X) ", in); strcat(info, tmp); + default: //snprintf(tmp, sizeof(tmp), "Unknown (%X) ", in); strcat(info, tmp); break; } } @@ -688,7 +688,7 @@ MtxOrb_getinfo (void) if (read (fd, &tmp, 2) < 0) { syslog(LOG_WARNING, "MatrixOrbital driver: unable to read data"); } else { - sprintf(buf, "Serial No: %ld ", (long int) tmp); + snprintf(buf, sizeof(buf), "Serial No: %ld ", (long int) tmp); strcat(info, buf); } } else @@ -711,7 +711,7 @@ MtxOrb_getinfo (void) if (read (fd, &tmp, 2) < 0) { syslog(LOG_WARNING, "MatrixOrbital driver: unable to read data"); } else { - sprintf(buf, "Firmware Rev. %ld ", (long int) tmp); + snprintf(buf, sizeof(buf), "Firmware Rev. %ld ", (long int) tmp); strcat(info, buf); } } else @@ -823,7 +823,7 @@ static void MtxOrb_num (int x, int num) { char out[5]; - sprintf (out, "\x0FE#%c%c", x, num); + snprintf (out, sizeof(out), "\x0FE#%c%c", x, num); write (fd, out, 4); } @@ -848,7 +848,7 @@ MtxOrb_set_char (int n, char *dat) if (!dat) return; - sprintf (out, "\x0FEN%c", n); + snprintf (out, sizeof(out), "\x0FEN%c", n); write (fd, out, 3); for (row = 0; row < MtxOrb->cellhgt; row++) { @@ -919,12 +919,12 @@ MtxOrb_draw_frame (char *dat) if (!dat) return; -// sprintf(out, "%cG%c%c", 254, 1, 1); +// snprintf(out, sizeof(out), "%cG%c%c", 254, 1, 1); // write(fd, out, 4); // write(fd, dat, lcd.wid*lcd.hgt); for (i = 0; i < MtxOrb->hgt; i++) { - sprintf (out, "\x0FEG\x001%c", i + 1); + snprintf (out, sizeof(out), "\x0FEG\x001%c", i + 1); write (fd, out, 4); write (fd, dat + (MtxOrb->wid * i), MtxOrb->wid); } diff --git a/server/drivers/bayrad.c b/server/drivers/bayrad.c index 5316202..d35480b 100644 --- a/server/drivers/bayrad.c +++ b/server/drivers/bayrad.c @@ -669,7 +669,7 @@ void bayrad_set_char(int n, char *dat) n = 0x40 + (n * 8); /* Set n to the proper location in CG RAM */ /* Set the LCD to accept data for rewrite-able char n */ - sprintf(out, "\x88%c", n); + snprintf(out, sizeof(out), "\x88%c", n); write(fd, out, 2); for(row=0; row= 0) c += 128; // lcd.framebuf[(y*lcd.wid) + x] = c; char chr[1]; - sprintf(chr, "%c", c); + snprintf (chr, sizeof(chr), "%c", c); LB216_string (x, y, chr); } @@ -267,11 +267,11 @@ void LB216_backlight(int on) char out[4]; if(on) { - sprintf(out, "%c%c", 254, 253); + snprintf (out, sizeof(out), "%c%c", 254, 253); } else { - sprintf(out, "%c%c", 254, 252); + snprintf (out, sizeof(out), "%c%c", 254, 252); } write(fd, out, 2); } @@ -283,7 +283,7 @@ void LB216_backlight(int on) static void LB216_hidecursor() { char out[4]; - sprintf(out, "%c%c", 254,12); + snprintf (out, sizeof(out), "%c%c", 254,12); write(fd, out, 2); } @@ -293,7 +293,7 @@ static void LB216_hidecursor() static void LB216_reboot() { char out[4]; - sprintf(out, "%c%c", 254,1); + snprintf (out, sizeof(out), "%c%c", 254,1); write(fd, out, 2); } @@ -310,18 +310,18 @@ void LB216_draw_frame(char *dat) if(!dat) return; - sprintf(out, "%c%c", 254,80); + snprintf (out, sizeof(out), "%c%c", 254,80); write(fd, out, 2); for(j=0; j=2) { - sprintf(out,"%c%c",254,148+(64*(j-2))); + snprintf (out, sizeof(out),"%c%c",254,148+(64*(j-2))); } else { - sprintf(out,"%c%c",254,128+(64*(j))); + snprintf (out, sizeof(out),"%c%c",254,128+(64*(j))); } write(fd, out, 2); for(i=0; i 0); } - sprintf(out,"%c",letter); + snprintf (out, sizeof(out),"%c",letter); write(fd, out, 1); } } diff --git a/server/drivers/wirz-sli.c b/server/drivers/wirz-sli.c index 7a10809..a382c02 100644 --- a/server/drivers/wirz-sli.c +++ b/server/drivers/wirz-sli.c @@ -226,9 +226,9 @@ sli_flush_box (int lft, int top, int rgt, int bot) /* I like having hex, everywhere and all the time */ for (y = top; y <= bot; y++) { if (y == 1) - sprintf (out, "%c%c", 0x0FE, 0x080 + lft); + snprintf (out, sizeof(out), "%c%c", 0x0FE, 0x080 + lft); if (y == 2) - sprintf (out, "%c%c", 0x0FE, 0x0C0 + lft); + snprintf (out, sizeof(out), "%c%c", 0x0FE, 0x0C0 + lft); write (fd, out, 0x002); write (fd, lcd.framebuf + (y * lcd.wid) + lft, rgt - lft + 1); } diff --git a/server/main.c b/server/main.c index 389759e..f0925e9 100644 --- a/server/main.c +++ b/server/main.c @@ -433,7 +433,7 @@ exit_program (int val) case 1: strcat(buf, "SIGHUP"); break; case 2: strcat(buf, "SIGINT"); break; case 15: strcat(buf, "SIGTERM"); break; - default: sprintf(buf, "server shutting down on signal %d", val); break; + default: snprintf(buf, sizeof(buf), "server shutting down on signal %d", val); break; // Other values should not be seen, but just in case.. }