From 166cbe0f93250b5fb412f03f2ff9ec67bf4fdfd6 Mon Sep 17 00:00:00 2001 From: Paul Bartell Date: Tue, 11 May 2021 10:27:13 -0700 Subject: [PATCH] Reduce gnu complexity score of httpHeaderCpy function. --- source/core_http_client.c | 62 ++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/source/core_http_client.c b/source/core_http_client.c index e7ae2778..e7d94dba 100644 --- a/source/core_http_client.c +++ b/source/core_http_client.c @@ -1289,44 +1289,32 @@ static size_t httpHeaderCpy( char * pDest, for( i = 0; i < len; i++ ) { - switch( pSrc[ i ] ) + if( pSrc[ i ] == NULL_CHARACTER ) + { + endOfInput = 1U; + } + else if( pSrc[ i ] == CARRIAGE_RETURN_CHARACTER ) + { + LogError( ( "Invalid character '\r' found in %.*s", + ( int ) len, pSrc ) ); + hasError = 1U; + } + else if( pSrc[ i ] == LINEFEED_CHARACTER ) + { + LogError( ( "Invalid character '\n' found in %.*s", + ( int ) len, pSrc ) ); + hasError = 1U; + } + else if( ( pSrc[ i ] == COLON_CHARACTER ) && ( isField == 1U ) ) + { + LogError( ( "Invalid character ':' found in %.*s", + ( int ) len, pSrc ) ); + hasError = 1U; + } + else { - case NULL_CHARACTER: - endOfInput = 1U; - break; - - case CARRIAGE_RETURN_CHARACTER: - LogError( ( "Invalid character '\r' found in %.*s", - ( int ) len, pSrc ) ); - hasError = 1U; - break; - - case LINEFEED_CHARACTER: - LogError( ( "Invalid character '\n' found in %.*s", - ( int ) len, pSrc ) ); - hasError = 1U; - break; - - case COLON_CHARACTER: - - if( isField == 1U ) - { - LogError( ( "Invalid character ':' found in %.*s", - ( int ) len, pSrc ) ); - hasError = 1U; - } - else - { - pDest[ i ] = pSrc[ i ]; - charsWritten++; - } - - break; - - default: - pDest[ i ] = pSrc[ i ]; - charsWritten++; - break; + pDest[ i ] = pSrc[ i ]; + charsWritten++; } if( ( endOfInput == 1U ) || ( hasError == 1U ) )