diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-10-29 11:08:17 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-11-23 12:15:06 -0800 |
commit | 05d8a7f7a785eff3292f0f0537bb3902930f1b5c (patch) | |
tree | 43dc322a988c1fab65622c2aea31c2b818ce20c8 /hw | |
parent | b967bf2af264726042e2f6ffb9ca7d234f34b56b (diff) |
Convert a bunch of sprintf to snprintf calls
This batch is the straightforward set - others are more complex and
need more analysis to determine right size to pass.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/dmx/examples/ev.c | 4 | ||||
-rw-r--r-- | hw/dmx/glxProxy/glxscreens.c | 5 | ||||
-rw-r--r-- | hw/kdrive/ephyr/ephyrhostvideo.c | 9 | ||||
-rw-r--r-- | hw/kdrive/linux/linux.c | 2 | ||||
-rw-r--r-- | hw/vfb/InitOutput.c | 3 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Option.c | 6 | ||||
-rw-r--r-- | hw/xfree86/common/xf86sbusBus.c | 2 | ||||
-rw-r--r-- | hw/xfree86/fbdevhw/fbdevhw.c | 6 | ||||
-rw-r--r-- | hw/xfree86/os-support/bsd/bsd_init.c | 10 | ||||
-rw-r--r-- | hw/xfree86/os-support/bus/Sbus.c | 12 | ||||
-rw-r--r-- | hw/xfree86/os-support/linux/lnx_init.c | 2 | ||||
-rw-r--r-- | hw/xfree86/x86emu/debug.c | 2 |
12 files changed, 33 insertions, 30 deletions
diff --git a/hw/dmx/examples/ev.c b/hw/dmx/examples/ev.c index ba45c2b25..ed23b8aa9 100644 --- a/hw/dmx/examples/ev.c +++ b/hw/dmx/examples/ev.c @@ -60,7 +60,7 @@ int main(int argc, char **argv) #define test_bit(bit) (mask[(bit)/8] & (1 << ((bit)%8))) for (i = 0; i < 32; i++) { - sprintf(name, "/dev/input/event%d", i); + snprintf(name, sizeof(name), "/dev/input/event%d", i); if ((fd = open(name, O_RDONLY, 0)) >= 0) { ioctl(fd, EVIOCGVERSION, &version); ioctl(fd, EVIOCGNAME(sizeof(buf)), buf); @@ -92,7 +92,7 @@ int main(int argc, char **argv) } if (argc > 1) { - sprintf(name, "/dev/input/event%d", atoi(argv[1])); + snprintf(name, sizeof(name), "/dev/input/event%d", atoi(argv[1])); if ((fd = open(name, O_RDWR, 0)) >= 0) { printf("%s: open, fd = %d\n", name, fd); for (i = 0; i < LED_MAX; i++) { diff --git a/hw/dmx/glxProxy/glxscreens.c b/hw/dmx/glxProxy/glxscreens.c index 01e041c8f..baa4a65a7 100644 --- a/hw/dmx/glxProxy/glxscreens.c +++ b/hw/dmx/glxProxy/glxscreens.c @@ -120,8 +120,9 @@ static void CalcServerVersionAndExtensions( void ) __glXVersionMinor = GLX_SERVER_MINOR_VERSION; } - sprintf(GLXServerVersion, "%d.%d DMX %d back-end server(s)", - __glXVersionMajor, __glXVersionMinor, __glXNumActiveScreens ); + snprintf(GLXServerVersion, sizeof(GLXServerVersion), + "%d.%d DMX %d back-end server(s)", + __glXVersionMajor, __glXVersionMinor, __glXNumActiveScreens ); /* * set the ExtensionsString to the minimum extensions string */ diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c index 600b50f74..69ad8a517 100644 --- a/hw/kdrive/ephyr/ephyrhostvideo.c +++ b/hw/kdrive/ephyr/ephyrhostvideo.c @@ -140,7 +140,7 @@ ephyrHostXVLogXErrorEvent (Display *a_display, mesg, BUFSIZ); (void) fprintf(a_fp, mesg, a_err_event->request_code); if (a_err_event->request_code < 128) { - sprintf(number, "%d", a_err_event->request_code); + snprintf(number, sizeof(number), "%d", a_err_event->request_code); XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); } else { for (ext = dpy->ext_procs; @@ -159,7 +159,8 @@ ephyrHostXVLogXErrorEvent (Display *a_display, fputs(" ", a_fp); (void) fprintf(a_fp, mesg, a_err_event->minor_code); if (ext) { - sprintf(mesg, "%s.%d", ext->name, a_err_event->minor_code); + snprintf(mesg, sizeof(mesg), "%s.%d", + ext->name, a_err_event->minor_code); XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ); (void) fprintf(a_fp, " (%s)", buffer); } @@ -182,8 +183,8 @@ ephyrHostXVLogXErrorEvent (Display *a_display, bext = ext; } if (bext) - sprintf(buffer, "%s.%d", bext->name, - a_err_event->error_code - bext->codes.first_error); + snprintf(buffer, sizeof(buffer), "%s.%d", bext->name, + a_err_event->error_code - bext->codes.first_error); else strcpy(buffer, "Value"); XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ); diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c index a53db4965..194e7cd59 100644 --- a/hw/kdrive/linux/linux.c +++ b/hw/kdrive/linux/linux.c @@ -109,7 +109,7 @@ LinuxInit (void) close(fd); } - sprintf(vtname,"/dev/tty%d",vtno); /* /dev/tty1-64 */ + snprintf(vtname,sizeof(vtname),"/dev/tty%d",vtno); /* /dev/tty1-64 */ if ((LinuxConsoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) < 0) { diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c index 121854781..3e5d05100 100644 --- a/hw/vfb/InitOutput.c +++ b/hw/vfb/InitOutput.c @@ -560,7 +560,8 @@ vfbAllocateMmappedFramebuffer(vfbScreenInfoPtr pvfb) char dummyBuffer[DUMMY_BUFFER_SIZE]; int currentFileSize, writeThisTime; - sprintf(pvfb->mmap_file, "%s/Xvfb_screen%d", pfbdir, (int) (pvfb - vfbScreens)); + snprintf(pvfb->mmap_file, sizeof(pvfb->mmap_file), "%s/Xvfb_screen%d", + pfbdir, (int) (pvfb - vfbScreens)); if (-1 == (pvfb->mmap_fd = open(pvfb->mmap_file, O_CREAT|O_RDWR, 0666))) { perror("open"); diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c index 9c528782f..d1d74f5a5 100644 --- a/hw/xfree86/common/xf86Option.c +++ b/hw/xfree86/common/xf86Option.c @@ -306,7 +306,7 @@ XF86OptionPtr xf86ReplaceIntOption(XF86OptionPtr optlist, const char *name, const int val) { char tmp[16]; - sprintf(tmp,"%i",val); + snprintf(tmp,sizeof(tmp),"%i",val); return xf86AddNewOption(optlist,name,tmp); } @@ -314,7 +314,7 @@ XF86OptionPtr xf86ReplaceRealOption(XF86OptionPtr optlist, const char *name, const double val) { char tmp[32]; - snprintf(tmp,32,"%f",val); + snprintf(tmp,sizeof(tmp),"%f",val); return xf86AddNewOption(optlist,name,tmp); } @@ -328,7 +328,7 @@ XF86OptionPtr xf86ReplacePercentOption(XF86OptionPtr optlist, const char *name, const double val) { char tmp[16]; - sprintf(tmp, "%lf%%", val); + snprintf(tmp, sizeof(tmp), "%lf%%", val); return xf86AddNewOption(optlist,name,tmp); } diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c index 181c6ab00..b7bb913fe 100644 --- a/hw/xfree86/common/xf86sbusBus.c +++ b/hw/xfree86/common/xf86sbusBus.c @@ -88,7 +88,7 @@ xf86SbusProbe(void) xf86SbusInfo = malloc(sizeof(psdp)); *xf86SbusInfo = NULL; for (i = 0; i < 32; i++) { - sprintf(fbDevName, "/dev/fb%d", i); + snprintf(fbDevName, sizeof(fbDevName), "/dev/fb%d", i); CheckSbusDevice(fbDevName, i); } if (sparcPromInit() >= 0) { diff --git a/hw/xfree86/fbdevhw/fbdevhw.c b/hw/xfree86/fbdevhw/fbdevhw.c index 30a2a9133..d7b4d3c20 100644 --- a/hw/xfree86/fbdevhw/fbdevhw.c +++ b/hw/xfree86/fbdevhw/fbdevhw.c @@ -265,20 +265,20 @@ fbdev_open_pci(struct pci_device * pPci, char **namep) int fd, i; for (i = 0; i < 8; i++) { - sprintf(filename, + snprintf(filename, sizeof(filename), "/sys/bus/pci/devices/%04x:%02x:%02x.%d/graphics/fb%d", pPci->domain, pPci->bus, pPci->dev, pPci->func, i); fd = open(filename, O_RDONLY, 0); if (fd < 0) { - sprintf(filename, + snprintf(filename, sizeof(filename), "/sys/bus/pci/devices/%04x:%02x:%02x.%d/graphics:fb%d", pPci->domain, pPci->bus, pPci->dev, pPci->func, i); fd = open(filename, O_RDONLY, 0); } if (fd >= 0) { close(fd); - sprintf(filename, "/dev/fb%d", i); + snprintf(filename, sizeof(filename), "/dev/fb%d", i); fd = open(filename, O_RDWR, 0); if (fd != -1) { diff --git a/hw/xfree86/os-support/bsd/bsd_init.c b/hw/xfree86/os-support/bsd/bsd_init.c index b58d6a790..7079d62b4 100644 --- a/hw/xfree86/os-support/bsd/bsd_init.c +++ b/hw/xfree86/os-support/bsd/bsd_init.c @@ -446,7 +446,7 @@ xf86OpenSyscons() } close(fd); - sprintf(vtname, "/dev/ttyv%01x", xf86Info.vtno - 1); + snprintf(vtname, sizeof(vtname), "/dev/ttyv%01x", xf86Info.vtno - 1); if ((fd = open(vtname, SYSCONS_CONSOLE_MODE, 0)) < 0) { FatalError("xf86OpenSyscons: Cannot open %s (%s)", @@ -550,13 +550,13 @@ xf86OpenPcvt() } close(fd); - sprintf(vtname, "%s%01x", vtprefix, xf86Info.vtno - 1); + snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, xf86Info.vtno - 1); if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { ErrorF("xf86OpenPcvt: Cannot open %s (%s)", vtname, strerror(errno)); xf86Info.vtno = initialVT; - sprintf(vtname, "%s%01x", vtprefix, xf86Info.vtno - 1); + snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, xf86Info.vtno - 1); if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { FatalError("xf86OpenPcvt: Cannot open %s (%s)", vtname, strerror(errno)); @@ -602,9 +602,9 @@ xf86OpenWScons() /* XXX Is this ok? */ for (i = 0; i < 8; i++) { #if defined(__NetBSD__) - sprintf(ttyname, "/dev/ttyE%d", i); + snprintf(ttyname, sizeof(ttyname), "/dev/ttyE%d", i); #elif defined(__OpenBSD__) - sprintf(ttyname, "/dev/ttyC%x", i); + snprintf(ttyname, sizeof(ttyname), "/dev/ttyC%x", i); #endif if ((fd = open(ttyname, 2)) != -1) break; diff --git a/hw/xfree86/os-support/bus/Sbus.c b/hw/xfree86/os-support/bus/Sbus.c index 7829d803f..c02d2cd55 100644 --- a/hw/xfree86/os-support/bus/Sbus.c +++ b/hw/xfree86/os-support/bus/Sbus.c @@ -446,14 +446,14 @@ promGetReg(int type) if (prop && len >= 4) { unsigned int *reg = (unsigned int *)prop; if (!promP1275 || (type == PROM_NODE_SBUS) || (type == PROM_NODE_EBUS)) - sprintf (regstr, "@%x,%x", reg[0], reg[1]); + snprintf (regstr, sizeof(regstr), "@%x,%x", reg[0], reg[1]); else if (type == PROM_NODE_PCI) { if ((reg[0] >> 8) & 7) - sprintf (regstr, "@%x,%x", (reg[0] >> 11) & 0x1f, (reg[0] >> 8) & 7); + snprintf (regstr, sizeof(regstr), "@%x,%x", (reg[0] >> 11) & 0x1f, (reg[0] >> 8) & 7); else - sprintf (regstr, "@%x", (reg[0] >> 11) & 0x1f); + snprintf (regstr, sizeof(regstr), "@%x", (reg[0] >> 11) & 0x1f); } else if (len == 4) - sprintf (regstr, "@%x", reg[0]); + snprintf (regstr, sizeof(regstr), "@%x", reg[0]); else { unsigned int regs[2]; @@ -465,9 +465,9 @@ promGetReg(int type) prop = promGetProperty("upa-portid", &len); if (prop && len == 4) { reg = (unsigned int *)prop; - sprintf (regstr, "@%x,%x", reg[0], regs[1]); + snprintf (regstr, sizeof(regstr), "@%x,%x", reg[0], regs[1]); } else - sprintf (regstr, "@%x,%x", regs[0] >> 4, regs[1]); + snprintf (regstr, sizeof(regstr), "@%x,%x", regs[0] >> 4, regs[1]); } } return regstr; diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c index f18271f38..5f3e3a9fb 100644 --- a/hw/xfree86/os-support/linux/lnx_init.c +++ b/hw/xfree86/os-support/linux/lnx_init.c @@ -146,7 +146,7 @@ xf86OpenConsole(void) i=0; while (vcs[i] != NULL) { - sprintf(vtname, vcs[i], xf86Info.vtno); /* /dev/tty1-64 */ + snprintf(vtname, sizeof(vtname), vcs[i], xf86Info.vtno); /* /dev/tty1-64 */ if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) >= 0) break; i++; diff --git a/hw/xfree86/x86emu/debug.c b/hw/xfree86/x86emu/debug.c index 5eda90805..04d0741e0 100644 --- a/hw/xfree86/x86emu/debug.c +++ b/hw/xfree86/x86emu/debug.c @@ -172,7 +172,7 @@ void x86emu_decode_printf (char *x) void x86emu_decode_printf2 (char *x, int y) { char temp[100]; - sprintf(temp,x,y); + snprintf(temp,sizeof(temp),x,y); sprintf(M.x86.decoded_buf+M.x86.enc_str_pos,"%s",temp); M.x86.enc_str_pos += strlen(temp); } |