Skip to content

Commit

Permalink
Revert "fix: MQTTPacket.c read&write Int/Int4 error" #1336
Browse files Browse the repository at this point in the history
This reverts commit ed07139.
  • Loading branch information
icraggs committed Oct 9, 2023
1 parent d7b8c17 commit 67e3eb6
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/MQTTPacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,10 @@ int MQTTPacket_decode(networkHandles* net, size_t* value)
*/
int readInt(char** pptr)
{
char *ptr = *pptr;
int val = ((((uint32_t)ptr[0]) << 8) | ((uint32_t)ptr[1]));
char* ptr = *pptr;
int len = 256*((unsigned char)(*ptr)) + (unsigned char)(*(ptr+1));
*pptr += 2;
return val;
return len;
}


Expand Down Expand Up @@ -452,10 +452,10 @@ void writeChar(char** pptr, char c)
*/
void writeInt(char** pptr, int anInt)
{
char* ptr = *pptr;
ptr[0] = (uint8_t) ((anInt >> 8) & 0xFF);
ptr[1] = (uint8_t) (anInt & 0xFF);
*pptr += 2;
**pptr = (char)(anInt / 256);
(*pptr)++;
**pptr = (char)(anInt % 256);
(*pptr)++;
}


Expand Down Expand Up @@ -944,28 +944,33 @@ void MQTTPacket_free_packet(MQTTPacket* pack)
*/
void writeInt4(char** pptr, unsigned int anInt)
{
unsigned char* ptr = (unsigned char*)*pptr;
ptr[0] = (uint8_t) ((anInt >> 24) & 0xFF);
ptr[1] = (uint8_t) ((anInt >> 16) & 0xFF);
ptr[2] = (uint8_t) ((anInt >> 8) & 0xFF);
ptr[3] = (uint8_t) (anInt & 0xFF);
*pptr += 4;
**pptr = (char)(anInt / 16777216);
(*pptr)++;
anInt %= 16777216;
**pptr = (char)(anInt / 65536);
(*pptr)++;
anInt %= 65536;
**pptr = (char)(anInt / 256);
(*pptr)++;
**pptr = (char)(anInt % 256);
(*pptr)++;
}


/**
* Calculates an integer from two bytes read from the input buffer
* @param pptr pointer to the input buffer - incremented by the number of bytes
* used & returned
* @param pptr pointer to the input buffer - incremented by the number of bytes used & returned
* @return the integer value calculated
*/
unsigned int readInt4(char** pptr)
{
unsigned char *ptr = (unsigned char *)*pptr;
unsigned int val = ((((uint32_t)ptr[0]) << 24) | (((uint32_t)ptr[1]) << 16) | (((uint32_t)ptr[2]) << 8) | ((uint32_t)ptr[3]));
unsigned char* ptr = (unsigned char*)*pptr;
unsigned int value = 16777216*(*ptr) + 65536*(*(ptr+1)) + 256*(*(ptr+2)) + (*(ptr+3));
*pptr += 4;
return val;
return value;
}


void writeMQTTLenString(char** pptr, MQTTLenString lenstring)
{
writeInt(pptr, lenstring.len);
Expand Down

0 comments on commit 67e3eb6

Please sign in to comment.