Commit 2912e2b9 authored by Ian Craggs's avatar Ian Craggs

Fix compile warnings in 64 bit builds & make debug builds work properly

Bug: 480160, 443722
parent ddc08ce8
......@@ -85,12 +85,16 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_WINDOWS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)\..\src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)\Debug\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;paho-mqtt3c.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
......@@ -99,14 +103,16 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_WINDOWS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)\..\src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)\x64\$(Configuration)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;paho-mqtt3c.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......
......@@ -85,12 +85,16 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_WINDOWS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)\..\src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)..\build\output\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;paho-mqtt3cs.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
......@@ -99,14 +103,16 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_WINDOWS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)\..\src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)\x64\$(Configuration)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;paho-mqtt3cs.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......
......@@ -85,12 +85,16 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_WINDOWS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)\..\src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)..\build\output\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;paho-mqtt3a.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
......@@ -99,13 +103,16 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_WINDOWS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)\..\src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)\x64\$(Configuration)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;paho-mqtt3a.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......
......@@ -85,12 +85,16 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;_WINDOWS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)\..\src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)..\build\output\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;paho-mqtt3as.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
......@@ -99,13 +103,16 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;_WINDOWS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)\..\src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)\x64\$(Configuration)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;paho-mqtt3as.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......
......@@ -62,7 +62,7 @@ typedef struct
char* file; /**< the name of the source file where the storage was allocated */
int line; /**< the line no in the source file where it was allocated */
void* ptr; /**< pointer to the allocated storage */
int size; /**< size of the allocated storage */
size_t size; /**< size of the allocated storage */
} storageElement;
static Tree heap; /**< Tree that holds the allocation records */
......@@ -75,7 +75,7 @@ static char* errmsg = "Memory allocation error";
* @param size the size actually needed
* @return the rounded up size
*/
int Heap_roundup(int size)
size_t Heap_roundup(size_t size)
{
static int multsize = 4*sizeof(int);
......@@ -139,8 +139,8 @@ void Heap_check(char* string, void* ptr)
void* mymalloc(char* file, int line, size_t size)
{
storageElement* s = NULL;
int space = sizeof(storageElement);
int filenamelen = strlen(file)+1;
size_t space = sizeof(storageElement);
size_t filenamelen = strlen(file)+1;
Thread_lock_mutex(heap_mutex);
size = Heap_roundup(size);
......@@ -180,7 +180,7 @@ void* mymalloc(char* file, int line, size_t size)
}
void checkEyecatchers(char* file, int line, void* p, int size)
void checkEyecatchers(char* file, int line, void* p, size_t size)
{
int *sp = (int*)p;
char *cp = (char*)p;
......@@ -282,8 +282,8 @@ void *myrealloc(char* file, int line, void* p, size_t size)
Log(LOG_ERROR, 13, "Failed to reallocate heap item at file %s line %d", file, line);
else
{
int space = sizeof(storageElement);
int filenamelen = strlen(file)+1;
size_t space = sizeof(storageElement);
size_t filenamelen = strlen(file)+1;
checkEyecatchers(file, line, p, s->size);
size = Heap_roundup(size);
......@@ -393,7 +393,7 @@ heap_info* Heap_get_info()
int HeapDumpString(FILE* file, char* str)
{
int rc = 0;
int len = str ? strlen(str) + 1 : 0; /* include the trailing null */
size_t len = str ? strlen(str) + 1 : 0; /* include the trailing null */
if (fwrite(&(str), sizeof(char*), 1, file) != 1)
rc = -1;
......
......@@ -56,8 +56,8 @@
*/
typedef struct
{
int current_size; /**< current size of the heap in bytes */
int max_size; /**< max size the heap has reached in bytes */
size_t current_size; /**< current size of the heap in bytes */
size_t max_size; /**< max size the heap has reached in bytes */
} heap_info;
......
......@@ -67,7 +67,7 @@ List* ListInitialize(void)
* @param newel the ListElement to be used in adding the new item
* @param size the size of the element
*/
void ListAppendNoMalloc(List* aList, void* content, ListElement* newel, int size)
void ListAppendNoMalloc(List* aList, void* content, ListElement* newel, size_t size)
{ /* for heap use */
newel->content = content;
newel->next = NULL;
......@@ -88,7 +88,7 @@ void ListAppendNoMalloc(List* aList, void* content, ListElement* newel, int size
* @param content the list item content itself
* @param size the size of the element
*/
void ListAppend(List* aList, void* content, int size)
void ListAppend(List* aList, void* content, size_t size)
{
ListElement* newel = malloc(sizeof(ListElement));
ListAppendNoMalloc(aList, content, newel, size);
......@@ -103,7 +103,7 @@ void ListAppend(List* aList, void* content, int size)
* @param index the position in the list. If NULL, this function is equivalent
* to ListAppend.
*/
void ListInsert(List* aList, void* content, int size, ListElement* index)
void ListInsert(List* aList, void* content, size_t size, ListElement* index)
{
ListElement* newel = malloc(sizeof(ListElement));
......@@ -359,7 +359,8 @@ void ListEmpty(List* aList)
aList->first = first->next;
free(first);
}
aList->count = aList->size = 0;
aList->count = 0;
aList->size = 0;
aList->current = aList->first = aList->last = NULL;
}
......
......@@ -13,11 +13,14 @@
* Contributors:
* Ian Craggs - initial API and implementation and/or initial documentation
* Ian Craggs - updates for the async client
* Ian Craggs - change size types from int to size_t
*******************************************************************************/
#if !defined(LINKEDLIST_H)
#define LINKEDLIST_H
#include <stdlib.h> // for size_t definition
/*BE
defm defList(T)
......@@ -66,16 +69,16 @@ typedef struct
ListElement *first, /**< first element in the list */
*last, /**< last element in the list */
*current; /**< current element in the list, for iteration */
int count, /**< no of items */
size; /**< heap storage used */
int count; /**< no of items */
size_t size; /**< heap storage used */
} List;
void ListZero(List*);
List* ListInitialize(void);
void ListAppend(List* aList, void* content, int size);
void ListAppendNoMalloc(List* aList, void* content, ListElement* newel, int size);
void ListInsert(List* aList, void* content, int size, ListElement* index);
void ListAppend(List* aList, void* content, size_t size);
void ListAppendNoMalloc(List* aList, void* content, ListElement* newel, size_t size);
void ListInsert(List* aList, void* content, size_t size, ListElement* index);
int ListRemove(List* aList, void* content);
int ListRemoveItem(List* aList, void* content, int(*callback)(void*, void*));
......
......@@ -489,7 +489,7 @@ int MQTTAsync_persistCommand(MQTTAsync_queuedCommand* qcmd)
int rc = 0;
MQTTAsyncs* aclient = qcmd->client;
MQTTAsync_command* command = &qcmd->command;
int* lens = NULL;
size_t* lens = NULL;
void** bufs = NULL;
int bufindex = 0, i, nbufs = 0;
char key[PERSISTENCE_MAX_KEY_LENGTH + 1];
......@@ -500,7 +500,7 @@ int MQTTAsync_persistCommand(MQTTAsync_queuedCommand* qcmd)
case SUBSCRIBE:
nbufs = 3 + (command->details.sub.count * 2);
lens = (int*)malloc(nbufs * sizeof(int));
lens = (size_t*)malloc(nbufs * sizeof(int));
bufs = malloc(nbufs * sizeof(char *));
bufs[bufindex] = &command->type;
......@@ -525,7 +525,7 @@ int MQTTAsync_persistCommand(MQTTAsync_queuedCommand* qcmd)
case UNSUBSCRIBE:
nbufs = 3 + command->details.unsub.count;
lens = (int*)malloc(nbufs * sizeof(int));
lens = (size_t*)malloc(nbufs * sizeof(size_t));
bufs = malloc(nbufs * sizeof(char *));
bufs[bufindex] = &command->type;
......@@ -548,7 +548,7 @@ int MQTTAsync_persistCommand(MQTTAsync_queuedCommand* qcmd)
case PUBLISH:
nbufs = 7;
lens = (int*)malloc(nbufs * sizeof(int));
lens = (size_t*)malloc(nbufs * sizeof(size_t));
bufs = malloc(nbufs * sizeof(char *));
bufs[bufindex] = &command->type;
......@@ -577,7 +577,7 @@ int MQTTAsync_persistCommand(MQTTAsync_queuedCommand* qcmd)
}
if (nbufs > 0)
{
if ((rc = aclient->c->persistence->pput(aclient->c->phandle, key, nbufs, (char**)bufs, lens)) != 0)
if ((rc = aclient->c->persistence->pput(aclient->c->phandle, key, nbufs, (char**)bufs, (int*)lens)) != 0)
Log(LOG_ERROR, 0, "Error persisting command, rc %d", rc);
qcmd->seqno = aclient->command_seqno;
}
......@@ -595,7 +595,8 @@ MQTTAsync_queuedCommand* MQTTAsync_restoreCommand(char* buffer, int buflen)
MQTTAsync_command* command = NULL;
MQTTAsync_queuedCommand* qcommand = NULL;
char* ptr = buffer;
int i, data_size;
int i;
size_t data_size;
FUNC_ENTRY;
qcommand = malloc(sizeof(MQTTAsync_queuedCommand));
......@@ -633,7 +634,7 @@ MQTTAsync_queuedCommand* MQTTAsync_restoreCommand(char* buffer, int buflen)
for (i = 0; i < command->details.unsub.count; ++i)
{
int data_size = strlen(ptr) + 1;
size_t data_size = strlen(ptr) + 1;
command->details.unsub.topics[i] = malloc(data_size);
strcpy(command->details.unsub.topics[i], ptr);
......@@ -1877,7 +1878,7 @@ int MQTTAsync_deliverMessage(MQTTAsyncs* m, char* topicName, size_t topicLen, MQ
Log(TRACE_MIN, -1, "Calling messageArrived for client %s, queue depth %d",
m->c->clientID, m->c->messageQueue->count);
rc = (*(m->ma))(m->context, topicName, topicLen, mm);
rc = (*(m->ma))(m->context, topicName, (int)topicLen, mm);
/* if 0 (false) is returned by the callback then it failed, so we don't remove the message from
* the queue, and it will be retried later. If 1 is returned then the message data may have been freed,
* so we must be careful how we use it.
......
......@@ -96,10 +96,10 @@ void* MQTTPacket_Factory(networkHandles* net, int* error)
{
char* data = NULL;
static Header header;
int remaining_length, ptype;
size_t remaining_length_new;
size_t remaining_length;
int ptype;
void* pack = NULL;
int actual_len = 0;
size_t actual_len = 0;
FUNC_ENTRY;
*error = SOCKET_ERROR; /* indicate whether an error occurred, or not */
......@@ -148,9 +148,8 @@ void* MQTTPacket_Factory(networkHandles* net, int* error)
char *buf = malloc(10);
buf[0] = header.byte;
buf0len = 1 + MQTTPacket_encode(&buf[1], remaining_length);
remaining_length_new = remaining_length;
*error = MQTTPersistence_put(net->socket, buf, buf0len, 1,
&data, &remaining_length_new, header.bits.type, ((Publish *)pack)->msgId, 1);
&data, &remaining_length, header.bits.type, ((Publish *)pack)->msgId, 1);
free(buf);
}
#endif
......@@ -174,7 +173,8 @@ exit:
*/
int MQTTPacket_send(networkHandles* net, Header header, char* buffer, size_t buflen, int free)
{
int rc, buf0len;
int rc;
size_t buf0len;
char *buf;
FUNC_ENTRY;
......@@ -220,7 +220,8 @@ int MQTTPacket_send(networkHandles* net, Header header, char* buffer, size_t buf
*/
int MQTTPacket_sends(networkHandles* net, Header header, int count, char** buffers, size_t* buflens, int* frees)
{
int i, rc, buf0len, total = 0;
int i, rc;
size_t buf0len, total = 0;
char *buf;
FUNC_ENTRY;
......@@ -261,7 +262,7 @@ int MQTTPacket_sends(networkHandles* net, Header header, int count, char** buffe
* @param length the length to be encoded
* @return the number of bytes written to buffer
*/
int MQTTPacket_encode(char* buf, int length)
int MQTTPacket_encode(char* buf, size_t length)
{
int rc = 0;
......@@ -286,7 +287,7 @@ int MQTTPacket_encode(char* buf, int length)
* @param value the decoded length returned
* @return the number of bytes read from the socket
*/
int MQTTPacket_decode(networkHandles* net, int* value)
int MQTTPacket_decode(networkHandles* net, size_t* value)
{
int rc = SOCKET_ERROR;
char c;
......@@ -429,8 +430,8 @@ void writeInt(char** pptr, int anInt)
*/
void writeUTF(char** pptr, const char* string)
{
int len = strlen(string);
writeInt(pptr, len);
size_t len = strlen(string);
writeInt(pptr, (int)len);
memcpy(*pptr, string, len);
*pptr += len;
}
......@@ -497,7 +498,7 @@ void* MQTTPacket_publish(unsigned char aHeader, char* data, size_t datalen)
else
pack->msgId = 0;
pack->payload = curdata;
pack->payloadlen = datalen-(curdata-data);
pack->payloadlen = (int)(datalen-(curdata-data));
exit:
FUNC_EXIT;
return pack;
......@@ -691,7 +692,7 @@ int MQTTPacket_send_publish(Publish* pack, int dup, int qos, int retained, netwo
writeInt(&ptr, pack->msgId);
ptr = topiclen;
writeInt(&ptr, lens[1]);
writeInt(&ptr, (int)lens[1]);
rc = MQTTPacket_sends(net, header, 4, bufs, lens, frees);
if (rc != TCPSOCKET_INTERRUPTED)
free(buf);
......@@ -703,7 +704,7 @@ int MQTTPacket_send_publish(Publish* pack, int dup, int qos, int retained, netwo
size_t lens[3] = {2, strlen(pack->topic), pack->payloadlen};
int frees[3] = {1, 0, 0};
writeInt(&ptr, lens[1]);
writeInt(&ptr, (int)lens[1]);
rc = MQTTPacket_sends(net, header, 3, bufs, lens, frees);
}
if (rc != TCPSOCKET_INTERRUPTED)
......
......@@ -216,8 +216,8 @@ typedef Ack Pubrel;
typedef Ack Pubcomp;
typedef Ack Unsuback;
int MQTTPacket_encode(char* buf, int length);
int MQTTPacket_decode(networkHandles* net, int* value);
int MQTTPacket_encode(char* buf, size_t length);
int MQTTPacket_decode(networkHandles* net, size_t* value);
int readInt(char** pptr);
char* readUTF(char** pptr, char* enddata);
unsigned char readChar(char** pptr);
......
......@@ -51,13 +51,13 @@ int MQTTPacket_send_connect(Clients* client, int MQTTVersion)
packet.header.byte = 0;
packet.header.bits.type = CONNECT;
len = ((MQTTVersion == 3) ? 12 : 10) + strlen(client->clientID)+2;
len = ((MQTTVersion == 3) ? 12 : 10) + (int)strlen(client->clientID)+2;
if (client->will)
len += strlen(client->will->topic)+2 + strlen(client->will->msg)+2;
len += (int)strlen(client->will->topic)+2 + (int)strlen(client->will->msg)+2;
if (client->username)
len += strlen(client->username)+2;
len += (int)strlen(client->username)+2;
if (client->password)
len += strlen(client->password)+2;
len += (int)strlen(client->password)+2;
ptr = buf = malloc(len);
if (MQTTVersion == 3)
......@@ -179,7 +179,7 @@ int MQTTPacket_send_subscribe(List* topics, List* qoss, int msgid, int dup, netw
datalen = 2 + topics->count * 3; // utf length + char qos == 3
while (ListNextElement(topics, &elem))
datalen += strlen((char*)(elem->content));
datalen += (int)strlen((char*)(elem->content));
ptr = data = malloc(datalen);
writeInt(&ptr, msgid);
......@@ -252,7 +252,7 @@ int MQTTPacket_send_unsubscribe(List* topics, int msgid, int dup, networkHandles
datalen = 2 + topics->count * 2; // utf length == 2
while (ListNextElement(topics, &elem))
datalen += strlen((char*)(elem->content));
datalen += (int)strlen((char*)(elem->content));
ptr = data = malloc(datalen);
writeInt(&ptr, msgid);
......
......@@ -350,13 +350,13 @@ int MQTTPersistence_put(int socket, char* buf0, size_t buf0len, int count,
{
key = malloc(MESSAGE_FILENAME_LENGTH + 1);
nbufs = 1 + count;
lens = (int *) malloc(nbufs * sizeof(int));
lens = (int *)malloc(nbufs * sizeof(int));
bufs = (char **)malloc(nbufs * sizeof(char *));
lens[0] = buf0len;
lens[0] = (int)buf0len;
bufs[0] = buf0;
for (i = 0; i < count; i++)
{
lens[i+1] = buflens[i];
lens[i+1] = (int)buflens[i];
bufs[i+1] = buffers[i];
}
......@@ -512,7 +512,7 @@ int MQTTPersistence_persistQueueEntry(Clients* aclient, MQTTPersistence_qEntry*
lens[bufindex++] = sizeof(qe->msg->msgid);
bufs[bufindex] = qe->topicName;
lens[bufindex++] = strlen(qe->topicName) + 1;
lens[bufindex++] = (int)strlen(qe->topicName) + 1;
bufs[bufindex] = &qe->topicLen;
lens[bufindex++] = sizeof(qe->topicLen);
......@@ -564,7 +564,7 @@ MQTTPersistence_qEntry* MQTTPersistence_restoreQueueEntry(char* buffer, size_t b
qe->msg->msgid = *(int*)ptr;
ptr += sizeof(int);
data_size = strlen(ptr) + 1;
data_size = (int)strlen(ptr) + 1;
qe->topicName = malloc(data_size);
strcpy(qe->topicName, ptr);
ptr += data_size;
......
......@@ -148,8 +148,8 @@ int pstput(void* handle, char* key, int bufcount, char* buffers[], int buflens[]
char *clientDir = handle;
char *file;
FILE *fp;
int bytesWritten = 0;
int bytesTotal = 0;
size_t bytesWritten = 0,
bytesTotal = 0;
int i;
FUNC_ENTRY;
......@@ -169,14 +169,14 @@ int pstput(void* handle, char* key, int bufcount, char* buffers[], int buflens[]
for(i=0; i<bufcount; i++)
{
bytesTotal += buflens[i];
bytesWritten += fwrite( buffers[i], sizeof(char), buflens[i], fp );
bytesWritten += fwrite(buffers[i], sizeof(char), buflens[i], fp );
}
fclose(fp);
fp = NULL;
} else
rc = MQTTCLIENT_PERSISTENCE_ERROR;
if ( bytesWritten != bytesTotal )
if (bytesWritten != bytesTotal)
{
pstremove(handle, key);
rc = MQTTCLIENT_PERSISTENCE_ERROR;
......@@ -221,7 +221,7 @@ int pstget(void* handle, char* key, char** buffer, int* buflen)
fileLen = ftell(fp);
fseek(fp, 0, SEEK_SET);
buf=(char *)malloc(fileLen);
bytesRead = fread(buf, sizeof(char), fileLen, fp);
bytesRead = (int)fread(buf, sizeof(char), fileLen, fp);
*buffer = buf;
*buflen = bytesRead;
if ( bytesRead != fileLen )
......
......@@ -210,7 +210,7 @@ Publications* MQTTProtocol_storePublication(Publish* publish, int* len)
FUNC_ENTRY;
p->refcount = 1;
*len = strlen(publish->topic)+1;
*len = (int)strlen(publish->topic)+1;
if (Heap_findItem(publish->topic))
p->topic = publish->topic;
else
......
......@@ -45,7 +45,7 @@ char* MQTTProtocol_addressPort(const char* uri, int* port)
{
char* colon_pos = strrchr(uri, ':'); /* reverse find to allow for ':' in IPv6 addresses */
char* buf = (char*)uri;
int len;
size_t len;
FUNC_ENTRY;
if (uri[0] == '[')
......@@ -56,7 +56,7 @@ char* MQTTProtocol_addressPort(const char* uri, int* port)
if (colon_pos)
{
int addr_len = colon_pos - uri;
size_t addr_len = colon_pos - uri;
buf = malloc(addr_len + 1);
*port = atoi(colon_pos + 1);
MQTTStrncpy(buf, uri, addr_len+1);
......
......@@ -71,7 +71,7 @@ char* FindString(char* filename, char* eyecatcher_input)
memset(value, 0, 100);
if ((infile = fopen(filename, "rb")) != NULL)
{
int buflen = strlen(eyecatcher);
size_t buflen = strlen(eyecatcher);
char* buffer = (char*) malloc(buflen);
int count = 0;
int c = fgetc(infile);
......
......@@ -295,7 +295,7 @@ int pem_passwd_cb(char* buf, int size, int rwflag, void* userdata)
{
strncpy(buf, (char*)(userdata), size);
buf[size-1] = '\0';
rc = strlen(buf);
rc = (int)strlen(buf);
}
FUNC_EXIT_RC(rc);
return rc;
......@@ -642,7 +642,7 @@ exit:
* @param actual_len the actual number of bytes read
* @return completion code
*/
char *SSLSocket_getdata(SSL* ssl, int socket, int bytes, int* actual_len)
char *SSLSocket_getdata(SSL* ssl, int socket, size_t bytes, size_t* actual_len)
{
int rc;
char* buf;
......@@ -656,7 +656,7 @@ char *SSLSocket_getdata(SSL* ssl, int socket, int bytes, int* actual_len)
buf = SocketBuffer_getQueuedData(socket, bytes, actual_len);
if ((rc = SSL_read(ssl, buf + (*actual_len), (size_t)(bytes - (*actual_len)))) < 0)
if ((rc = SSL_read(ssl, buf + (*actual_len), (int)(bytes - (*actual_len)))) < 0)
{
rc = SSLSocket_error("SSL_read - getdata", ssl, socket, rc);
if (rc != SSL_ERROR_WANT_READ && rc != SSL_ERROR_WANT_WRITE)
......@@ -728,9 +728,9 @@ int SSLSocket_putdatas(SSL* ssl, int socket, char* buf0, size_t buf0len, int cou
int sslerror;
FUNC_ENTRY;
iovec.iov_len = buf0len;
iovec.iov_len = (ULONG)buf0len;
for (i = 0; i < count; i++)
iovec.iov_len += buflens[i];
iovec.iov_len += (ULONG)buflens[i];
ptr = iovec.iov_base = (char *)malloc(iovec.iov_len);
memcpy(ptr, buf0, buf0len);
......
......@@ -34,7 +34,7 @@ int SSLSocket_initialize();
void SSLSocket_terminate();
int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts);
int SSLSocket_getch(SSL* ssl, int socket, char* c);
char *SSLSocket_getdata(SSL* ssl, int socket, int bytes, int* actual_len);
char *SSLSocket_getdata(SSL* ssl, int socket, size_t bytes, size_t* actual_len);
int SSLSocket_close(networkHandles* net);
int SSLSocket_putdatas(SSL* ssl, int socket, char* buf0, size_t buf0len, int count, char** buffers, size_t* buflens, int* frees);
......
......@@ -328,7 +328,7 @@ exit:
* @param actual_len the actual number of bytes read
* @return completion code
*/
char *Socket_getdata(int socket, int bytes, int* actual_len)
char *Socket_getdata(int socket, size_t bytes, size_t* actual_len)
{
int rc;
char* buf;
......@@ -342,7 +342,7 @@ char *Socket_getdata(int socket, int bytes, int* actual_len)
buf = SocketBuffer_getQueuedData(socket, bytes, actual_len);
if ((rc = recv(socket, buf + (*actual_len), (size_t)(bytes - (*actual_len)), 0)) == SOCKET_ERROR)
if ((rc = recv(socket, buf + (*actual_len), (int)(bytes - (*actual_len)), 0)) == SOCKET_ERROR)
{
rc = Socket_error("recv - getdata", socket);
if (rc != EAGAIN && rc != EWOULDBLOCK)
......@@ -438,7 +438,8 @@ int Socket_putdatas(int socket, char* buf0, size_t buf0len, int count, char** bu
unsigned long bytes = 0L;
iobuf iovecs[5];
int frees1[5];
int rc = TCPSOCKET_INTERRUPTED, i, total = buf0len;
int rc = TCPSOCKET_INTERRUPTED, i;
size_t total = buf0len;
FUNC_ENTRY;
if (!Socket_noPendingWrites(socket))
......@@ -452,12 +453,12 @@ int Socket_putdatas(int socket, char* buf0, size_t buf0len, int count, char** bu
total += buflens[i];
iovecs[0].iov_base = buf0;
iovecs[0].iov_len = buf0len;
iovecs[0].iov_len = (ULONG)buf0len;
frees1[0] = 1;
for (i = 0; i < count; i++)
{
iovecs[i+1].iov_base = buffers[i];
iovecs[i+1].iov_len = buflens[i];
iovecs[i+1].iov_len = (ULONG)buflens[i];
frees1[i+1] = frees[i];
}
......@@ -649,7 +650,7 @@ int Socket_new(char* addr, int port, int* sock)
Log(LOG_ERROR, -1, "%s is not a valid IP address", addr);
else
{
*sock = socket(family, type, 0);
*sock = (int)socket(family, type, 0);
if (*sock == INVALID_SOCKET)
rc = Socket_error("socket", *sock);
else
......@@ -733,8 +734,8 @@ int Socket_continueWrite(int socket)
else if (pw->bytes < curbuflen + pw->iovecs[i].iov_len)
{ /* if previously written length is in the middle of the buffer we are currently looking at,
add some of the buffer */
int offset = pw->bytes - curbuflen;
iovecs1[++curbuf].iov_len = pw->iovecs[i].iov_len - offset;
size_t offset = pw->bytes - curbuflen;
iovecs1[++curbuf].iov_len = pw->iovecs[i].iov_len - (ULONG)offset;
iovecs1[curbuf].iov_base = pw->iovecs[i].iov_base + offset;
break;
}
......
......@@ -51,6 +51,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/uio.h>
#define ULONG size_t
#endif
/** socket operation completed successfully */
......@@ -114,7 +115,7 @@ void Socket_outInitialize(void);
void Socket_outTerminate(void);
int Socket_getReadySocket(int more_work, struct timeval *tp);
int Socket_getch(int socket, char* c);
char *Socket_getdata(int socket, int bytes, int* actual_len);
char *Socket_getdata(int socket, size_t bytes, size_t* actual_len);
int Socket_putdatas(int socket, char* buf0, size_t buf0len, int count, char** buffers, size_t* buflens, int* frees);
void Socket_close(int socket);
int Socket_new(char* addr, int port, int* socket);
......
......@@ -73,7 +73,8 @@ void SocketBuffer_newDefQ(void)
def_queue = malloc(sizeof(socket_queue));
def_queue->buflen = 1000;
def_queue->buf = malloc(def_queue->buflen);
def_queue->socket = def_queue->index = def_queue->buflen = def_queue->datalen = 0;
def_queue->socket = def_queue->index = 0;
def_queue->buflen = def_queue->datalen = 0;
}
......@@ -130,7 +131,10 @@ void SocketBuffer_cleanup(int socket)
ListRemove(queues, queues->current->content);
}
if (def_queue->socket == socket)
def_queue->socket = def_queue->index = def_queue->headerlen = def_queue->datalen = 0;
{
def_queue->socket = def_queue->index = 0;
def_queue->headerlen = def_queue->datalen = 0;
}
FUNC_EXIT;
}
......@@ -142,7 +146,7 @@ void SocketBuffer_cleanup(int socket)
* @param actual_len the actual length returned
* @return the actual data
*/
char* SocketBuffer_getQueuedData(int socket, int bytes, int* actual_len)
char* SocketBuffer_getQueuedData(int socket, size_t bytes, size_t* actual_len)
{
socket_queue* queue = NULL;
......@@ -215,7 +219,7 @@ exit:
* @param socket the socket to get queued data for
* @param actual_len the actual length of data that was read
*/
void SocketBuffer_interrupted(int socket, int actual_len)
void SocketBuffer_interrupted(int socket, size_t actual_len)
{
socket_queue* queue = NULL;
......@@ -249,7 +253,8 @@ char* SocketBuffer_complete(int socket)
def_queue = queue;
ListDetach(queues, queue);
}
def_queue->socket = def_queue->index = def_queue->headerlen = def_queue->datalen = 0;
def_queue->socket = def_queue->index = 0;
def_queue->headerlen = def_queue->datalen = 0;
FUNC_EXIT;
return def_queue->buf;
}
......@@ -271,7 +276,8 @@ void SocketBuffer_queueChar(int socket, char c)
else if (def_queue->socket == 0)
{
def_queue->socket = socket;
def_queue->index = def_queue->datalen = 0;
def_queue->index = 0;
def_queue->datalen = 0;
}
else if (def_queue->socket != socket)
{
......@@ -302,9 +308,9 @@ void SocketBuffer_queueChar(int socket, char c)
* @param bytes actual data length that was written
*/
#if defined(OPENSSL)
void SocketBuffer_pendingWrite(int socket, SSL* ssl, int count, iobuf* iovecs, int* frees, int total, int bytes)
void SocketBuffer_pendingWrite(int socket, SSL* ssl, int count, iobuf* iovecs, int* frees, size_t total, size_t bytes)
#else
void SocketBuffer_pendingWrite(int socket, int count, iobuf* iovecs, int* frees, int total, int bytes)
void SocketBuffer_pendingWrite(int socket, int count, iobuf* iovecs, int* frees, size_t total, size_t bytes)
#endif
{
int i = 0;
......
......@@ -37,20 +37,22 @@
typedef struct
{
int socket;
int index, headerlen;
unsigned int index;
size_t headerlen;
char fixed_header[5]; /**< header plus up to 4 length bytes */
int buflen, /**< total length of the buffer */
size_t buflen, /**< total length of the buffer */
datalen; /**< current length of data in buf */
char* buf;
} socket_queue;
typedef struct
{
int socket, total, count;
int socket, count;
size_t total;
#if defined(OPENSSL)
SSL* ssl;
#endif
unsigned long bytes;
size_t bytes;
iobuf iovecs[5];
int frees[5];
} pending_writes;
......@@ -64,16 +66,16 @@ typedef struct
void SocketBuffer_initialize(void);
void SocketBuffer_terminate(void);
void SocketBuffer_cleanup(int socket);
char* SocketBuffer_getQueuedData(int socket, int bytes, int* actual_len);
char* SocketBuffer_getQueuedData(int socket, size_t bytes, size_t* actual_len);
int SocketBuffer_getQueuedChar(int socket, char* c);
void SocketBuffer_interrupted(int socket, int actual_len);
void SocketBuffer_interrupted(int socket, size_t actual_len);
char* SocketBuffer_complete(int socket);
void SocketBuffer_queueChar(int socket, char c);
#if defined(OPENSSL)
void SocketBuffer_pendingWrite(int socket, SSL* ssl, int count, iobuf* iovecs, int* frees, int total, int bytes);
void SocketBuffer_pendingWrite(int socket, SSL* ssl, int count, iobuf* iovecs, int* frees, size_t total, size_t bytes);
#else
void SocketBuffer_pendingWrite(int socket, int count, iobuf* iovecs, int* frees, int total, int bytes);
void SocketBuffer_pendingWrite(int socket, int count, iobuf* iovecs, int* frees, size_t total, size_t bytes);
#endif
pending_writes* SocketBuffer_getWrite(int socket);
int SocketBuffer_writeComplete(int socket);
......
......@@ -189,7 +189,7 @@ void TreeBalanceAfterAdd(Tree* aTree, Node* curnode, int index)
* @param content the list item content itself
* @param size the size of the element
*/
void* TreeAddByIndex(Tree* aTree, void* content, int size, int index)
void* TreeAddByIndex(Tree* aTree, void* content, size_t size, int index)
{
Node* curparent = NULL;
Node* curnode = aTree->index[index].root;
......@@ -249,7 +249,7 @@ void* TreeAddByIndex(Tree* aTree, void* content, int size, int index)
}
void* TreeAdd(Tree* aTree, void* content, int size)
void* TreeAdd(Tree* aTree, void* content, size_t size)
{
void* rc = NULL;
int i;
......@@ -399,7 +399,7 @@ void* TreeRemoveNodeIndex(Tree* aTree, Node* curnode, int index)
{
Node* redundant = curnode;
Node* curchild = NULL;
int size = curnode->size;
size_t size = curnode->size;
void* content = curnode->content;
/* if the node to remove has 0 or 1 children, it can be removed without involving another node */
......
......@@ -18,6 +18,8 @@
#if !defined(TREE_H)
#define TREE_H
#include <stdlib.h> // for size_t definition
/*BE
defm defTree(T) // macro to define a tree
......@@ -63,7 +65,7 @@ typedef struct NodeStruct
struct NodeStruct *parent, /**< pointer to parent tree node, in case we need it */
*child[2]; /**< pointers to child tree nodes 0 = left, 1 = right */
void* content; /**< pointer to element content */
int size; /**< size of content */
size_t size; /**< size of content */
unsigned int red : 1;
} Node;
......@@ -79,8 +81,8 @@ typedef struct
int (*compare)(void*, void*, int); /**< comparison function */
} index[2];
int indexes, /**< no of indexes into tree */
count, /**< no of items */
size; /**< heap storage used */
count; /**< no of items */
size_t size; /**< heap storage used */
unsigned int heap_tracking : 1; /**< switch on heap tracking for this tree? */
unsigned int allow_duplicates : 1; /**< switch to allow duplicate entries */
} Tree;
......@@ -90,7 +92,7 @@ Tree* TreeInitialize(int(*compare)(void*, void*, int));
void TreeInitializeNoMalloc(Tree* aTree, int(*compare)(void*, void*, int));
void TreeAddIndex(Tree* aTree, int(*compare)(void*, void*, int));
void* TreeAdd(Tree* aTree, void* content, int size);
void* TreeAdd(Tree* aTree, void* content, size_t size);
void* TreeRemove(Tree* aTree, void* content);
......
......@@ -153,7 +153,7 @@ int UTF8_validateString(const char* string)
int rc = 0;
FUNC_ENTRY;
rc = UTF8_validate(strlen(string), string);
rc = UTF8_validate((int)strlen(string), string);
FUNC_EXIT_RC(rc);
return rc;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment