[PATCH 2/6 v2] Convert existing Xprintf style calls to Xasprintf style

Alan Coopersmith alan.coopersmith at oracle.com
Tue Nov 30 21:53:27 PST 2010


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 config/hal.c                       |    4 ++-
 config/udev.c                      |   14 ++++++-----
 dix/dixfonts.c                     |    4 ++-
 hw/xfree86/common/xf86AutoConfig.c |    4 +-
 hw/xfree86/common/xf86Config.c     |    7 ++---
 hw/xfree86/common/xf86Helper.c     |   10 ++++++--
 hw/xfree86/modes/xf86Modes.c       |    4 +-
 hw/xwin/win.h                      |    7 +++--
 hw/xwin/windialogs.c               |    5 +--
 hw/xwin/winerror.c                 |   23 +++++++++++-------
 xkb/ddxList.c                      |   43 ++++++++++++++++++++++-------------
 xkb/ddxLoad.c                      |    8 ++++--
 12 files changed, 80 insertions(+), 53 deletions(-)

diff --git a/config/hal.c b/config/hal.c
index 6e2850c..cd16f8b 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -200,7 +200,9 @@ device_added(LibHalContext *hal_ctx, const char *udi)
                        "config/hal: getting usb.product_id on %s "
                        "returned %04x\n", parent, usb_product);
         if (usb_vendor && usb_product)
-            attrs.usb_id = Xprintf("%04x:%04x", usb_vendor, usb_product);
+            if (Xasprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_product)
+		== -1)
+		attrs.usb_id = NULL;
 
         free(parent);
     }
diff --git a/config/udev.c b/config/udev.c
index 31f4f80..7f41e09 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -108,8 +108,10 @@ device_added(struct udev_device *udev_device)
 
         /* construct USB ID in lowercase hex - "0000:ffff" */
         if (product && sscanf(product, "%*x/%4x/%4x/%*x", &usb_vendor, &usb_model) == 2) {
-            attrs.usb_id = Xprintf("%04x:%04x", usb_vendor, usb_model);
-            if (attrs.usb_id)
+            if (Xasprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_model)
+                == -1)
+                attrs.usb_id = NULL;
+            else
                 LOG_PROPERTY(path, "PRODUCT", product);
         }
     }
@@ -127,9 +129,10 @@ device_added(struct udev_device *udev_device)
     LOG_PROPERTY(path, "ID_INPUT.tags", tags_prop);
     attrs.tags = xstrtokenize(tags_prop, ",");
 
-    config_info = Xprintf("udev:%s", syspath);
-    if (!config_info)
+    if (Xasprintf(&config_info, "udev:%s", syspath) == -1) {
+        config_info = NULL;
         goto unwind;
+    }
 
     if (device_is_duplicate(config_info)) {
         LogMessage(X_WARNING, "config/udev: device %s already added. "
@@ -217,8 +220,7 @@ device_removed(struct udev_device *device)
     char *value;
     const char *syspath = udev_device_get_syspath(device);
 
-    value = Xprintf("udev:%s", syspath);
-    if (!value)
+    if (Xasprintf(&value, "udev:%s", syspath) == -1)
         return;
 
     remove_devices("udev", value);
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index ccb4627..15ee982 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -1817,7 +1817,9 @@ SetDefaultFontPath(char *path)
 	start = end;
     }
     if (!start) {
-	temp_path = Xprintf("%s%sbuilt-ins", path, *path ? "," : "");
+	if (Xasprintf(&temp_path, "%s%sbuilt-ins", path, *path ? "," : "")
+	    == -1)
+	    temp_path = NULL;
     } else {
 	temp_path = strdup(path);
     }
diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
index 3cd5ef6..4f7d7ed 100644
--- a/hw/xfree86/common/xf86AutoConfig.c
+++ b/hw/xfree86/common/xf86AutoConfig.c
@@ -297,8 +297,8 @@ copyScreen(confScreenPtr oscreen, GDevPtr odev, int i, char *driver)
     }
     memcpy(cptr, odev, sizeof(GDevRec));
 
