sssd/0002-DEBUG-TESTS-Fix-warnings-format-not-a-string-literal.patch

294 lines
10 KiB
Diff
Raw Normal View History

From cb9ad222358a84e2b2ea148c2950c2389f81de2c Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn@redhat.com>
Date: Mon, 27 Jul 2020 04:01:19 +0000
Subject: [PATCH] DEBUG-TESTS: Fix warnings format not a string literal and no
format arguments
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
e.g.
src/tests/resolv-tests.c: In function test_timeout:
src/tests/resolv-tests.c:942:5: error: format not a string literal and no format arguments [-Werror=format-security]
942 | ck_leaks_pop(tmp_ctx);
|
src/tests/debug-tests.c:413:9: error: format not a string literal and no format arguments [-Werror=format-security]
413 | fail_if(result == DEBUG_TEST_NOK_TS, msg);
| ^~~~~~~
src/tests/debug-tests.c: In function test_debug_is_notset_timestamp_microseconds_fn:
src/tests/debug-tests.c:603:13: error: format not a string literal and no format arguments [-Werror=format-security]
603 | fail(error_msg);
|
src/tests/debug-tests.c: In function test_debug_is_set_false_fn:
src/tests/debug-tests.c:671:9: error: format not a string literal and no format arguments [-Werror=format-security]
671 | fail_unless(result == 0, msg);
|
---
src/tests/common_check.h | 2 +-
src/tests/debug-tests.c | 128 +++++++++++++++------------------------
2 files changed, 49 insertions(+), 81 deletions(-)
diff --git a/src/tests/common_check.h b/src/tests/common_check.h
index 51c3c3f49..ac92d0a74 100644
--- a/src/tests/common_check.h
+++ b/src/tests/common_check.h
@@ -31,6 +31,6 @@ void ck_leak_check_setup(void);
void ck_leak_check_teardown(void);
#define ck_leaks_push(ctx) check_leaks_push(ctx)
-#define ck_leaks_pop(ctx) fail_unless(check_leaks_pop(ctx) == true, check_leaks_err_msg())
+#define ck_leaks_pop(ctx) fail_unless(check_leaks_pop(ctx) == true, "%s", check_leaks_err_msg())
#endif /* __TESTS_COMMON_CHECK_H__ */
diff --git a/src/tests/debug-tests.c b/src/tests/debug-tests.c
index 1e78f506e..092ccf684 100644
--- a/src/tests/debug-tests.c
+++ b/src/tests/debug-tests.c
@@ -55,10 +55,8 @@ START_TEST(test_debug_convert_old_level_old_format)
for (old_level = 0; old_level < N_ELEMENTS(levels); old_level++) {
expected_level |= levels[old_level];
- char *msg = NULL;
- msg = talloc_asprintf(NULL, "Invalid conversion of %d", old_level);
- fail_unless(debug_convert_old_level(old_level) == expected_level, msg);
- talloc_free(msg);
+ fail_unless(debug_convert_old_level(old_level) == expected_level,
+ "Invalid conversion of %d", old_level);
}
}
END_TEST
@@ -343,7 +341,6 @@ START_TEST(test_debug_is_set_single_no_timestamp)
SSSDBG_TRACE_ALL,
SSSDBG_TRACE_LDB
};
- char *error_msg;
debug_timestamps = 0;
debug_microseconds = 0;
@@ -357,15 +354,13 @@ START_TEST(test_debug_is_set_single_no_timestamp)
errno = 0;
result = test_helper_debug_check_message(levels[i]);
- if (result == DEBUG_TEST_ERROR) {
- error_msg = strerror(errno);
- fail(error_msg);
- }
+ fail_if(result == DEBUG_TEST_ERROR,
+ "Expecting DEBUG_TEST_ERROR, got: %d, error: %s",
+ result, strerror(errno));
- char *msg = NULL;
- msg = talloc_asprintf(NULL, "Test of level %#.4x failed - message don't match", levels[i]);
- fail_unless(result == EOK, msg);
- talloc_free(msg);
+ fail_unless(result == EOK,
+ "Test of level %#.4x failed - message don't match",
+ levels[i]);
}
}
END_TEST
@@ -387,7 +382,6 @@ START_TEST(test_debug_is_set_single_timestamp)
SSSDBG_TRACE_ALL,
SSSDBG_TRACE_LDB
};
- char *error_msg;
debug_timestamps = 1;
debug_microseconds = 0;
@@ -402,20 +396,16 @@ START_TEST(test_debug_is_set_single_timestamp)
errno = 0;
result = test_helper_debug_check_message(levels[i]);
- if (result == DEBUG_TEST_ERROR) {
- error_msg = strerror(errno);
- fail(error_msg);
- }
-
- char *msg = NULL;
+ fail_if(result == DEBUG_TEST_ERROR,
+ "Expecting DEBUG_TEST_ERROR, got: %d, error: %s",
+ result, strerror(errno));
- msg = talloc_asprintf(NULL, "Test of level %#.4x failed - invalid timestamp", levels[i]);
- fail_if(result == DEBUG_TEST_NOK_TS, msg);
- talloc_free(msg);
+ fail_if(result == DEBUG_TEST_NOK_TS,
+ "Test of level %#.4x failed - invalid timestamp", levels[i]);
- msg = talloc_asprintf(NULL, "Test of level %#.4x failed - message don't match", levels[i]);
- fail_unless(result == EOK, msg);
- talloc_free(msg);
+ fail_unless(result == EOK,
+ "Test of level %#.4x failed - message don't match",
+ levels[i]);
}
}
END_TEST
@@ -437,7 +427,6 @@ START_TEST(test_debug_is_set_single_timestamp_microseconds)
SSSDBG_TRACE_ALL,
SSSDBG_TRACE_LDB
};
- char *error_msg;
debug_timestamps = 1;
debug_microseconds = 1;
@@ -452,20 +441,16 @@ START_TEST(test_debug_is_set_single_timestamp_microseconds)
errno = 0;
result = test_helper_debug_check_message(levels[i]);
- if (result == DEBUG_TEST_ERROR) {
- error_msg = strerror(errno);
- fail(error_msg);
- }
-
- char *msg = NULL;
+ fail_if(result == DEBUG_TEST_ERROR,
+ "Expecting DEBUG_TEST_ERROR, got: %d, error: %s",
+ result, strerror(errno));
- msg = talloc_asprintf(NULL, "Test of level %#.4x failed - invalid timestamp", levels[i]);
- fail_if(result == DEBUG_TEST_NOK_TS, msg);
- talloc_free(msg);
+ fail_if(result == DEBUG_TEST_NOK_TS,
+ "Test of level %#.4x failed - invalid timestamp", levels[i]);
- msg = talloc_asprintf(NULL, "Test of level %#.4x failed - message don't match", levels[i]);
- fail_unless(result == EOK, msg);
- talloc_free(msg);
+ fail_unless(result == EOK,
+ "Test of level %#.4x failed - message don't match",
+ levels[i]);
}
}
END_TEST
@@ -488,7 +473,6 @@ START_TEST(test_debug_is_notset_no_timestamp)
SSSDBG_TRACE_ALL,
SSSDBG_TRACE_LDB
};
- char *error_msg;
debug_timestamps = 0;
debug_microseconds = 0;
@@ -503,17 +487,13 @@ START_TEST(test_debug_is_notset_no_timestamp)
errno = 0;
result = test_helper_debug_is_empty_message(levels[i]);
- if (result == DEBUG_TEST_ERROR) {
- error_msg = strerror(errno);
- fail(error_msg);
- }
+ fail_if(result == DEBUG_TEST_ERROR,
+ "Expecting DEBUG_TEST_ERROR, got: %d, error: %s",
+ result, strerror(errno));
- char *msg = NULL;
- msg = talloc_asprintf(NULL,
- "Test of level %#.4x failed - message has been written",
- levels[i]);
- fail_unless(result == EOK, msg);
- talloc_free(msg);
+ fail_unless(result == EOK,
+ "Test of level %#.4x failed - message has been written",
+ levels[i]);
}
}
END_TEST
@@ -536,7 +516,6 @@ START_TEST(test_debug_is_notset_timestamp)
SSSDBG_TRACE_ALL,
SSSDBG_TRACE_LDB
};
- char *error_msg;
debug_timestamps = 0;
debug_microseconds = 0;
@@ -551,17 +530,13 @@ START_TEST(test_debug_is_notset_timestamp)
errno = 0;
result = test_helper_debug_is_empty_message(levels[i]);
- if (result == DEBUG_TEST_ERROR) {
- error_msg = strerror(errno);
- fail(error_msg);
- }
+ fail_if(result == DEBUG_TEST_ERROR,
+ "Expecting DEBUG_TEST_ERROR, got: %d, error: %s",
+ result, strerror(errno));
- char *msg = NULL;
- msg = talloc_asprintf(NULL,
- "Test of level %#.4x failed - message has been written",
- levels[i]);
- fail_unless(result == EOK, msg);
- talloc_free(msg);
+ fail_unless(result == EOK,
+ "Test of level %#.4x failed - message has been written",
+ levels[i]);
}
}
END_TEST
@@ -584,7 +559,6 @@ START_TEST(test_debug_is_notset_timestamp_microseconds)
SSSDBG_TRACE_ALL,
SSSDBG_TRACE_LDB
};
- char *error_msg;
debug_timestamps = 0;
debug_microseconds = 1;
@@ -598,17 +572,13 @@ START_TEST(test_debug_is_notset_timestamp_microseconds)
errno = 0;
result = test_helper_debug_is_empty_message(levels[i]);
- if (result == DEBUG_TEST_ERROR) {
- error_msg = strerror(errno);
- fail(error_msg);
- }
+ fail_if(result == DEBUG_TEST_ERROR,
+ "Expecting DEBUG_TEST_ERROR, got: %d, error: %s",
+ result, strerror(errno));
- char *msg = NULL;
- msg = talloc_asprintf(NULL,
- "Test of level %#.4x failed - message has been written",
- levels[i]);
- fail_unless(result == EOK, msg);
- talloc_free(msg);
+ fail_unless(result == EOK,
+ "Test of level %#.4x failed - message has been written",
+ levels[i]);
}
}
END_TEST
@@ -635,10 +605,9 @@ START_TEST(test_debug_is_set_true)
for (i = 0; i < N_ELEMENTS(levels); i++) {
result = DEBUG_IS_SET(levels[i]);
- char *msg = NULL;
- msg = talloc_asprintf(NULL, "Test of level %#.4x failed - result is 0x%.4x", levels[i], result);
- fail_unless(result > 0, msg);
- talloc_free(msg);
+ fail_unless(result > 0,
+ "Test of level %#.4x failed - result is 0x%.4x",
+ levels[i], result);
}
}
END_TEST
@@ -666,10 +635,9 @@ START_TEST(test_debug_is_set_false)
debug_level = all_set & ~levels[i];
result = DEBUG_IS_SET(levels[i]);
- char *msg = NULL;
- msg = talloc_asprintf(NULL, "Test of level %#.4x failed - result is 0x%.4x", levels[i], result);
- fail_unless(result == 0, msg);
- talloc_free(msg);
+ fail_unless(result == 0,
+ "Test of level %#.4x failed - result is 0x%.4x",
+ levels[i], result);
}
}
END_TEST
--
2.28.0.rc2