[PATCH 3/7] Convert existing Xprintf style calls to asprintf style

Jeremy Huddleston jeremyhu at apple.com
Fri Dec 3 22:40:54 PST 2010


Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

On Dec 3, 2010, at 21:09, Alan Coopersmith wrote:

> 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     |    9 +++----
> 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                 |   24 ++++++++++++-------
> xkb/ddxList.c                      |   43 ++++++++++++++++++++++-------------
> xkb/ddxLoad.c                      |   19 +++++++++------
> 12 files changed, 88 insertions(+), 59 deletions(-)
> 
> diff --git a/config/hal.c b/config/hal.c
> index 6e2850c..5e35911 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 (asprintf(&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..496bfbf 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 (asprintf(&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 (asprintf(&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 (asprintf(&value, "udev:%s", syspath) == -1)
>         return;
> 
>     remove_devices("udev", value);
> diff --git a/dix/dixfonts.c b/dix/dixfonts.c
> index ccb4627..bd1ad30 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 (asprintf(&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..eb61f87 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 (asprintf(&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..94300c2 100644
> --- a/hw/xfree86/common/xf86Config.c
> +++ b/hw/xfree86/common/xf86Config.c
> @@ -585,12 +585,11 @@ 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 (asprintf(&defaultFontPath, "%s%s%s", fileconf->file_fontpath,
> +			 *temp_path ? "," : "", temp_path) == -1)
> +		defaultFontPath = NULL;
> +	    else
> 		must_copy = FALSE;
> -	    }
> 	}
> 	else
> 	    defaultFontPath = fileconf->file_fontpath;
> diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
> index ea0acbf..30185c8 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 (asprintf(&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..4430781 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 (asprintf (&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..679b3fa 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 (asprintf (&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..5e32d09 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 = vasprintf (&pszErrorF, pszError, args);
>   va_end(args);
> -  if (!pszErrorF)
> +  if (size == -1) {
> +    pszErrorF = NULL;
>     goto winMessageBoxF_Cleanup;
> +  }
> 
> #define MESSAGEBOXF \
> 	"%s\n" \
> @@ -117,15 +120,18 @@ 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 = asprintf (&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..9623cb6 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 (asprintf(&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 (asprintf
> +		(&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 (asprintf(&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 (asprintf
> +		(&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..e6904a5 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 (asprintf(&xkbbasedirflag, "\"-R%s\"", XkbBaseDirectory) == -1)
> +	    xkbbasedirflag = NULL;
>     }
> 
>     if (XkbBinDirectory != NULL) {
> @@ -225,14 +226,16 @@ XkbDDXCompileKeymapByNames(	XkbDescPtr		xkb,
> 	}
>     }
> 
> -    buf = Xprintf("\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" "
> +    if (asprintf(&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);
> +		 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) == -1)
> +	buf = NULL;
> 
>     free(xkbbasedirflag);
> 
> -- 
> 1.7.3.2
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel



More information about the xorg-devel mailing list