[PATCH] Replace XmuSnprintf with snprintf.
Jamey Sharp
jamey at minilop.net
Sun Sep 18 18:57:16 PDT 2011
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 at bfs.de>
Signed-off-by: Jamey Sharp <jamey at minilop.net>
---
hw/dmx/config/xdmxconfig.c | 23 +++++++++++------------
hw/dmx/dmxclient.h | 1 -
hw/dmx/dmxinit.c | 11 ++++++-----
hw/dmx/dmxprop.c | 9 +++++----
hw/dmx/doc/dmx.xml | 2 +-
hw/dmx/examples/dmxwininfo.c | 3 +--
hw/dmx/input/dmxinputinit.c | 6 +++---
hw/dmx/input/lnx-keyboard.c | 4 ++--
hw/dmx/input/usb-common.c | 4 ++--
9 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/hw/dmx/config/xdmxconfig.c b/hw/dmx/config/xdmxconfig.c
index 2de7f2b..a153f09 100644
--- a/hw/dmx/config/xdmxconfig.c
+++ b/hw/dmx/config/xdmxconfig.c
@@ -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);
diff --git a/hw/dmx/dmxclient.h b/hw/dmx/dmxclient.h
index c45f71f..f0f235f 100644
--- a/hw/dmx/dmxclient.h
+++ b/hw/dmx/dmxclient.h
@@ -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>
diff --git a/hw/dmx/dmxinit.c b/hw/dmx/dmxinit.c
index bc1509b..165476c 100644
--- a/hw/dmx/dmxinit.c
+++ b/hw/dmx/dmxinit.c
@@ -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
}
diff --git a/hw/dmx/dmxprop.c b/hw/dmx/dmxprop.c
index d4618e3..b4695dd 100644
--- a/hw/dmx/dmxprop.c
+++ b/hw/dmx/dmxprop.c
@@ -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));
}
diff --git a/hw/dmx/doc/dmx.xml b/hw/dmx/doc/dmx.xml
index 8dbb7d8..ce472c2 100644
--- a/hw/dmx/doc/dmx.xml
+++ b/hw/dmx/doc/dmx.xml
@@ -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.
diff --git a/hw/dmx/examples/dmxwininfo.c b/hw/dmx/examples/dmxwininfo.c
index 6cf1d41..3d027d5 100644
--- a/hw/dmx/examples/dmxwininfo.c
+++ b/hw/dmx/examples/dmxwininfo.c
@@ -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,
diff --git a/hw/dmx/input/dmxinputinit.c b/hw/dmx/input/dmxinputinit.c
index 1b067c7..16ecae3 100644
--- a/hw/dmx/input/dmxinputinit.c
+++ b/hw/dmx/input/dmxinputinit.c
@@ -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;
diff --git a/hw/dmx/input/lnx-keyboard.c b/hw/dmx/input/lnx-keyboard.c
index 5b92f3b..06e9ec7 100644
--- a/hw/dmx/input/lnx-keyboard.c
+++ b/hw/dmx/input/lnx-keyboard.c
@@ -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)
diff --git a/hw/dmx/input/usb-common.c b/hw/dmx/input/usb-common.c
index 25479ae..944033e 100644
--- a/hw/dmx/input/usb-common.c
+++ b/hw/dmx/input/usb-common.c
@@ -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);
--
1.7.5.4
More information about the xorg-devel
mailing list