commit 58ed795: [Test] Do not cause sigsegv on failed test

Vsevolod Stakhov vsevolod at rspamd.com
Fri Apr 15 21:14:04 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-04-15 21:09:35 +0100
URL: https://github.com/rspamd/rspamd/commit/58ed7953ef439d242c4822f837ed745c6869f761

[Test] Do not cause sigsegv on failed test

---
 test/rspamd_cxx_unit_dkim.hxx | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/test/rspamd_cxx_unit_dkim.hxx b/test/rspamd_cxx_unit_dkim.hxx
index 29facba8a..802e9ecbf 100644
--- a/test/rspamd_cxx_unit_dkim.hxx
+++ b/test/rspamd_cxx_unit_dkim.hxx
@@ -150,11 +150,15 @@ TEST_CASE("rspamd_dkim_parse_key")
 				CHECK(key != nullptr);
 				char hexbuf[RSPAMD_DKIM_KEY_ID_LEN * 2 + 1];
 				auto *id = rspamd_dkim_key_id(key);
-				auto hexlen = rspamd_encode_hex_buf(id, RSPAMD_DKIM_KEY_ID_LEN, hexbuf,
-						sizeof(hexbuf));
-				CHECK(hexlen > 0);
-				CHECK(std::string{hexbuf, (std::size_t) hexlen} == c.expected_id);
-				rspamd_dkim_key_free(key);
+				CHECK(id != nullptr);
+
+				if (id) {
+					auto hexlen = rspamd_encode_hex_buf(id, RSPAMD_DKIM_KEY_ID_LEN, hexbuf,
+							sizeof(hexbuf));
+					CHECK(hexlen > 0);
+					CHECK(std::string{hexbuf, (std::size_t) hexlen} == c.expected_id);
+					rspamd_dkim_key_free(key);
+				}
 			}
 			else {
 				CHECK(key == nullptr);


More information about the Commits mailing list