diff --git a/src/prival.c b/src/prival.c index 224bd004..77f6cffa 100644 --- a/src/prival.c +++ b/src/prival.c @@ -66,6 +66,11 @@ stumpless_get_priority_string( int prival ) { size_t priority_string_size; char* priority_string; + if (facility_is_invalid(get_facility(prival))) + return NULL; + if (severity_is_invalid(get_severity(prival))) + return NULL; + facility = stumpless_get_facility_string( get_facility( prival ) ); severity = stumpless_get_severity_string( get_severity( prival ) ); diff --git a/test/function/prival.cpp b/test/function/prival.cpp index a645bf24..51df63ae 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -132,4 +132,15 @@ namespace { free( ( void * ) result ); } + + TEST(GetPriorityString, InvalidPrivals) { + int prival; + const char *result; + + prival = 0x100; + result = stumpless_get_priority_string( prival ); + EXPECT_STREQ( result, NULL ); + + free( ( void * ) result ); + } }