Skip to content

Commit

Permalink
jobs: more asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanTheGeek committed Dec 16, 2023
1 parent ec1ae74 commit 0acf989
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions source/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
#endif
#define CONST_STRLEN( x ) ( sizeof( ( x ) ) - 1U )

/**
* @brief Get the length on an array.
*/
#ifdef ARRAY_LENGTH
#undef ARRAY_LENGTH
#endif
#define ARRAY_LENGTH( x ) ( sizeof( ( x ) ) / sizeof( ( x )[ 0 ] ) )

/**
* @brief Table of topic API strings in JobsTopic_t order.
*/
Expand Down Expand Up @@ -817,7 +825,7 @@ size_t Jobs_UpdateMsg( JobCurrentStatus_t status,
char * buffer,
size_t bufferSize )
{
static const char * const jobStatusString[ 5U ] =
static const char * const jobStatusString[] =
{
"QUEUED",
"IN_PROGRESS",
Expand All @@ -826,7 +834,7 @@ size_t Jobs_UpdateMsg( JobCurrentStatus_t status,
"REJECTED"
};

static const size_t jobStatusStringLengths[ 5U ] =
static const size_t jobStatusStringLengths[] =
{
CONST_STRLEN( "QUEUED" ),
CONST_STRLEN( "IN_PROGRESS" ),
Expand All @@ -835,6 +843,8 @@ size_t Jobs_UpdateMsg( JobCurrentStatus_t status,
CONST_STRLEN( "REJECTED" )
};

assert( ( ( size_t ) status ) < ARRAY_LENGTH( jobStatusString ) );

size_t start = 0U;

if( ( expectedVersion != NULL ) && ( expectedVersionLength > 0U ) && ( bufferSize >=
Expand Down Expand Up @@ -867,18 +877,20 @@ bool Jobs_IsJobUpdateStatus( const char * topic,
const size_t thingNameLength,
JobUpdateStatus_t expectedStatus )
{
static const char * const jobUpdateStatusString[ 2U ] =
static const char * const jobUpdateStatusString[] =
{
"accepted",
"rejected"
};

static const size_t jobUpdateStatusStringLengths[ 2U ] =
static const size_t jobUpdateStatusStringLengths[] =
{
CONST_STRLEN( "accepted" ),
CONST_STRLEN( "rejected" )
};

assert( ( ( size_t ) expectedStatus ) < ARRAY_LENGTH( jobUpdateStatusString ) );

/* Max suffix size = max topic size - "$aws/<thingname>" prefix */
size_t suffixBufferLength = ( TOPIC_BUFFER_SIZE - CONST_STRLEN( "$aws/<thingname>" ) );
char suffixBuffer[ TOPIC_BUFFER_SIZE - CONST_STRLEN( "$aws/<thingname>" ) ] = { '\0' };
Expand Down

0 comments on commit 0acf989

Please sign in to comment.