diff options
Diffstat (limited to 'xorg-server/os/log.c')
-rw-r--r-- | xorg-server/os/log.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/xorg-server/os/log.c b/xorg-server/os/log.c index ee231a31d..8d4dfc4ec 100644 --- a/xorg-server/os/log.c +++ b/xorg-server/os/log.c @@ -183,10 +183,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;
@@ -195,13 +193,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",
|