aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-12-28 18:13:40 +0000
committerlloyd <[email protected]>2011-12-28 18:13:40 +0000
commit965275b1d8457a9829a474821c2623a045213e53 (patch)
treee591297be4192bc6abac610a6484711a423b57e6 /src
parentf501568f586735f06afd1822dcb7ed9ec4bc129d (diff)
Add non-null assertion, don't print msg if empty string
Diffstat (limited to 'src')
-rw-r--r--src/utils/assert.cpp2
-rw-r--r--src/utils/assert.h10
2 files changed, 11 insertions, 1 deletions
diff --git a/src/utils/assert.cpp b/src/utils/assert.cpp
index 29af831d8..3747912d6 100644
--- a/src/utils/assert.cpp
+++ b/src/utils/assert.cpp
@@ -21,7 +21,7 @@ void assertion_failure(const char* expr_str,
format << "Assertion " << expr_str << " failed ";
- if(msg)
+ if(msg && msg[0] != 0)
format << "(" << msg << ") ";
if(func)
diff --git a/src/utils/assert.h b/src/utils/assert.h
index 67ca665e3..135c1d392 100644
--- a/src/utils/assert.h
+++ b/src/utils/assert.h
@@ -36,6 +36,16 @@ void assertion_failure(const char* expr_str,
__LINE__); \
} while(0)
+#define BOTAN_ASSERT_NONNULL(ptr, msg) \
+ do { \
+ if(static_cast<bool>(ptr) == false) \
+ Botan::assertion_failure(#ptr " is not null", \
+ msg, \
+ BOTAN_ASSERT_FUNCTION, \
+ __FILE__, \
+ __LINE__); \
+ } while(0)
+
/*
* Unfortunately getting the function name from the preprocessor
* isn't standard in C++98 (C++0x uses C99's __func__)