[PATCH:libXt 4/4 v2] Convert some sprintf calls to snprintf

Alan Coopersmith alan.coopersmith at oracle.com
Tue Dec 21 19:15:36 PST 2010


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/Selection.c |    2 +-
 src/Shell.c     |    5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

Amended as suggested by walter harms to incorporate constant string
directly in format string.

diff --git a/src/Selection.c b/src/Selection.c
index 1759c02..101ea6a 100644
--- a/src/Selection.c
+++ b/src/Selection.c
@@ -226,7 +226,7 @@ static Atom GetSelectionProperty(
  propCount = sarray->propCount++;
  sarray->list = (SelectionProp) XtRealloc((XtPointer)sarray->list,
   		(unsigned)(sarray->propCount*sizeof(SelectionPropRec)));
- (void) sprintf(propname, "%s%d", "_XT_SELECTION_", propCount);
+ (void) snprintf(propname, sizeof(propname), "_XT_SELECTION_%d", propCount);
  sarray->list[propCount].prop = XInternAtom(dpy, propname, FALSE);
  sarray->list[propCount].avail = FALSE;
  return(sarray->list[propCount].prop);
diff --git a/src/Shell.c b/src/Shell.c
index 732e978..ef6dad2 100644
--- a/src/Shell.c
+++ b/src/Shell.c
@@ -1780,7 +1780,8 @@ static void GetGeometry(
 	}
 	else hints.flags = 0;
 
-	sprintf( def_geom, "%dx%d+%d+%d", width, height, x, y );
+	snprintf( def_geom, sizeof(def_geom), "%dx%d+%d+%d",
+		  width, height, x, y );
 	flag = XWMGeometry( XtDisplay(W),
 			    XScreenNumberOfScreen(XtScreen(W)),
 			    w->shell.geometry, def_geom,
@@ -3013,7 +3014,7 @@ static void SetSessionProperties(
 	user_name = _XtGetUserName(nam_buf, sizeof nam_buf);
 	if (user_name)
 	    props[num_props++] = ArrayPack(SmUserID, &user_name);
-	sprintf(pid, "%ld", (long)getpid());
+	snprintf(pid, sizeof(pid), "%ld", (long)getpid());
 	props[num_props++] = ArrayPack(SmProcessID, &pidp);
 
 	if (num_props) {
-- 
1.7.3.2



More information about the xorg-devel mailing list