Loading lib_util/cmdl_tools.c +25 −0 Original line number Diff line number Diff line Loading @@ -225,3 +225,28 @@ bool isEmptyString( { return str[0] == '\0'; } /*---------------------------------------------------------------------* * strLength() * * Get the length of a string up to a maximum length. * * Equivalent to strnlen, which is not part of the C standard and only provided by POSIX. * *---------------------------------------------------------------------*/ int32_t strLength( const char *str, int32_t maxlen ) { int32_t len; len = 0; while ( len < maxlen && str[len] != '\0' ) { len++; } return len; } lib_util/cmdl_tools.h +2 −0 Original line number Diff line number Diff line Loading @@ -50,4 +50,6 @@ void clearString( char *str ); bool isEmptyString( const char *str ); int32_t strLength( const char *str, int32_t maxlen ); #endif /* CMDL_TOOLS_H */ lib_util/cmdln_parser.c +7 −6 Original line number Diff line number Diff line Loading @@ -52,7 +52,8 @@ typedef struct } Option; /* Error enum for internal use */ typedef enum { typedef enum { CMDLN_PARSER_ERR_OK = 0, CMDLN_PARSER_ERR_FAILED_PARSING = -1, CMDLN_PARSER_ERR_MISCONFIGURED = -2, Loading Loading @@ -94,12 +95,12 @@ static CmdLnParserError validateOptionProps( } /* Check match string length */ if ( strnlen( props.match, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) if ( strLength( props.match, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) { fprintf( stderr, "[dev] Option with ID %d - match string exceeds limit of %d characters.\n", props.id, MAX_OPTION_MATCH_LENGTH ); return CMDLN_PARSER_ERR_MISCONFIGURED; } if ( props.matchShort != NULL && strnlen( props.matchShort, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) if ( props.matchShort != NULL && strLength( props.matchShort, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) { fprintf( stderr, "[dev] Option with ID %d - matchShort string exceeds limit of %d characters.\n", props.id, MAX_OPTION_MATCH_LENGTH ); return CMDLN_PARSER_ERR_MISCONFIGURED; Loading Loading
lib_util/cmdl_tools.c +25 −0 Original line number Diff line number Diff line Loading @@ -225,3 +225,28 @@ bool isEmptyString( { return str[0] == '\0'; } /*---------------------------------------------------------------------* * strLength() * * Get the length of a string up to a maximum length. * * Equivalent to strnlen, which is not part of the C standard and only provided by POSIX. * *---------------------------------------------------------------------*/ int32_t strLength( const char *str, int32_t maxlen ) { int32_t len; len = 0; while ( len < maxlen && str[len] != '\0' ) { len++; } return len; }
lib_util/cmdl_tools.h +2 −0 Original line number Diff line number Diff line Loading @@ -50,4 +50,6 @@ void clearString( char *str ); bool isEmptyString( const char *str ); int32_t strLength( const char *str, int32_t maxlen ); #endif /* CMDL_TOOLS_H */
lib_util/cmdln_parser.c +7 −6 Original line number Diff line number Diff line Loading @@ -52,7 +52,8 @@ typedef struct } Option; /* Error enum for internal use */ typedef enum { typedef enum { CMDLN_PARSER_ERR_OK = 0, CMDLN_PARSER_ERR_FAILED_PARSING = -1, CMDLN_PARSER_ERR_MISCONFIGURED = -2, Loading Loading @@ -94,12 +95,12 @@ static CmdLnParserError validateOptionProps( } /* Check match string length */ if ( strnlen( props.match, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) if ( strLength( props.match, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) { fprintf( stderr, "[dev] Option with ID %d - match string exceeds limit of %d characters.\n", props.id, MAX_OPTION_MATCH_LENGTH ); return CMDLN_PARSER_ERR_MISCONFIGURED; } if ( props.matchShort != NULL && strnlen( props.matchShort, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) if ( props.matchShort != NULL && strLength( props.matchShort, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) { fprintf( stderr, "[dev] Option with ID %d - matchShort string exceeds limit of %d characters.\n", props.id, MAX_OPTION_MATCH_LENGTH ); return CMDLN_PARSER_ERR_MISCONFIGURED; Loading