Skip to content

Commit

Permalink
Convert existing Xprintf style calls to asprintf style
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Coopersmith <[email protected]>
Reviewed-by: Jeremy Huddleston <[email protected]>
Reviewed-by: Mikhail Gusarov <[email protected]>
  • Loading branch information
alanc committed Dec 7, 2010
1 parent c95c1d3 commit 03e8bfa
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 59 deletions.
4 changes: 3 additions & 1 deletion config/hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 8 additions & 6 deletions config/udev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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. "
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion dix/dixfonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions hw/xfree86/common/xf86AutoConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions hw/xfree86/common/xf86Config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions hw/xfree86/common/xf86Helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions hw/xfree86/modes/xf86Modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" : "");
}

/*
Expand Down
7 changes: 4 additions & 3 deletions hw/xwin/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,...)
Expand Down
5 changes: 2 additions & 3 deletions hw/xwin/windialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
24 changes: 15 additions & 9 deletions hw/xwin/winerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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,
Expand Down
43 changes: 27 additions & 16 deletions xkb/ddxList.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 11 additions & 8 deletions xkb/ddxLoad.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down

0 comments on commit 03e8bfa

Please sign in to comment.