[PATCH:xsm 1/2] Convert XtMalloc + sprintf to XtAsprintf
Alan Coopersmith
alan.coopersmith at oracle.com
Thu Jan 13 00:19:45 PST 2011
Depends on libXt > 1.0.99 to ensure XtAsprintf is available.
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
choose.c | 8 +++-----
configure.ac | 2 +-
info.c | 5 +----
save.c | 5 +----
xsm.c | 26 ++++++--------------------
5 files changed, 12 insertions(+), 34 deletions(-)
diff --git a/choose.c b/choose.c
index c2a0c34..b8cc946 100644
--- a/choose.c
+++ b/choose.c
@@ -145,6 +145,7 @@ GetSessionNames(int *count_ret, String **short_names_ret,
{
char *host = ((char *) strchr (id, '/')) + 1;
char *colon = (char *) strrchr (host, ':');
+ char *lockmsg;
/* backtrack over previous colon if there are 2 (DECnet),
but not three (IPv6) */
@@ -153,11 +154,8 @@ GetSessionNames(int *count_ret, String **short_names_ret,
*colon = '\0';
- (*long_names_ret)[*count_ret] =
- XtMalloc (strlen (name) + strlen (host) + 14);
-
- sprintf ((*long_names_ret)[*count_ret],
- "%s (locked at %s)", name, host);
+ XtAsprintf (&lockmsg, "%s (locked at %s)", name, host);
+ (*long_names_ret)[*count_ret] = lockmsg;
*colon = ':';
XtFree (id);
diff --git a/configure.ac b/configure.ac
index 8afe1f8..a2b2a1b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,7 +48,7 @@ AC_CHECK_FUNC([putenv], [],
AC_DEFINE(NOPUTENV,1,[Define to 1 if you DO NOT have the 'putenv' function.]))
# Checks for pkg-config packages
-PKG_CHECK_MODULES(XSM, x11 xt ice sm xaw7)
+PKG_CHECK_MODULES(XSM, [x11 xt > 1.0.99 ice sm xaw7])
xt_appdefaultdir=`$PKG_CONFIG --variable=appdefaultdir xt`
AC_ARG_WITH(appdefaultdir,
diff --git a/info.c b/info.c
index 728bbb3..2c51fd4 100644
--- a/info.c
+++ b/info.c
@@ -559,9 +559,6 @@ UpdateClientList(void)
else
hint = "";
- clientInfo = (String) XtMalloc (strlen (progName) +
- extra1 + extra2 + 3 + strlen (hostname) + 3 + strlen (hint) + 1);
-
for (k = 0; k < extra1; k++)
extraBuf1[k] = ' ';
extraBuf1[extra1] = '\0';
@@ -570,7 +567,7 @@ UpdateClientList(void)
extraBuf2[k] = ' ';
extraBuf2[extra2] = '\0';
- sprintf (clientInfo, "%s%s (%s%s) %s", progName, extraBuf1,
+ XtAsprintf (&clientInfo, "%s%s (%s%s) %s", progName, extraBuf1,
hostname, extraBuf2, hint);
clientListRecs[i] = client;
diff --git a/save.c b/save.c
index 1c40d72..3cb0c36 100644
--- a/save.c
+++ b/save.c
@@ -1314,9 +1314,6 @@ PopupBadSave(void)
extra1 = maxlen1 - strlen (progName) + 5;
extra2 = maxlen2 - strlen (hostname);
- clientInfo = (String) XtMalloc (strlen (progName) +
- extra1 + extra2 + 3 + strlen (hostname) + 1);
-
for (k = 0; k < extra1; k++)
extraBuf1[k] = ' ';
extraBuf1[extra1] = '\0';
@@ -1325,7 +1322,7 @@ PopupBadSave(void)
extraBuf2[k] = ' ';
extraBuf2[extra2] = '\0';
- sprintf (clientInfo, "%s%s (%s%s)", progName, extraBuf1,
+ XtAsprintf (&clientInfo, "%s%s (%s%s)", progName, extraBuf1,
hostname, extraBuf2);
failedNames[i++] = clientInfo;
diff --git a/xsm.c b/xsm.c
index 1d377bc..4de4075 100644
--- a/xsm.c
+++ b/xsm.c
@@ -257,9 +257,7 @@ main(int argc, char *argv[])
/* the sizeof includes the \0, so we don't need to count the '=' */
networkIds = IceComposeNetworkIdList (numTransports, listenObjs);
- p = (char *) XtMalloc((sizeof environment_name) + strlen(networkIds) + 1);
- if(!p) nomem();
- sprintf(p, "%s=%s", environment_name, networkIds);
+ XtAsprintf(&p, "%s=%s", environment_name, networkIds);
putenv(p);
if (cmd_line_display)
@@ -270,8 +268,7 @@ main(int argc, char *argv[])
* the session manager will run on the specified display.
*/
- p = (char *) XtMalloc(8 + strlen(cmd_line_display) + 1);
- sprintf(p, "DISPLAY=%s", cmd_line_display);
+ XtAsprintf(&p, "DISPLAY=%s", cmd_line_display);
putenv(p);
}
@@ -428,9 +425,7 @@ GetEnvironment(void)
display_env = NULL;
if((p = cmd_line_display) || (p = (char *) getenv(envDISPLAY))) {
- display_env = (char *) XtMalloc(strlen(envDISPLAY)+1+strlen(p)+1);
- if(!display_env) nomem();
- sprintf(display_env, "%s=%s", envDISPLAY, p);
+ XtAsprintf(&display_env, "%s=%s", envDISPLAY, p);
/*
* When we restart a remote client, we have to make sure the
@@ -457,21 +452,14 @@ GetEnvironment(void)
char hostnamebuf[256];
gethostname (hostnamebuf, sizeof hostnamebuf);
- non_local_display_env = (char *) XtMalloc (
- strlen (envDISPLAY) + 1 +
- strlen (hostnamebuf) + strlen (temp) + 1);
- if (!non_local_display_env) nomem();
- sprintf(non_local_display_env, "%s=%s%s",
+ XtAsprintf(&non_local_display_env, "%s=%s%s",
envDISPLAY, hostnamebuf, temp);
}
}
session_env = NULL;
if((p = (char *) getenv(envSESSION_MANAGER))) {
- session_env = (char *) XtMalloc(
- strlen(envSESSION_MANAGER)+1+strlen(p)+1);
- if(!session_env) nomem();
- sprintf(session_env, "%s=%s", envSESSION_MANAGER, p);
+ XtAsprintf(&session_env, "%s=%s", envSESSION_MANAGER, p);
/*
* When we restart a remote client, we have to make sure the
@@ -507,9 +495,7 @@ GetEnvironment(void)
audio_env = NULL;
if((p = (char *) getenv(envAUDIOSERVER))) {
- audio_env = (char *) XtMalloc(strlen(envAUDIOSERVER)+1+strlen(p)+1);
- if(!audio_env) nomem();
- sprintf(audio_env, "%s=%s", envAUDIOSERVER, p);
+ XtAsprintf(&audio_env, "%s=%s", envAUDIOSERVER, p);
}
}
--
1.7.3.2
More information about the xorg-devel
mailing list