summaryrefslogtreecommitdiff
authorPeter Hutterer <peter.hutterer@who-t.net>2009-04-16 06:17:07 (GMT)
committer Peter Hutterer <peter.hutterer@who-t.net>2009-04-19 12:20:18 (GMT)
commit0e0642ee9466d3268476d0084a83a9d93a4aa555 (patch) (side-by-side diff)
tree990120737140491870bf3da6b8bdcc1894baa1e2
parent62d2fb68638e9f2aa3c1d72027619c4d38f5b812 (diff)
downloadxserver-0e0642ee9466d3268476d0084a83a9d93a4aa555.zip
xserver-0e0642ee9466d3268476d0084a83a9d93a4aa555.tar.gz
os: don't malloc memory in LogVMessageVerb.
LogVWrite is limited to a buffer size of 1024, so we don't loose anything here by truncating. This way we can use LogVMessageVerb (and xf86Msg and friends) during signal handlers with the normal message types. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Acked-by: Alan Coopersmith <alan.coopersmith@sun.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--os/log.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/os/log.c b/os/log.c
index 3961b0b..8108890 100644
--- a/os/log.c
+++ b/os/log.c
@@ -316,7 +316,7 @@ void
LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
{
const char *s = X_UNKNOWN_STRING;
- char *tmpBuf = NULL;
+ char tmpBuf[1024];
/* Ignore verbosity for X_ERROR */
if (logVerbosity >= verb || logFileVerbosity >= verb || type == X_ERROR) {
@@ -358,21 +358,11 @@ LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
break;
}
- /*
- * Prefix the format string with the message type. We do it this way
- * so that LogVWrite() is only called once per message.
- */
- if (s) {
- tmpBuf = malloc(strlen(format) + strlen(s) + 1 + 1);
- /* Silently return if malloc fails here. */
- if (!tmpBuf)
- return;
- sprintf(tmpBuf, "%s ", s);
- strcat(tmpBuf, format);
- LogVWrite(verb, tmpBuf, args);
- free(tmpBuf);
- } else
- LogVWrite(verb, format, args);
+ /* if s is not NULL we need a space before format */
+ snprintf(tmpBuf, sizeof(tmpBuf), "%s%s%s", s ? s : "",
+ s ? " " : "",
+ format);
+ LogVWrite(verb, tmpBuf, args);
}
}