Convert existing Xprintf style calls to asprintf style

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
Reviewed-by: Mikhail Gusarov <dottedmag@dottedmag.net>
This commit is contained in:
Alan Coopersmith 2010-11-27 20:09:04 -08:00
parent c95c1d338f
commit 03e8bfa1d1
12 changed files with 88 additions and 59 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -1193,9 +1193,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 */

View File

@ -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" : "");
}
/*

View File

@ -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,...)

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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);