xkbcomp: Don't segfault if the debug files aren't set
authorDan Nicholson <dbn.lists@gmail.com>
Sat, 4 Apr 2009 04:16:56 +0000 (21:16 -0700)
committerDan Nicholson <dbn.lists@gmail.com>
Sat, 4 Apr 2009 04:17:52 +0000 (21:17 -0700)
Another interface that needs to be cleaned up.

src/xkbcomp/utils.c

index 55efbe1..34ba8e0 100644 (file)
@@ -120,6 +120,9 @@ uEntry(int l, char *s, ...)
     int i;
     va_list args;
 
+    if (!entryFile)
+        return;
+
     for (i = 0; i < uEntryLevel; i++)
     {
         putc(' ', entryFile);
@@ -135,6 +138,9 @@ uExit(int l, char *rtVal)
 {
     int i;
 
+    if (!entryFile)
+        return;
+
     uEntryLevel -= l;
     if (uEntryLevel < 0)
         uEntryLevel = 0;
@@ -180,6 +186,9 @@ uDebug(char *s, ...)
     int i;
     va_list args;
 
+    if (!uDebugFile)
+        return;
+
     for (i = (uDebugIndentLevel * uDebugIndentSize); i > 0; i--)
     {
         putc(' ', uDebugFile);
@@ -195,6 +204,9 @@ uDebugNOI(char *s, ...)
 {
     va_list args;
 
+    if (!uDebugFile)
+        return;
+
     va_start(args, s);
     vfprintf(uDebugFile, s, args);
     va_end(args);
@@ -234,6 +246,9 @@ uInformation(const char *s, ...)
 {
     va_list args;
 
+    if (!errorFile)
+        return;
+
     va_start(args, s);
     vfprintf(errorFile, s, args);
     va_end(args);
@@ -247,6 +262,9 @@ uAction(const char *s, ...)
 {
     va_list args;
 
+    if (!errorFile)
+        return;
+
     if (prefix != NULL)
         fprintf(errorFile, "%s", prefix);
     fprintf(errorFile, "                  ");
@@ -263,6 +281,9 @@ uWarning(const char *s, ...)
 {
     va_list args;
 
+    if (!errorFile)
+        return;
+
     if ((outCount == 0) && (preMsg != NULL))
         fprintf(errorFile, "%s\n", preMsg);
     if (prefix != NULL)
@@ -282,6 +303,9 @@ uError(const char *s, ...)
 {
     va_list args;
 
+    if (!errorFile)
+        return;
+
     if ((outCount == 0) && (preMsg != NULL))
         fprintf(errorFile, "%s\n", preMsg);
     if (prefix != NULL)
@@ -301,6 +325,9 @@ uFatalError(const char *s, ...)
 {
     va_list args;
 
+    if (!errorFile)
+        return;
+
     if ((outCount == 0) && (preMsg != NULL))
         fprintf(errorFile, "%s\n", preMsg);
     if (prefix != NULL)
@@ -323,6 +350,9 @@ uInternalError(const char *s, ...)
 {
     va_list args;
 
+    if (!errorFile)
+        return;
+
     if ((outCount == 0) && (preMsg != NULL))
         fprintf(errorFile, "%s\n", preMsg);
     if (prefix != NULL)
@@ -360,7 +390,7 @@ uSetErrorPrefix(char *pre)
 void
 uFinishUp(void)
 {
-    if ((outCount > 0) && (postMsg != NULL))
+    if (errorFile && (outCount > 0) && (postMsg != NULL))
         fprintf(errorFile, "%s\n", postMsg);
     return;
 }