Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Use size_t for length and index fields #237

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ static MQTTStatus_t validatePublishParams( const MQTTContext_t * pContext,
* @return Returns whether the topic filter and the topic name match.
*/
static bool matchEndWildcardsSpecialCases( const char * pTopicFilter,
uint16_t topicFilterLength,
uint16_t filterIndex );
size_t topicFilterLength,
size_t filterIndex );

/**
* @brief Attempt to match topic name with a topic filter starting with a wildcard.
Expand All @@ -505,11 +505,11 @@ static bool matchEndWildcardsSpecialCases( const char * pTopicFilter,
* caller should continue parsing the topics.
*/
static bool matchWildcards( const char * pTopicName,
uint16_t topicNameLength,
size_t topicNameLength,
const char * pTopicFilter,
uint16_t topicFilterLength,
uint16_t * pNameIndex,
uint16_t * pFilterIndex,
size_t topicFilterLength,
size_t * pNameIndex,
size_t * pFilterIndex,
bool * pMatch );

/**
Expand All @@ -523,15 +523,15 @@ static bool matchWildcards( const char * pTopicName,
* @return `true` if the topic name and topic filter match; `false` otherwise.
*/
static bool matchTopicFilter( const char * pTopicName,
uint16_t topicNameLength,
size_t topicNameLength,
const char * pTopicFilter,
uint16_t topicFilterLength );
size_t topicFilterLength );

/*-----------------------------------------------------------*/

static bool matchEndWildcardsSpecialCases( const char * pTopicFilter,
uint16_t topicFilterLength,
uint16_t filterIndex )
size_t topicFilterLength,
size_t filterIndex )
{
bool matchFound = false;

Expand Down Expand Up @@ -571,11 +571,11 @@ static bool matchEndWildcardsSpecialCases( const char * pTopicFilter,
/*-----------------------------------------------------------*/

static bool matchWildcards( const char * pTopicName,
uint16_t topicNameLength,
size_t topicNameLength,
const char * pTopicFilter,
uint16_t topicFilterLength,
uint16_t * pNameIndex,
uint16_t * pFilterIndex,
size_t topicFilterLength,
size_t * pNameIndex,
size_t * pFilterIndex,
bool * pMatch )
{
bool shouldStopMatching = false;
Expand Down Expand Up @@ -675,12 +675,13 @@ static bool matchWildcards( const char * pTopicName,
/*-----------------------------------------------------------*/

static bool matchTopicFilter( const char * pTopicName,
uint16_t topicNameLength,
size_t topicNameLength,
const char * pTopicFilter,
uint16_t topicFilterLength )
size_t topicFilterLength )
{
bool matchFound = false, shouldStopMatching = false;
uint16_t nameIndex = 0, filterIndex = 0;
size_t nameIndex = 0;
size_t filterIndex = 0;

assert( pTopicName != NULL );
assert( topicNameLength != 0 );
Expand Down Expand Up @@ -2195,7 +2196,7 @@ static MQTTStatus_t sendConnectWithoutCopy( MQTTContext_t * pContext,
/* Serialize the payload. Payload of last will and testament can be NULL. */
vectorsAdded = addEncodedStringToVector( serializedPayloadLength,
pWillInfo->pPayload,
( uint16_t ) pWillInfo->payloadLength,
pWillInfo->payloadLength,
iterator,
&totalMessageLength );

Expand Down Expand Up @@ -3126,9 +3127,9 @@ uint16_t MQTT_GetPacketId( MQTTContext_t * pContext )
/*-----------------------------------------------------------*/

MQTTStatus_t MQTT_MatchTopic( const char * pTopicName,
const uint16_t topicNameLength,
const size_t topicNameLength,
const char * pTopicFilter,
const uint16_t topicFilterLength,
const size_t topicFilterLength,
bool * pIsMatch )
{
MQTTStatus_t status = MQTTSuccess;
Expand Down
6 changes: 3 additions & 3 deletions source/core_mqtt_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static size_t remainingLengthEncodedSize( size_t length );
*/
static uint8_t * encodeString( uint8_t * pDestination,
const char * pSource,
uint16_t sourceLength );
size_t sourceLength );

/**
* @brief Retrieves and decodes the Remaining Length from the network interface
Expand Down Expand Up @@ -522,7 +522,7 @@ static uint8_t * encodeRemainingLength( uint8_t * pDestination,

static uint8_t * encodeString( uint8_t * pDestination,
const char * pSource,
uint16_t sourceLength )
size_t sourceLength )
{
uint8_t * pBuffer = NULL;

Expand Down Expand Up @@ -1664,7 +1664,7 @@ static void serializeConnectPacket( const MQTTConnectInfo_t * pConnectInfo,

pIndex = encodeString( pIndex,
pWillInfo->pPayload,
( uint16_t ) pWillInfo->payloadLength );
pWillInfo->payloadLength );
}

/* Encode the user name if provided. */
Expand Down
4 changes: 2 additions & 2 deletions source/include/core_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -902,9 +902,9 @@ uint16_t MQTT_GetPacketId( MQTTContext_t * pContext );
* @endcode
*/
MQTTStatus_t MQTT_MatchTopic( const char * pTopicName,
const uint16_t topicNameLength,
const size_t topicNameLength,
const char * pTopicFilter,
const uint16_t topicFilterLength,
const size_t topicFilterLength,
bool * pIsMatch );

/**
Expand Down
12 changes: 6 additions & 6 deletions source/include/core_mqtt_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ typedef struct MQTTConnectInfo
/**
* @brief MQTT keep alive period.
*/
uint16_t keepAliveSeconds;
size_t keepAliveSeconds;

/**
* @brief MQTT client identifier. Must be unique per client.
Expand All @@ -161,7 +161,7 @@ typedef struct MQTTConnectInfo
/**
* @brief Length of the client identifier.
*/
uint16_t clientIdentifierLength;
size_t clientIdentifierLength;

/**
* @brief MQTT user name. Set to NULL if not used.
Expand All @@ -171,7 +171,7 @@ typedef struct MQTTConnectInfo
/**
* @brief Length of MQTT user name. Set to 0 if not used.
*/
uint16_t userNameLength;
size_t userNameLength;

/**
* @brief MQTT password. Set to NULL if not used.
Expand All @@ -181,7 +181,7 @@ typedef struct MQTTConnectInfo
/**
* @brief Length of MQTT password. Set to 0 if not used.
*/
uint16_t passwordLength;
size_t passwordLength;
} MQTTConnectInfo_t;

/**
Expand All @@ -203,7 +203,7 @@ typedef struct MQTTSubscribeInfo
/**
* @brief Length of subscription topic filter.
*/
uint16_t topicFilterLength;
size_t topicFilterLength;
} MQTTSubscribeInfo_t;

/**
Expand Down Expand Up @@ -235,7 +235,7 @@ typedef struct MQTTPublishInfo
/**
* @brief Length of topic name.
*/
uint16_t topicNameLength;
size_t topicNameLength;

/**
* @brief Message payload.
Expand Down