-    cptr->identifier = Xprintf("Autoconfigured Video Device %s", driver);
-    if (!cptr->identifier) {
+    if (Xasprintf(&cptr->identifier, "Autoconfigured Video Device %s", driver)
+        == -1) {
         free(cptr);
         free(nscreen);
         return FALSE;
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 5800700..a1419d1 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -585,10 +585,9 @@ configFiles(XF86ConfFilesPtr fileconf)
     else if (fileconf && fileconf->file_fontpath) {
 	pathFrom = X_CONFIG;
 	if (xf86Info.useDefaultFontPath) {
-	    defaultFontPath = Xprintf("%s%s%s",
-				      fileconf->file_fontpath,
-				      *temp_path ? "," : "", temp_path);
-	    if (defaultFontPath != NULL) {
+	    if (Xasprintf(&defaultFontPath, "%s%s%s", fileconf->file_fontpath,
+			  *temp_path ? "," : "", temp_path) == -1) {
+		defaultFontPath = NULL;
 		must_copy = FALSE;
 	    }
 	}
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index ea0acbf..a28cc99 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1189,9 +1189,13 @@ xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, const char *forma
 {
     char *msg;
 
-    msg = Xprintf("%s: %s: %s", dev->drv->driverName, dev->name, format);
-    LogVMessageVerb(type, verb, msg, args);
-    free(msg);
+    if (Xasprintf(&msg, "%s: %s: %s", dev->drv->driverName, dev->name, format)
+	== -1) {
+	LogVMessageVerb(type, verb, "%s", args);
+    } else {
+	LogVMessageVerb(type, verb, msg, args);
+	free(msg);
+    }
 }
 
 /* Print input driver message, with verbose level specified directly */
diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c
index 51eb4c9..75584cf 100644
--- a/hw/xfree86/modes/xf86Modes.c
+++ b/hw/xfree86/modes/xf86Modes.c
@@ -132,8 +132,8 @@ xf86SetModeDefaultName(DisplayModePtr mode)
 
     free(mode->name);
 
-    mode->name = XNFprintf("%dx%d%s", mode->HDisplay, mode->VDisplay,
-			   interlaced ? "i" : "");
+    XNFasprintf(&mode->name, "%dx%d%s", mode->HDisplay, mode->VDisplay,
+		interlaced ? "i" : "");
 }
 
 /*
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index f22a2d5..7a392bf 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -221,9 +221,10 @@ if (fDebugProcMsg) \
 { \
   char *pszTemp; \
   int iLength; \
-  pszTemp = Xprintf (str, ##__VA_ARGS__); \
-  MessageBox (NULL, pszTemp, szFunctionName, MB_OK); \
-  free(pszTemp); \
+  if (Xasprintf (&pszTemp, str, ##__VA_ARGS__) != -1) { \
+    MessageBox (NULL, pszTemp, szFunctionName, MB_OK); \
+    free (pszTemp); \
+  } \
 }
 #else
 #define DEBUG_MSG(str,...)
diff --git a/hw/xwin/windialogs.c b/hw/xwin/windialogs.c
index 22d8cd7..87f2bb0 100644
--- a/hw/xwin/windialogs.c
+++ b/hw/xwin/windialogs.c
@@ -341,11 +341,10 @@ winExitDlgProc (HWND hDialog, UINT message,
 	winInitDialog (hDialog);
 
 	/* Format the connected clients string */
-	pszConnectedClients = Xprintf (CONNECTED_CLIENTS_FORMAT,
+	if (Xasprintf (&pszConnectedClients, CONNECTED_CLIENTS_FORMAT,
            (s_pScreenPriv->iConnectedClients == 1) ? "is" : "are",
             s_pScreenPriv->iConnectedClients,
-           (s_pScreenPriv->iConnectedClients == 1) ? "" : "s");
-	if (!pszConnectedClients)
+           (s_pScreenPriv->iConnectedClients == 1) ? "" : "s") == -1)
 	    return TRUE;
      
         
diff --git a/hw/xwin/winerror.c b/hw/xwin/winerror.c
index aadfd28..8823537 100644
--- a/hw/xwin/winerror.c
+++ b/hw/xwin/winerror.c
@@ -101,12 +101,15 @@ winMessageBoxF (const char *pszError, UINT uType, ...)
   char *	pszErrorF = NULL;
   char *	pszMsgBox = NULL;
   va_list	args;
+  int		size;
 
   va_start(args, uType);
-  pszErrorF = Xvprintf(pszError, args);
+  size = Xvasprintf (&pszErrorF, pszError, args);
   va_end(args);
-  if (!pszErrorF)
+  if (size == -1) {
+    pszErrorF = NULL;
     goto winMessageBoxF_Cleanup;
+  }
 
 #define MESSAGEBOXF \
 	"%s\n" \
@@ -117,15 +120,17 @@ winMessageBoxF (const char *pszError, UINT uType, ...)
 	"XWin was started with the following command-line:\n\n" \
 	"%s\n"
 
-  pszMsgBox = Xprintf (MESSAGEBOXF,
-                       pszErrorF, XVENDORNAME,
-		       XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, XORG_VERSION_SNAP, XORG_VERSION_CURRENT,
-		       BUILDERADDR,
-		       BUILDERSTRING,
-		       g_pszCommandLine);
+  size = Xasprintf (&pszMsgBox, MESSAGEBOXF,
+                    pszErrorF, XVENDORNAME,
+                    XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, XORG_VERSION_SNAP, XORG_VERSION_CURRENT,
+                    BUILDERADDR,
+                    BUILDERSTRING,
+                    g_pszCommandLine);
 
-  if (!pszMsgBox)
+  if (size == -1) {
+    pszMsgBox = NULL;
     goto winMessageBoxF_Cleanup;
+  }
 
   /* Display the message box string */
   MessageBox (NULL,
diff --git a/xkb/ddxList.c b/xkb/ddxList.c
index c1ada5c..b729959 100644
--- a/xkb/ddxList.c
+++ b/xkb/ddxList.c
@@ -156,34 +156,45 @@ char	tmpname[PATH_MAX];
 #endif
     if (XkbBaseDirectory!=NULL) {
 	if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
-	    buf = Xprintf("%s/%s.dir",XkbBaseDirectory,componentDirs[what]);
-	    in= fopen(buf,"r");
+	    if (Xasprintf(&buf, "%s/%s.dir", XkbBaseDirectory,
+			  componentDirs[what]) == -1)
+		buf = NULL;
+	    else
+		in = fopen(buf,"r");
 	}
 	if (!in) {
 	    haveDir= FALSE;
 	    free(buf);
-	    buf = Xprintf(
-		"'%s/xkbcomp' '-R%s/%s' -w %ld -l -vlfhpR '%s'" W32_tmparg,
-                XkbBinDirectory,XkbBaseDirectory,componentDirs[what],(long)
-		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
-		file W32_tmpfile
-                );
+	    if (Xasprintf
+		(&buf,
+		 "'%s/xkbcomp' '-R%s/%s' -w %ld -l -vlfhpR '%s'" W32_tmparg,
+		 XkbBinDirectory, XkbBaseDirectory, componentDirs[what],
+		 (long) ((xkbDebugFlags < 2) ? 1 :
+			 ((xkbDebugFlags>10) ? 10 : xkbDebugFlags)),
+		 file W32_tmpfile
+		    ) == -1)
+		buf = NULL;
 	}
     }
     else {
 	if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
-	    buf = Xprintf("%s.dir",componentDirs[what]);
-	    in= fopen(buf,"r");
+	    if (Xasprintf(&buf, "%s.dir", componentDirs[what]) == -1)
+		buf = NULL;
+	    else
+		in = fopen(buf,"r");
 	}
 	if (!in) {
 	    haveDir= FALSE;
 	    free(buf);
-	    buf = Xprintf(
-		"xkbcomp -R%s -w %ld -l -vlfhpR '%s'" W32_tmparg,
-                componentDirs[what],(long)
-		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
-		file W32_tmpfile
-                );
+	    if (Xasprintf
+		(&buf,
+		 "xkbcomp -R%s -w %ld -l -vlfhpR '%s'" W32_tmparg,
+		 componentDirs[what],
+		 (long)	((xkbDebugFlags < 2) ? 1 :
+			 ((xkbDebugFlags > 10) ? 10 : xkbDebugFlags)),
+		 file W32_tmpfile
+		    ) == -1)
+		buf = NULL;
 	}
     }
     status= Success;
diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index cfc6198..f484cae 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -210,7 +210,8 @@ XkbDDXCompileKeymapByNames(	XkbDescPtr		xkb,
 #endif
 
     if (XkbBaseDirectory != NULL) {
-	xkbbasedirflag = Xprintf("\"-R%s\"", XkbBaseDirectory);
+	if (Xasprintf(&xkbbasedirflag, "\"-R%s\"", XkbBaseDirectory) == -1)
+	    xkbbasedirflag = NULL;
     }
 
     if (XkbBinDirectory != NULL) {
@@ -225,14 +226,15 @@ XkbDDXCompileKeymapByNames(	XkbDescPtr		xkb,
 	}
     }
 
-    buf = Xprintf("\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" "
+    if (Xasprintf(&buf, "\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" "
 		  "-em1 %s -emp %s -eml %s \"%s%s.xkm\"",
 		  xkbbindir, xkbbindirsep,
 		  ( (xkbDebugFlags < 2) ? 1 :
 		    ((xkbDebugFlags > 10) ? 10 : (int)xkbDebugFlags) ),
 		  xkbbasedirflag ? xkbbasedirflag : "", xkmfile,
 		  PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1,
-		  xkm_output_dir, keymap);
+		  xkm_output_dir, keymap) == -1)
+	buf = NULL;
 
     free(xkbbasedirflag);
 
-- 
1.7.3.2



More information about the xorg-devel mailing list