From 5d6730c2e40cf191b4ca1f1c096dcd3f8491d1b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Mon, 17 Oct 2011 14:42:46 +0200
Subject: [PATCH] Fixes debug-tests.c coverity issues: NEGATIVE_RETURNS,
 FORWARD_NULL

https://fedorahosted.org/sssd/ticket/1046
---
 src/tests/debug-tests.c |   49 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/src/tests/debug-tests.c b/src/tests/debug-tests.c
index cded13f..8b1c35c 100644
--- a/src/tests/debug-tests.c
+++ b/src/tests/debug-tests.c
@@ -218,8 +218,17 @@ int test_helper_debug_check_message(int level, int msgmode)
         DEBUG_MSG(level, __FUNCTION__, "some error");
     }
 
-    fseek(file, 0, SEEK_END);
+    ret = fseek(file, 0, SEEK_END);
+    if (ret == -1) {
+        ret = errno;
+        goto done;
+    }
+
     filesize = ftell(file);
+    if (filesize == -1) {
+        ret = errno;
+        goto done;
+    }
 
     rewind(file);
 
@@ -296,7 +305,9 @@ int test_helper_debug_check_message(int level, int msgmode)
 
 done:
     talloc_free(ctx);
-    fclose(file);
+    if (file != NULL) {
+        fclose(file);
+    }
     remove(filename);
     return ret;
 }
@@ -332,13 +343,25 @@ int test_helper_debug_is_empty_message(int level, int msgmode)
     } else {
         DEBUG_MSG(level, __FUNCTION__, "some error");
     }
-    fseek(file, 0, SEEK_END);
+
+    ret = fseek(file, 0, SEEK_END);
+    if (ret == -1) {
+        ret = errno;
+        goto done;
+    }
+
     filesize = ftell(file);
+    if (filesize == -1) {
+        ret = errno;
+        goto done;
+    }
 
     ret = filesize == 0 ? EOK : DEBUG_TEST_NOK;
 
 done:
-    fclose(file);
+    if (file != NULL) {
+        fclose(file);
+    }
     remove(filename);
     return ret;
 }
@@ -370,8 +393,10 @@ START_TEST(test_debug_is_set_single_no_timestamp)
         debug_level = levels[i];
         result = test_helper_debug_check_message(levels[i], 0);
 
-        error_msg = strerror(result);
-        fail_unless(result == EOK || result == DEBUG_TEST_NOK || result == DEBUG_TEST_NOK_TS, error_msg);
+        if (result != EOK && result != DEBUG_TEST_NOK && result != DEBUG_TEST_NOK_TS) {
+            error_msg = strerror(result);
+            fail(error_msg);
+        }
 
         char *msg = NULL;
         msg = talloc_asprintf(NULL, "Test of level %#.4x failed - message don't match", levels[i]);
@@ -408,8 +433,10 @@ START_TEST(test_debug_is_set_single_timestamp)
         debug_level = levels[i];
         result = test_helper_debug_check_message(levels[i], 0);
 
-        error_msg = strerror(result);
-        fail_unless(result == EOK || result == DEBUG_TEST_NOK || result == DEBUG_TEST_NOK_TS, error_msg);
+        if (result != EOK && result != DEBUG_TEST_NOK && result != DEBUG_TEST_NOK_TS) {
+            error_msg = strerror(result);
+            fail(error_msg);
+        }
 
         char *msg = NULL;
 
@@ -451,8 +478,10 @@ START_TEST(test_debug_is_set_single_timestamp_microseconds)
         debug_level = levels[i];
         result = test_helper_debug_check_message(levels[i], 0);
 
-        error_msg = strerror(result);
-        fail_unless(result == EOK || result == DEBUG_TEST_NOK || result == DEBUG_TEST_NOK_TS, error_msg);
+        if (result != EOK && result != DEBUG_TEST_NOK && result != DEBUG_TEST_NOK_TS) {
+            error_msg = strerror(result);
+            fail(error_msg);
+        }
 
         char *msg = NULL;
 
-- 
1.7.6.4
