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

View File

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

View File

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

View File

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

View File

@ -3392,7 +3392,7 @@ Unrepaired warnings are as follows:
<orderedlist>
<listitem><para>
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
config/xdmxconfig.c (which is not part of the Xdmx server) and
input/usb-common.c.

View File

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

View File

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

View File

@ -430,10 +430,10 @@ static int kbdLinuxOpenVT(int vtno)
int fd = -1;
int i;
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++) {
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 < 0)

View File

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