From 016abde018e5ebfba3db36da548eb9cfe5ae5f07 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:07:07 +0200 Subject: [PATCH 01/16] Updated test function to make the Severity and Facility case consistent --- test/function/prival.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/function/prival.cpp b/test/function/prival.cpp index f7943058e..265aa11f5 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -134,8 +134,6 @@ namespace { result = stumpless_prival_from_string( "syslog.err" ); EXPECT_EQ( result, -1 ); - EXPECT_ERROR_ID_EQ( STUMPLESS_MEMORY_ALLOCATION_FAILURE ); - set_malloc_result = stumpless_set_malloc( malloc ); EXPECT_TRUE( set_malloc_result == malloc ); } From 4162d40cfd1e4ba79737f1c978b6e47216fdce73 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:08:02 +0200 Subject: [PATCH 02/16] Updated the function stumpless_prival_from_string to make use of the get_x_from_buffer functions --- src/prival.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/prival.c b/src/prival.c index f5b39ba34..de62a54c8 100644 --- a/src/prival.c +++ b/src/prival.c @@ -64,7 +64,6 @@ stumpless_prival_from_string( const char *string ) { int prival; int severity; int facility; - const char *param; const char *period; const char *sec_period; size_t len; @@ -103,15 +102,7 @@ stumpless_prival_from_string( const char *string ) { // Calculate the facility length, up to the first period character len = period - string; - // Copy the facility substring to the param buffer - param = copy_cstring_length( string, len ); - if( !param ) { - return -1; - } - - facility = stumpless_get_facility_enum( param ); - - free_mem( param ); + facility = stumpless_get_facility_enum_from_buffer( string, len ); if( facility < 0 ) { raise_invalid_param( ); @@ -122,15 +113,7 @@ stumpless_prival_from_string( const char *string ) { len++; len = slen - len; - // Copy the severity substring to the param buffer - param = copy_cstring_length( period + 1, len ); - if( !param ) { - return -1; - } - - severity = stumpless_get_severity_enum( param ); - - free_mem( param ); + severity = stumpless_get_severity_enum_from_buffer( period + 1, len ); if( severity < 0 ) { raise_invalid_param( ); From 30c2fe2eb9fa6c13ecbad41f562384c8321ee80e Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:08:29 +0200 Subject: [PATCH 03/16] Updated the get_x_from_buffer function to make use of the length param --- src/facility.c | 3 +-- src/severity.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/facility.c b/src/facility.c index a7819e39d..b1b64723a 100644 --- a/src/facility.c +++ b/src/facility.c @@ -46,12 +46,11 @@ stumpless_get_facility_enum_from_buffer(const char *facility_buffer, size_t faci size_t i; char *facility_name; const int str_offset = 19; // to ommit "STUMPLESS_FACILITY_" - size_t buf_length; facility_bound = sizeof( facility_enum_to_string ) / sizeof( facility_enum_to_string[0] ); - facility_name = copy_cstring_with_length(facility_buffer, &buf_length); + facility_name = copy_cstring_length(facility_buffer, facility_buffer_length); if( !facility_name ) { return -1; } diff --git a/src/severity.c b/src/severity.c index fa2ec1604..5f8ca72ec 100644 --- a/src/severity.c +++ b/src/severity.c @@ -44,12 +44,11 @@ enum stumpless_severity stumpless_get_severity_enum_from_buffer(const char *seve size_t i; char *severity_name; const int str_offset = 19; // to ommit "STUMPLESS_SEVERITY_" - size_t buf_length; severity_bound = sizeof( severity_enum_to_string ) / sizeof( severity_enum_to_string[0] ); - severity_name = copy_cstring_with_length( severity_buffer, &buf_length ); + severity_name = copy_cstring_length( severity_buffer, severity_buffer_length ); if( !severity_name ) { return -1; } From 2a620868be0137f6813171e44e89c4e248d06858 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:08:29 +0200 Subject: [PATCH 04/16] Removed unused include --- src/facility.c | 3 +-- src/prival.c | 1 - src/severity.c | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/facility.c b/src/facility.c index a7819e39d..b1b64723a 100644 --- a/src/facility.c +++ b/src/facility.c @@ -46,12 +46,11 @@ stumpless_get_facility_enum_from_buffer(const char *facility_buffer, size_t faci size_t i; char *facility_name; const int str_offset = 19; // to ommit "STUMPLESS_FACILITY_" - size_t buf_length; facility_bound = sizeof( facility_enum_to_string ) / sizeof( facility_enum_to_string[0] ); - facility_name = copy_cstring_with_length(facility_buffer, &buf_length); + facility_name = copy_cstring_length(facility_buffer, facility_buffer_length); if( !facility_name ) { return -1; } diff --git a/src/prival.c b/src/prival.c index de62a54c8..4e11d3c43 100644 --- a/src/prival.c +++ b/src/prival.c @@ -31,7 +31,6 @@ #include "private/memory.h" #include "private/prival.h" #include "private/severity.h" -#include "private/strhelper.h" #include "private/validate.h" const char * diff --git a/src/severity.c b/src/severity.c index fa2ec1604..5f8ca72ec 100644 --- a/src/severity.c +++ b/src/severity.c @@ -44,12 +44,11 @@ enum stumpless_severity stumpless_get_severity_enum_from_buffer(const char *seve size_t i; char *severity_name; const int str_offset = 19; // to ommit "STUMPLESS_SEVERITY_" - size_t buf_length; severity_bound = sizeof( severity_enum_to_string ) / sizeof( severity_enum_to_string[0] ); - severity_name = copy_cstring_with_length( severity_buffer, &buf_length ); + severity_name = copy_cstring_length( severity_buffer, severity_buffer_length ); if( !severity_name ) { return -1; } From 02240df35b279faace1215e996d7b94d24fe05a9 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:44:45 +0200 Subject: [PATCH 05/16] Fixed memory allocation error being overwritten. --- src/prival.c | 2 +- test/function/prival.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/prival.c b/src/prival.c index 4e11d3c43..245100376 100644 --- a/src/prival.c +++ b/src/prival.c @@ -114,7 +114,7 @@ stumpless_prival_from_string( const char *string ) { severity = stumpless_get_severity_enum_from_buffer( period + 1, len ); - if( severity < 0 ) { + if( severity < 0 && !stumpless_has_error()) { raise_invalid_param( ); return -1; } diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 265aa11f5..f7943058e 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -134,6 +134,8 @@ namespace { result = stumpless_prival_from_string( "syslog.err" ); EXPECT_EQ( result, -1 ); + EXPECT_ERROR_ID_EQ( STUMPLESS_MEMORY_ALLOCATION_FAILURE ); + set_malloc_result = stumpless_set_malloc( malloc ); EXPECT_TRUE( set_malloc_result == malloc ); } From 47bae22b2fb6704ba9740ea9115e35281a499bd3 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:40:15 +0200 Subject: [PATCH 06/16] Added header --- src/prival.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/prival.c b/src/prival.c index 245100376..a5747b2e8 100644 --- a/src/prival.c +++ b/src/prival.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "private/config.h" #include "private/config/wrapper/locale.h" #include "private/error.h" From a9d0d81d5e76db7f62e14d78ad13bf1d4c0e7b22 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:12:34 +0200 Subject: [PATCH 07/16] Implemented strncasecmp --- src/facility.c | 17 +++-------------- src/severity.c | 20 ++++---------------- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/src/facility.c b/src/facility.c index b1b64723a..e2118a5ee 100644 --- a/src/facility.c +++ b/src/facility.c @@ -44,38 +44,27 @@ enum stumpless_facility stumpless_get_facility_enum_from_buffer(const char *facility_buffer, size_t facility_buffer_length) { size_t facility_bound; size_t i; - char *facility_name; const int str_offset = 19; // to ommit "STUMPLESS_FACILITY_" facility_bound = sizeof( facility_enum_to_string ) / sizeof( facility_enum_to_string[0] ); - facility_name = copy_cstring_length(facility_buffer, facility_buffer_length); - if( !facility_name ) { - return -1; - } - - to_upper_case(facility_name); for( i = 0; i < facility_bound; i++ ) { - if( strcmp( facility_name, facility_enum_to_string[i] + str_offset ) == 0 ) { - free_mem( facility_name ); + if( strncasecmp( facility_buffer, facility_enum_to_string[i] + str_offset, facility_buffer_length ) == 0 ) { return i << 3; } } // exeption, for 'security' return 'auth' enum value - if( strcmp( facility_name, "SECURITY" ) == 0 ) { - free_mem( facility_name ); + if( strncasecmp( facility_buffer, "SECURITY", facility_buffer_length ) == 0 ) { return STUMPLESS_FACILITY_AUTH_VALUE; } // exeption, for 'authpriv' not presented in enum list - if( strcmp( facility_name, "AUTHPRIV" ) == 0 ) { - free_mem( facility_name ); + if( strncasecmp( facility_buffer, "AUTHPRIV", facility_buffer_length ) == 0 ) { return STUMPLESS_FACILITY_AUTH2_VALUE; } - free_mem( facility_name ); return -1; } diff --git a/src/severity.c b/src/severity.c index 5f8ca72ec..fd1a45e0f 100644 --- a/src/severity.c +++ b/src/severity.c @@ -42,41 +42,29 @@ enum stumpless_severity stumpless_get_severity_enum(const char *severity_string) enum stumpless_severity stumpless_get_severity_enum_from_buffer(const char *severity_buffer, size_t severity_buffer_length) { size_t severity_bound; size_t i; - char *severity_name; const int str_offset = 19; // to ommit "STUMPLESS_SEVERITY_" severity_bound = sizeof( severity_enum_to_string ) / sizeof( severity_enum_to_string[0] ); - severity_name = copy_cstring_length( severity_buffer, severity_buffer_length ); - if( !severity_name ) { - return -1; - } - - to_upper_case( severity_name ); for( i = 0; i < severity_bound; i++ ) { - if( strcmp( severity_name, severity_enum_to_string[i] + str_offset ) == 0 ) { - free_mem( severity_name ); + if( strncasecmp( severity_buffer, severity_enum_to_string[i] + str_offset, severity_buffer_length ) == 0 ) { return i; } } - if( strcmp( severity_name, "PANIC" ) == 0 ) { - free_mem( severity_name ); + if( strncasecmp( severity_buffer, "PANIC", severity_buffer_length ) == 0 ) { return STUMPLESS_SEVERITY_EMERG_VALUE; } - if( strcmp( severity_name, "ERROR" ) == 0 ) { - free_mem( severity_name ); + if( strncasecmp( severity_buffer, "ERROR", severity_buffer_length ) == 0 ) { return STUMPLESS_SEVERITY_ERR_VALUE; } - if( strcmp( severity_name, "WARN" ) == 0 ) { - free_mem( severity_name ); + if( strncasecmp( severity_buffer, "WARN", severity_buffer_length ) == 0 ) { return STUMPLESS_SEVERITY_WARNING_VALUE; } - free_mem( severity_name ); return -1; } From 42fcd5b3b3d3052230de93706b92050b3336eb1d Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:13:07 +0200 Subject: [PATCH 08/16] Removed tests because function no longer allocates --- test/function/prival.cpp | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/test/function/prival.cpp b/test/function/prival.cpp index f7943058e..bf478262a 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -112,34 +112,6 @@ namespace { EXPECT_ERROR_ID_EQ( STUMPLESS_INVALID_PARAM_STRING ); } - TEST( GetPrivalFromString, InvalidMemFacilityPriority ) { - int result; - void * (*set_malloc_result)(size_t); - set_malloc_result = stumpless_set_malloc( MALLOC_FAIL ); - ASSERT_NOT_NULL( set_malloc_result ); - - result = stumpless_prival_from_string( "user.err" ); - EXPECT_EQ( result, -1 ); - - set_malloc_result = stumpless_set_malloc( malloc ); - EXPECT_TRUE( set_malloc_result == malloc ); - } - - TEST( GetPrivalFromString, InvalidMemSeverityPriority ) { - int result; - void * (*set_malloc_result)(size_t); - set_malloc_result = stumpless_set_malloc( MALLOC_FAIL_ON_SIZE( 4 ) ); - ASSERT_NOT_NULL( set_malloc_result ); - - result = stumpless_prival_from_string( "syslog.err" ); - EXPECT_EQ( result, -1 ); - - EXPECT_ERROR_ID_EQ( STUMPLESS_MEMORY_ALLOCATION_FAILURE ); - - set_malloc_result = stumpless_set_malloc( malloc ); - EXPECT_TRUE( set_malloc_result == malloc ); - } - TEST(GetPrivalString, ValidPrival) { int prival; const char *result; From c955345dbb9870f1b3ce6b66f6308af4b7250e7c Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:15:57 +0200 Subject: [PATCH 09/16] Removed header --- test/function/prival.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/function/prival.cpp b/test/function/prival.cpp index bf478262a..7c2623bf7 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -21,7 +21,6 @@ #include #include #include "test/helper/assert.hpp" -#include "test/helper/memory_allocation.hpp" namespace { From 25b4b2d4dab9b8d2415ee94fc2566e86d393b71c Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Fri, 23 Aug 2024 13:37:42 +0200 Subject: [PATCH 10/16] Removed error check in prival from string --- src/prival.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prival.c b/src/prival.c index a5747b2e8..eeac09849 100644 --- a/src/prival.c +++ b/src/prival.c @@ -115,7 +115,7 @@ stumpless_prival_from_string( const char *string ) { severity = stumpless_get_severity_enum_from_buffer( period + 1, len ); - if( severity < 0 && !stumpless_has_error()) { + if( severity < 0 ) { raise_invalid_param( ); return -1; } From adca72e9316843e9eed60b96d795ee50a8928a20 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Sat, 24 Aug 2024 14:09:40 +0200 Subject: [PATCH 11/16] Removed redundant tests --- test/function/facility.cpp | 27 --------------------------- test/function/severity.cpp | 27 --------------------------- 2 files changed, 54 deletions(-) diff --git a/test/function/facility.cpp b/test/function/facility.cpp index ca9092be9..9f26e5ae7 100644 --- a/test/function/facility.cpp +++ b/test/function/facility.cpp @@ -111,19 +111,6 @@ namespace { EXPECT_NO_ERROR; } - TEST( GetFacilityEnum, InvalidMemFacility ) { - int result; - void * (*set_malloc_result)(size_t); - set_malloc_result = stumpless_set_malloc( MALLOC_FAIL ); - ASSERT_NOT_NULL( set_malloc_result ); - - result = stumpless_get_facility_enum( "user" ); - EXPECT_EQ( result, -1 ); - - set_malloc_result = stumpless_set_malloc( malloc ); - EXPECT_TRUE( set_malloc_result == malloc ); - } - TEST( GetFacilityEnum, NoSuchFacility ) { int result; @@ -131,18 +118,4 @@ namespace { EXPECT_EQ( result, -1 ); } - TEST( GetFacilityEnumFromBuffer, InvalidMemFacility ) { - int result; - void * (*set_malloc_result)(size_t); - set_malloc_result = stumpless_set_malloc( MALLOC_FAIL ); - ASSERT_NOT_NULL( set_malloc_result ); - - result = stumpless_get_facility_enum_from_buffer( "user", sizeof( "user" ) ); - EXPECT_EQ( result, -1 ); - EXPECT_ERROR_ID_EQ( STUMPLESS_MEMORY_ALLOCATION_FAILURE ); - - set_malloc_result = stumpless_set_malloc( malloc ); - EXPECT_TRUE( set_malloc_result == malloc ); - } - } diff --git a/test/function/severity.cpp b/test/function/severity.cpp index 12d4afd84..7847e61b0 100644 --- a/test/function/severity.cpp +++ b/test/function/severity.cpp @@ -100,19 +100,6 @@ namespace { EXPECT_NO_ERROR; } - TEST( GetSeverityEnum, InvalidMemSeverity ) { - int result; - void * (*set_malloc_result)(size_t); - set_malloc_result = stumpless_set_malloc( MALLOC_FAIL ); - ASSERT_NOT_NULL( set_malloc_result ); - - result = stumpless_get_severity_enum( "info" ); - EXPECT_EQ( result, -1 ); - - set_malloc_result = stumpless_set_malloc( malloc ); - EXPECT_TRUE( set_malloc_result == malloc ); - } - TEST( GetSeverityEnum, NoSuchSeverity ) { int severity_count = 0; int result; @@ -128,18 +115,4 @@ namespace { EXPECT_EQ( result, -1 ); } - TEST( GetSeverityEnumFromBuffer, InvalidMemSeverity ) { - int result; - void * (*set_malloc_result)(size_t); - set_malloc_result = stumpless_set_malloc( MALLOC_FAIL ); - ASSERT_NOT_NULL( set_malloc_result ); - - result = stumpless_get_severity_enum_from_buffer( "info", sizeof("info") ); - EXPECT_EQ( result, -1 ); - EXPECT_ERROR_ID_EQ( STUMPLESS_MEMORY_ALLOCATION_FAILURE ); - - set_malloc_result = stumpless_set_malloc( malloc ); - EXPECT_TRUE( set_malloc_result == malloc ); - } - } From 9068c310c98b1b0a537a3a925a106b417913f8c0 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Sat, 24 Aug 2024 14:11:04 +0200 Subject: [PATCH 12/16] Removed unused headers --- src/facility.c | 1 - src/prival.c | 1 - src/severity.c | 1 - 3 files changed, 3 deletions(-) diff --git a/src/facility.c b/src/facility.c index e2118a5ee..ebf6b0612 100644 --- a/src/facility.c +++ b/src/facility.c @@ -21,7 +21,6 @@ #include #include "private/facility.h" #include "private/strhelper.h" -#include "private/memory.h" static char *facility_enum_to_string[] = { STUMPLESS_FOREACH_FACILITY( GENERATE_STRING ) diff --git a/src/prival.c b/src/prival.c index eeac09849..017139a0a 100644 --- a/src/prival.c +++ b/src/prival.c @@ -27,7 +27,6 @@ #include #include "private/config.h" #include "private/config/wrapper/locale.h" -#include "private/error.h" #include "private/facility.h" #include "private/memory.h" #include "private/prival.h" diff --git a/src/severity.c b/src/severity.c index fd1a45e0f..6d93db04f 100644 --- a/src/severity.c +++ b/src/severity.c @@ -21,7 +21,6 @@ #include #include "private/severity.h" #include "private/strhelper.h" -#include "private/memory.h" static char *severity_enum_to_string[] = { STUMPLESS_FOREACH_SEVERITY( GENERATE_STRING ) From 0b86db79e64df7a93724773deb70dda3ff5569c0 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Sat, 24 Aug 2024 15:22:53 +0200 Subject: [PATCH 13/16] Fix headers --- src/prival.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prival.c b/src/prival.c index 017139a0a..05d0abd28 100644 --- a/src/prival.c +++ b/src/prival.c @@ -24,7 +24,6 @@ #include #include #include -#include #include "private/config.h" #include "private/config/wrapper/locale.h" #include "private/facility.h" @@ -32,6 +31,7 @@ #include "private/prival.h" #include "private/severity.h" #include "private/validate.h" +#include "private/error.h" const char * stumpless_get_prival_string( int prival ) { From 175e77273779c4192a88a9ae2dd1db9489986683 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Mon, 26 Aug 2024 19:48:29 +0200 Subject: [PATCH 14/16] Created custom strncasecmp --- include/private/strhelper.h | 3 +++ src/facility.c | 6 +++--- src/severity.c | 8 ++++---- src/strhelper.c | 13 +++++++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/private/strhelper.h b/include/private/strhelper.h index 55e817c27..6d44eae82 100644 --- a/include/private/strhelper.h +++ b/include/private/strhelper.h @@ -40,4 +40,7 @@ copy_cstring_length( const char *str, size_t length ); void to_upper_case( char *str ); +int +strncasecmp_custom( const char *s1, const char *s2, size_t n ); + #endif /* __STUMPLESS_PRIVATE_STRHELPER_H */ diff --git a/src/facility.c b/src/facility.c index ebf6b0612..dff55c6d6 100644 --- a/src/facility.c +++ b/src/facility.c @@ -49,18 +49,18 @@ stumpless_get_facility_enum_from_buffer(const char *facility_buffer, size_t faci sizeof( facility_enum_to_string[0] ); for( i = 0; i < facility_bound; i++ ) { - if( strncasecmp( facility_buffer, facility_enum_to_string[i] + str_offset, facility_buffer_length ) == 0 ) { + if( strncasecmp_custom( facility_buffer, facility_enum_to_string[i] + str_offset, facility_buffer_length ) == 0 ) { return i << 3; } } // exeption, for 'security' return 'auth' enum value - if( strncasecmp( facility_buffer, "SECURITY", facility_buffer_length ) == 0 ) { + if( strncasecmp_custom( facility_buffer, "SECURITY", facility_buffer_length ) == 0 ) { return STUMPLESS_FACILITY_AUTH_VALUE; } // exeption, for 'authpriv' not presented in enum list - if( strncasecmp( facility_buffer, "AUTHPRIV", facility_buffer_length ) == 0 ) { + if( strncasecmp_custom( facility_buffer, "AUTHPRIV", facility_buffer_length ) == 0 ) { return STUMPLESS_FACILITY_AUTH2_VALUE; } diff --git a/src/severity.c b/src/severity.c index 6d93db04f..2a20bcdbf 100644 --- a/src/severity.c +++ b/src/severity.c @@ -47,20 +47,20 @@ enum stumpless_severity stumpless_get_severity_enum_from_buffer(const char *seve sizeof( severity_enum_to_string[0] ); for( i = 0; i < severity_bound; i++ ) { - if( strncasecmp( severity_buffer, severity_enum_to_string[i] + str_offset, severity_buffer_length ) == 0 ) { + if( strncasecmp_custom( severity_buffer, severity_enum_to_string[i] + str_offset, severity_buffer_length ) == 0 ) { return i; } } - if( strncasecmp( severity_buffer, "PANIC", severity_buffer_length ) == 0 ) { + if( strncasecmp_custom( severity_buffer, "PANIC", severity_buffer_length ) == 0 ) { return STUMPLESS_SEVERITY_EMERG_VALUE; } - if( strncasecmp( severity_buffer, "ERROR", severity_buffer_length ) == 0 ) { + if( strncasecmp_custom( severity_buffer, "ERROR", severity_buffer_length ) == 0 ) { return STUMPLESS_SEVERITY_ERR_VALUE; } - if( strncasecmp( severity_buffer, "WARN", severity_buffer_length ) == 0 ) { + if( strncasecmp_custom( severity_buffer, "WARN", severity_buffer_length ) == 0 ) { return STUMPLESS_SEVERITY_WARNING_VALUE; } diff --git a/src/strhelper.c b/src/strhelper.c index 82d9a4377..6db7d0179 100644 --- a/src/strhelper.c +++ b/src/strhelper.c @@ -79,3 +79,16 @@ to_upper_case( char *str ) { str[i] = toupper( str[i] ); } } + +int +strncasecmp_custom( const char *s1, const char *s2, size_t n ) { + if (n != 0) { + do { + if (tolower(*s1) != tolower(*s2++)) + return tolower(*s1) - tolower(*--s2); + if (*s1++ == '\0') + break; + } while (--n != 0); + } + return 0; +} From 5908d506759517a4fe5e63ef59a4eda40ac7bfa2 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Mon, 26 Aug 2024 19:49:13 +0200 Subject: [PATCH 15/16] Removed unused headers --- test/function/facility.cpp | 1 - test/function/severity.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/test/function/facility.cpp b/test/function/facility.cpp index 9f26e5ae7..ec9993ba5 100644 --- a/test/function/facility.cpp +++ b/test/function/facility.cpp @@ -20,7 +20,6 @@ #include #include #include "test/helper/assert.hpp" -#include "test/helper/memory_allocation.hpp" namespace { diff --git a/test/function/severity.cpp b/test/function/severity.cpp index 7847e61b0..35fc6bee0 100644 --- a/test/function/severity.cpp +++ b/test/function/severity.cpp @@ -20,7 +20,6 @@ #include #include #include "test/helper/assert.hpp" -#include "test/helper/memory_allocation.hpp" namespace { From f894f7f8daae4f6ae6cfe6fc1c8bbf0ad1e1cb64 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:23:20 +0200 Subject: [PATCH 16/16] Removed unused headers --- test/function/facility.cpp | 1 - test/function/severity.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/test/function/facility.cpp b/test/function/facility.cpp index ec9993ba5..b3292f1c2 100644 --- a/test/function/facility.cpp +++ b/test/function/facility.cpp @@ -16,7 +16,6 @@ * limitations under the License. */ -#include #include #include #include "test/helper/assert.hpp" diff --git a/test/function/severity.cpp b/test/function/severity.cpp index 35fc6bee0..70f431a94 100644 --- a/test/function/severity.cpp +++ b/test/function/severity.cpp @@ -16,7 +16,6 @@ * limitations under the License. */ -#include #include #include #include "test/helper/assert.hpp"