Replace XmuSnprintf with snprintf.

Alan Coopersmith explains:

	XmuSnprintf() can be replaced by snprintf() now. (It was a
	implementation X provided for it's libraries to use in the days
	before all platforms we cared about had snprintf in libc.)

Reported-by: walter harms <wharms@bfs.de>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
This commit is contained in:
Jamey Sharp 2011-09-18 20:47:04 -05:00
parent df4eeb1256
commit 87cc83474d
9 changed files with 31 additions and 32 deletions

View File

@ -49,7 +49,6 @@
#include <X11/Xaw/Viewport.h> #include <X11/Xaw/Viewport.h>
#include <X11/Xaw/Dialog.h> #include <X11/Xaw/Dialog.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/Xmu/SysUtil.h>
#include "Canvas.h" #include "Canvas.h"
#include "dmxparse.h" #include "dmxparse.h"
@ -199,8 +198,8 @@ static void dmxConfigDataUpdate(void)
XtVaSetValues(ndbutton1, XtNsensitive, False, NULL); XtVaSetValues(ndbutton1, XtNsensitive, False, NULL);
} else { } else {
name = dmxConfigCurrent->name; name = dmxConfigCurrent->name;
XmuSnprintf(cnambuf, sizeof(cnambuf), "%s", name ? name : ""); snprintf(cnambuf, sizeof(cnambuf), "%s", name ? name : "");
XmuSnprintf(cdimbuf, sizeof(cdimbuf), "%dx%d", snprintf(cdimbuf, sizeof(cdimbuf), "%dx%d",
dmxConfigWallWidth, dmxConfigWallHeight); dmxConfigWallWidth, dmxConfigWallHeight);
XtVaSetValues(cnamebox, XtNlabel, cnambuf, XtNsensitive, True, NULL); XtVaSetValues(cnamebox, XtNlabel, cnambuf, XtNsensitive, True, NULL);
XtVaSetValues(cdimbox, XtNlabel, cdimbuf, XtNsensitive, True, NULL); XtVaSetValues(cdimbox, XtNlabel, cdimbuf, XtNsensitive, True, NULL);
@ -219,22 +218,22 @@ static void dmxConfigDataUpdate(void)
XtVaSetValues(ddbutton, XtNsensitive, False, NULL); XtVaSetValues(ddbutton, XtNsensitive, False, NULL);
} else { } else {
name = dmxConfigCurrentDisplay->name; name = dmxConfigCurrentDisplay->name;
XmuSnprintf(nambuf, sizeof(nambuf), "%s", name ? name : ""); snprintf(nambuf, sizeof(nambuf), "%s", name ? name : "");
XmuSnprintf(dimbuf, sizeof(dimbuf), "%dx%d%c%d%c%d", snprintf(dimbuf, sizeof(dimbuf), "%dx%d%c%d%c%d",
dmxConfigCurrentDisplay->scrnWidth, dmxConfigCurrentDisplay->scrnWidth,
dmxConfigCurrentDisplay->scrnHeight, dmxConfigCurrentDisplay->scrnHeight,
dmxConfigCurrentDisplay->scrnXSign < 0 ? '-' : '+', dmxConfigCurrentDisplay->scrnXSign < 0 ? '-' : '+',
dmxConfigCurrentDisplay->scrnX, dmxConfigCurrentDisplay->scrnX,
dmxConfigCurrentDisplay->scrnYSign < 0 ? '-' : '+', dmxConfigCurrentDisplay->scrnYSign < 0 ? '-' : '+',
dmxConfigCurrentDisplay->scrnY); dmxConfigCurrentDisplay->scrnY);
XmuSnprintf(rtbuf, sizeof(dimbuf), "%dx%d%c%d%c%d", snprintf(rtbuf, sizeof(dimbuf), "%dx%d%c%d%c%d",
dmxConfigCurrentDisplay->rootWidth, dmxConfigCurrentDisplay->rootWidth,
dmxConfigCurrentDisplay->rootHeight, dmxConfigCurrentDisplay->rootHeight,
dmxConfigCurrentDisplay->rootXSign < 0 ? '-' : '+', dmxConfigCurrentDisplay->rootXSign < 0 ? '-' : '+',
dmxConfigCurrentDisplay->rootX, dmxConfigCurrentDisplay->rootX,
dmxConfigCurrentDisplay->rootYSign < 0 ? '-' : '+', dmxConfigCurrentDisplay->rootYSign < 0 ? '-' : '+',
dmxConfigCurrentDisplay->rootY); dmxConfigCurrentDisplay->rootY);
XmuSnprintf(offbuf, sizeof(offbuf), "@%dx%d", snprintf(offbuf, sizeof(offbuf), "@%dx%d",
dmxConfigCurrentDisplay->rootXOrigin, dmxConfigCurrentDisplay->rootXOrigin,
dmxConfigCurrentDisplay->rootYOrigin); dmxConfigCurrentDisplay->rootYOrigin);
XtVaSetValues(namebox, XtNlabel, nambuf, XtNsensitive, True, NULL); XtVaSetValues(namebox, XtNlabel, nambuf, XtNsensitive, True, NULL);
@ -596,14 +595,14 @@ static void dmxConfigCanCallback(Widget w, XtPointer closure,
static void dmxConfigECCallback(Widget w, XtPointer closure, static void dmxConfigECCallback(Widget w, XtPointer closure,
XtPointer callData) XtPointer callData)
{ {
char buf[256]; /* RATS: Only used in XmuSnprintf */ char buf[256]; /* RATS: Only used in snprintf */
if (!dmxConfigCurrent) return; if (!dmxConfigCurrent) return;
dmxConfigSetPopupPosition(ecpopup); dmxConfigSetPopupPosition(ecpopup);
XtVaSetValues(ecdialog0, XtNvalue, XtVaSetValues(ecdialog0, XtNvalue,
dmxConfigCurrent->name ? dmxConfigCurrent->name : "", dmxConfigCurrent->name ? dmxConfigCurrent->name : "",
NULL); NULL);
XmuSnprintf(buf, sizeof(buf), "%dx%d", snprintf(buf, sizeof(buf), "%dx%d",
dmxConfigCurrent->width, dmxConfigCurrent->height); dmxConfigCurrent->width, dmxConfigCurrent->height);
XtVaSetValues(ecdialog1, XtNvalue, buf, NULL); XtVaSetValues(ecdialog1, XtNvalue, buf, NULL);
XtPopup(ecpopup, XtGrabExclusive); XtPopup(ecpopup, XtGrabExclusive);
@ -692,7 +691,7 @@ static void dmxConfigECCanCallback(Widget w, XtPointer closure,
static void dmxConfigEDCallback(Widget w, XtPointer closure, static void dmxConfigEDCallback(Widget w, XtPointer closure,
XtPointer callData) XtPointer callData)
{ {
char buf[256]; /* RATS: Only used in XmuSnprintf */ char buf[256]; /* RATS: Only used in snprintf */
if (!dmxConfigCurrent || !dmxConfigCurrentDisplay) return; if (!dmxConfigCurrent || !dmxConfigCurrentDisplay) return;
dmxConfigSetPopupPosition(edpopup); dmxConfigSetPopupPosition(edpopup);
@ -701,7 +700,7 @@ static void dmxConfigEDCallback(Widget w, XtPointer closure,
? dmxConfigCurrentDisplay->name ? dmxConfigCurrentDisplay->name
: "", : "",
NULL); NULL);
XmuSnprintf(buf, sizeof(buf), "%dx%d%c%d%c%d", snprintf(buf, sizeof(buf), "%dx%d%c%d%c%d",
dmxConfigCurrentDisplay->scrnWidth, dmxConfigCurrentDisplay->scrnWidth,
dmxConfigCurrentDisplay->scrnHeight, dmxConfigCurrentDisplay->scrnHeight,
dmxConfigCurrentDisplay->scrnXSign < 0 ? '-' : '+', dmxConfigCurrentDisplay->scrnXSign < 0 ? '-' : '+',
@ -709,7 +708,7 @@ static void dmxConfigEDCallback(Widget w, XtPointer closure,
dmxConfigCurrentDisplay->scrnYSign < 0 ? '-' : '+', dmxConfigCurrentDisplay->scrnYSign < 0 ? '-' : '+',
dmxConfigCurrentDisplay->scrnY); dmxConfigCurrentDisplay->scrnY);
XtVaSetValues(eddialog1, XtNvalue, buf, NULL); XtVaSetValues(eddialog1, XtNvalue, buf, NULL);
XmuSnprintf(buf, sizeof(buf), "@%dx%d", snprintf(buf, sizeof(buf), "@%dx%d",
dmxConfigCurrentDisplay->rootXOrigin, dmxConfigCurrentDisplay->rootXOrigin,
dmxConfigCurrentDisplay->rootYOrigin); dmxConfigCurrentDisplay->rootYOrigin);
XtVaSetValues(eddialog2, XtNvalue, buf, NULL); XtVaSetValues(eddialog2, XtNvalue, buf, NULL);

View File

@ -82,7 +82,6 @@ typedef XID KeySym64;
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/cursorfont.h> #include <X11/cursorfont.h>
#include <X11/Xmu/SysUtil.h> /* For XmuSnprintf */
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>

View File

@ -56,6 +56,7 @@
#include "dmxpict.h" #include "dmxpict.h"
#include <X11/Xos.h> /* For gettimeofday */ #include <X11/Xos.h> /* For gettimeofday */
#include <X11/Xmu/SysUtil.h> /* For XmuGetHostname */
#include "dixstruct.h" #include "dixstruct.h"
#ifdef PANORAMIX #ifdef PANORAMIX
#include "panoramiXsrv.h" #include "panoramiXsrv.h"
@ -131,7 +132,7 @@ static int dmxErrorHandler(Display *dpy, XErrorEvent *ev)
/* Find major opcode name */ /* Find major opcode name */
if (ev->request_code < 128) { if (ev->request_code < 128) {
XmuSnprintf(request, sizeof(request), "%d", ev->request_code); snprintf(request, sizeof(request), "%d", ev->request_code);
XGetErrorDatabaseText(dpy, "XRequest", request, "", buf, sizeof(buf)); XGetErrorDatabaseText(dpy, "XRequest", request, "", buf, sizeof(buf));
} else { } else {
for (ext = dpy->ext_procs; for (ext = dpy->ext_procs;
@ -145,8 +146,8 @@ static int dmxErrorHandler(Display *dpy, XErrorEvent *ev)
/* Find minor opcode name */ /* Find minor opcode name */
if (ev->request_code >= 128 && ext) { if (ev->request_code >= 128 && ext) {
XmuSnprintf(request, sizeof(request), "%d", ev->request_code); snprintf(request, sizeof(request), "%d", ev->request_code);
XmuSnprintf(request, sizeof(request), "%s.%d", snprintf(request, sizeof(request), "%s.%d",
ext->name, ev->minor_code); ext->name, ev->minor_code);
XGetErrorDatabaseText(dpy, "XRequest", request, "", buf, sizeof(buf)); XGetErrorDatabaseText(dpy, "XRequest", request, "", buf, sizeof(buf));
dmxLog(dmxWarning, " Minor opcode: %d (%s)\n", dmxLog(dmxWarning, " Minor opcode: %d (%s)\n",
@ -515,7 +516,7 @@ static const char *dmxExecOS(void)
if (!initialized++) { if (!initialized++) {
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
uname(&u); uname(&u);
XmuSnprintf(buffer, sizeof(buffer)-1, "%s %s %s", snprintf(buffer, sizeof(buffer)-1, "%s %s %s",
u.sysname, u.release, u.version); u.sysname, u.release, u.version);
} }
return buffer; return buffer;
@ -530,7 +531,7 @@ static const char *dmxBuildCompiler(void)
if (!initialized++) { if (!initialized++) {
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
#if defined(__GNUC__) && defined(__GNUC_MINOR__) &&defined(__GNUC_PATCHLEVEL__) #if defined(__GNUC__) && defined(__GNUC_MINOR__) &&defined(__GNUC_PATCHLEVEL__)
XmuSnprintf(buffer, sizeof(buffer)-1, "gcc %d.%d.%d", snprintf(buffer, sizeof(buffer)-1, "gcc %d.%d.%d",
__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#endif #endif
} }

View File

@ -62,6 +62,7 @@
#include "dmx.h" #include "dmx.h"
#include "dmxprop.h" #include "dmxprop.h"
#include "dmxlog.h" #include "dmxlog.h"
#include <X11/Xmu/SysUtil.h> /* For XmuGetHostname */
/** Holds the window id of all DMX windows on the backend X server. */ /** Holds the window id of all DMX windows on the backend X server. */
#define DMX_ATOMNAME "DMX_NAME" #define DMX_ATOMNAME "DMX_NAME"
@ -87,7 +88,7 @@ static const unsigned char *dmxPropertyIdentifier(void)
if (initialized++) return (unsigned char *)buf; if (initialized++) return (unsigned char *)buf;
XmuGetHostname(hostname, sizeof(hostname)); XmuGetHostname(hostname, sizeof(hostname));
XmuSnprintf(buf, sizeof(buf), "%s:%s:%s", DMX_IDENT, hostname, display); snprintf(buf, sizeof(buf), "%s:%s:%s", DMX_IDENT, hostname, display);
return (unsigned char *)buf; return (unsigned char *)buf;
} }
@ -319,7 +320,7 @@ void dmxPropertyWindow(DMXScreenInfo *dmxScreen)
Display *dpy = dmxScreen->beDisplay; Display *dpy = dmxScreen->beDisplay;
Window win = dmxScreen->scrnWin; Window win = dmxScreen->scrnWin;
DMXScreenInfo *other; DMXScreenInfo *other;
char buf[128]; /* RATS: only used with XmuSnprintf */ char buf[128]; /* RATS: only used with snprintf */
if (!dpy) if (!dpy)
return; /* FIXME: What should be done here if Xdmx is started return; /* FIXME: What should be done here if Xdmx is started
@ -336,12 +337,12 @@ void dmxPropertyWindow(DMXScreenInfo *dmxScreen)
other->index, other->name, other->scrnWin); other->index, other->name, other->scrnWin);
} }
XmuSnprintf(buf, sizeof(buf), ".%d,%lu", dmxScreen->index, snprintf(buf, sizeof(buf), ".%d,%lu", dmxScreen->index,
(long unsigned)win); (long unsigned)win);
XChangeProperty(dpy, RootWindow(dpy,0), atom, XA_STRING, 8, XChangeProperty(dpy, RootWindow(dpy,0), atom, XA_STRING, 8,
PropModeAppend, (unsigned char *)buf, strlen(buf)); PropModeAppend, (unsigned char *)buf, strlen(buf));
XmuSnprintf(buf, sizeof(buf), "%s,%d", id, dmxScreen->index); snprintf(buf, sizeof(buf), "%s,%d", id, dmxScreen->index);
XChangeProperty(dpy, win, atom, XA_STRING, 8, XChangeProperty(dpy, win, atom, XA_STRING, 8,
PropModeAppend, (unsigned char *)buf, strlen(buf)); PropModeAppend, (unsigned char *)buf, strlen(buf));
} }

View File

@ -3392,7 +3392,7 @@ Unrepaired warnings are as follows:
<orderedlist> <orderedlist>
<listitem><para> <listitem><para>
Fixed-size buffers are used in many areas, but code has been Fixed-size buffers are used in many areas, but code has been
added to protect against buffer overflows (e.g., XmuSnprint). added to protect against buffer overflows (e.g., snprintf).
The only instances that have not yet been fixed are in The only instances that have not yet been fixed are in
config/xdmxconfig.c (which is not part of the Xdmx server) and config/xdmxconfig.c (which is not part of the Xdmx server) and
input/usb-common.c. input/usb-common.c.

View File

@ -39,7 +39,6 @@
#include <string.h> #include <string.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xmu/SysUtil.h>
#include <X11/extensions/dmxext.h> #include <X11/extensions/dmxext.h>
static const char *FontName = "fixed"; static const char *FontName = "fixed";
@ -80,7 +79,7 @@ EventLoop(Display *dpy, Window win, GC gc)
y += 20; y += 20;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
char str[500]; char str[500];
XmuSnprintf(str, sizeof(str), snprintf(str, sizeof(str),
"screen %d: pos: %dx%d+%d+%d visible: %dx%d+%d+%d", "screen %d: pos: %dx%d+%d+%d visible: %dx%d+%d+%d",
winInfo[i].screen, winInfo[i].screen,
winInfo[i].pos.width, winInfo[i].pos.height, winInfo[i].pos.width, winInfo[i].pos.height,

View File

@ -671,9 +671,9 @@ static char *dmxMakeUniqueDeviceName(DMXLocalInputInfoPtr dmxLocal)
} }
switch (dmxLocal->type) { switch (dmxLocal->type) {
case DMX_LOCAL_KEYBOARD: XmuSnprintf(buf, LEN, "Keyboard%d", k++); break; case DMX_LOCAL_KEYBOARD: snprintf(buf, LEN, "Keyboard%d", k++); break;
case DMX_LOCAL_MOUSE: XmuSnprintf(buf, LEN, "Mouse%d", m++); break; case DMX_LOCAL_MOUSE: snprintf(buf, LEN, "Mouse%d", m++); break;
default: XmuSnprintf(buf, LEN, "Other%d", o++); break; default: snprintf(buf, LEN, "Other%d", o++); break;
} }
return buf; return buf;

View File

@ -430,10 +430,10 @@ static int kbdLinuxOpenVT(int vtno)
int fd = -1; int fd = -1;
int i; int i;
const char *vcs[] = { "/dev/vc/", "/dev/tty", NULL }; const char *vcs[] = { "/dev/vc/", "/dev/tty", NULL };
char name[64]; /* RATS: Only used in XmuSnprintf */ char name[64]; /* RATS: Only used in snprintf */
for (i = 0; vcs[i]; i++) { for (i = 0; vcs[i]; i++) {
XmuSnprintf(name, sizeof(name), "%s%d", vcs[i], vtno); snprintf(name, sizeof(name), "%s%d", vcs[i], vtno);
if ((fd = open(name, O_RDWR | O_NONBLOCK, 0)) >= 0) break; if ((fd = open(name, O_RDWR | O_NONBLOCK, 0)) >= 0) break;
} }
if (fd < 0) if (fd < 0)

View File

@ -272,7 +272,7 @@ device. */
void usbInit(DevicePtr pDev, usbType type) void usbInit(DevicePtr pDev, usbType type)
{ {
GETPRIV; GETPRIV;
char name[64]; /* RATS: Only used in XmuSnprintf */ char name[64]; /* RATS: Only used in snprintf */
int i, j, k; int i, j, k;
char buf[256] = { 0, }; /* RATS: Use ok */ char buf[256] = { 0, }; /* RATS: Use ok */
int version; int version;
@ -284,7 +284,7 @@ void usbInit(DevicePtr pDev, usbType type)
if (priv->fd >=0) return; if (priv->fd >=0) return;
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
XmuSnprintf(name, sizeof(name), "/dev/input/event%d", i); snprintf(name, sizeof(name), "/dev/input/event%d", i);
if ((priv->fd = open(name, O_RDWR | O_NONBLOCK, 0)) >= 0) { if ((priv->fd = open(name, O_RDWR | O_NONBLOCK, 0)) >= 0) {
ioctl(priv->fd, EVIOCGVERSION, &version); ioctl(priv->fd, EVIOCGVERSION, &version);
ioctl(priv->fd, EVIOCGNAME(sizeof(buf)), buf); ioctl(priv->fd, EVIOCGNAME(sizeof(buf)), buf);