aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/os/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/os/log.c')
-rw-r--r--xorg-server/os/log.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/xorg-server/os/log.c b/xorg-server/os/log.c
index 2495b9066..adcf16244 100644
--- a/xorg-server/os/log.c
+++ b/xorg-server/os/log.c
@@ -177,10 +177,8 @@ LogInit(const char *fname, const char *backup)
char *logFileName = NULL;
if (fname && *fname) {
- logFileName = malloc(strlen(fname) + strlen(display) + 1);
- if (!logFileName)
+ if (asprintf(&logFileName, fname, display) == -1)
FatalError("Cannot allocate space for the log file name\n");
- sprintf(logFileName, fname, display);
if (backup && *backup) {
struct stat buf;
@@ -189,13 +187,9 @@ LogInit(const char *fname, const char *backup)
char *suffix;
char *oldLog;
- oldLog = malloc(strlen(logFileName) + strlen(backup) +
- strlen(display) + 1);
- suffix = malloc(strlen(backup) + strlen(display) + 1);
- if (!oldLog || !suffix)
+ if ((asprintf(&suffix, backup, display) == -1) ||
+ (asprintf(&oldLog, "%s%s", logFileName, suffix) == -1))
FatalError("Cannot allocate space for the log file name\n");
- sprintf(suffix, backup, display);
- sprintf(oldLog, "%s%s", logFileName, suffix);
free(suffix);
if (rename(logFileName, oldLog) == -1) {
FatalError("Cannot move old log file \"%s\" to \"%s\"\n",