Commit 359a9f4a authored by Ian Craggs's avatar Ian Craggs

Some cppcheck complaint fixes #36

parent 2ac34c25
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <time.h> #include <time.h>
#if defined(OPENSSL) #if defined(OPENSSL)
#if defined(WIN32) || defined(WIN64) #if defined(WIN32) || defined(WIN64)
#include "winsock2.h" #include <winsock2.h>
#endif #endif
#include <openssl/ssl.h> #include <openssl/ssl.h>
#endif #endif
......
...@@ -567,7 +567,7 @@ static int MQTTAsync_unpersistCommand(MQTTAsync_queuedCommand* qcmd) ...@@ -567,7 +567,7 @@ static int MQTTAsync_unpersistCommand(MQTTAsync_queuedCommand* qcmd)
char key[PERSISTENCE_MAX_KEY_LENGTH + 1]; char key[PERSISTENCE_MAX_KEY_LENGTH + 1];
FUNC_ENTRY; FUNC_ENTRY;
sprintf(key, "%s%d", PERSISTENCE_COMMAND_KEY, qcmd->seqno); sprintf(key, "%s%u", PERSISTENCE_COMMAND_KEY, qcmd->seqno);
if ((rc = qcmd->client->c->persistence->premove(qcmd->client->c->phandle, key)) != 0) if ((rc = qcmd->client->c->persistence->premove(qcmd->client->c->phandle, key)) != 0)
Log(LOG_ERROR, 0, "Error %d removing command from persistence", rc); Log(LOG_ERROR, 0, "Error %d removing command from persistence", rc);
FUNC_EXIT_RC(rc); FUNC_EXIT_RC(rc);
......
...@@ -1229,9 +1229,9 @@ DLLExport MQTTAsync_nameValue* MQTTAsync_getVersionInfo(void); ...@@ -1229,9 +1229,9 @@ DLLExport MQTTAsync_nameValue* MQTTAsync_getVersionInfo(void);
* @page publish Publication example * @page publish Publication example
@code @code
#include "stdio.h" #include <stdio.h>
#include "stdlib.h" #include <stdlib.h>
#include "string.h" #include <string.h>
#include "MQTTAsync.h" #include "MQTTAsync.h"
#define ADDRESS "tcp://localhost:1883" #define ADDRESS "tcp://localhost:1883"
...@@ -1364,9 +1364,9 @@ int main(int argc, char* argv[]) ...@@ -1364,9 +1364,9 @@ int main(int argc, char* argv[])
* @endcode * @endcode
* @page subscribe Subscription example * @page subscribe Subscription example
@code @code
#include "stdio.h" #include <stdio.h>
#include "stdlib.h" #include <stdlib.h>
#include "string.h" #include <string.h>
#include "MQTTAsync.h" #include "MQTTAsync.h"
#define ADDRESS "tcp://localhost:1883" #define ADDRESS "tcp://localhost:1883"
......
...@@ -1054,9 +1054,9 @@ DLLExport void MQTTClient_destroy(MQTTClient* handle); ...@@ -1054,9 +1054,9 @@ DLLExport void MQTTClient_destroy(MQTTClient* handle);
* of messages occurs. * of messages occurs.
* @page pubsync Synchronous publication example * @page pubsync Synchronous publication example
@code @code
#include "stdio.h" #include <stdio.h>
#include "stdlib.h" #include <stdlib.h>
#include "string.h" #include <string.h>
#include "MQTTClient.h" #include "MQTTClient.h"
#define ADDRESS "tcp://localhost:1883" #define ADDRESS "tcp://localhost:1883"
...@@ -1103,9 +1103,9 @@ int main(int argc, char* argv[]) ...@@ -1103,9 +1103,9 @@ int main(int argc, char* argv[])
* *
* @page pubasync Asynchronous publication example * @page pubasync Asynchronous publication example
@code{.c} @code{.c}
#include "stdio.h" #include <stdio.h>
#include "stdlib.h" #include <stdlib.h>
#include "string.h" #include <string.h>
#include "MQTTClient.h" #include "MQTTClient.h"
#define ADDRESS "tcp://localhost:1883" #define ADDRESS "tcp://localhost:1883"
...@@ -1187,9 +1187,9 @@ int main(int argc, char* argv[]) ...@@ -1187,9 +1187,9 @@ int main(int argc, char* argv[])
* @endcode * @endcode
* @page subasync Asynchronous subscription example * @page subasync Asynchronous subscription example
@code @code
#include "stdio.h" #include <stdio.h>
#include "stdlib.h" #include <stdlib.h>
#include "string.h" #include <string.h>
#include "MQTTClient.h" #include "MQTTClient.h"
#define ADDRESS "tcp://localhost:1883" #define ADDRESS "tcp://localhost:1883"
......
...@@ -479,7 +479,7 @@ int MQTTPersistence_unpersistQueueEntry(Clients* client, MQTTPersistence_qEntry* ...@@ -479,7 +479,7 @@ int MQTTPersistence_unpersistQueueEntry(Clients* client, MQTTPersistence_qEntry*
char key[PERSISTENCE_MAX_KEY_LENGTH + 1]; char key[PERSISTENCE_MAX_KEY_LENGTH + 1];
FUNC_ENTRY; FUNC_ENTRY;
sprintf(key, "%s%d", PERSISTENCE_QUEUE_KEY, qe->seqno); sprintf(key, "%s%u", PERSISTENCE_QUEUE_KEY, qe->seqno);
if ((rc = client->persistence->premove(client->phandle, key)) != 0) if ((rc = client->persistence->premove(client->phandle, key)) != 0)
Log(LOG_ERROR, 0, "Error %d removing qEntry from persistence", rc); Log(LOG_ERROR, 0, "Error %d removing qEntry from persistence", rc);
FUNC_EXIT_RC(rc); FUNC_EXIT_RC(rc);
......
...@@ -99,16 +99,17 @@ int pstopen(void **handle, const char* clientID, const char* serverURI, void* co ...@@ -99,16 +99,17 @@ int pstopen(void **handle, const char* clientID, const char* serverURI, void* co
while ( (pToken != NULL) && (rc == 0) ) while ( (pToken != NULL) && (rc == 0) )
{ {
/* Append the next directory level and try to create it */ /* Append the next directory level and try to create it */
sprintf( pCrtDirName, "%s/%s", pCrtDirName, pToken ); strcat( pCrtDirName, "/" );
strcat( pCrtDirName, pToken );
rc = pstmkdir( pCrtDirName ); rc = pstmkdir( pCrtDirName );
pToken = strtok_r( NULL, "\\/", &save_ptr ); pToken = strtok_r( NULL, "\\/", &save_ptr );
} }
*handle = clientDir; *handle = clientDir;
free(perserverURI);
free(pTokDirName); free(pTokDirName);
free(pCrtDirName); free(pCrtDirName);
free(perserverURI);
FUNC_EXIT_RC(rc); FUNC_EXIT_RC(rc);
return rc; return rc;
......
...@@ -51,12 +51,12 @@ ...@@ -51,12 +51,12 @@
* */ * */
char* libraries[] = {"paho-mqtt3c", "paho-mqtt3cs", "paho-mqtt3a", "paho-mqtt3as"}; static const char* libraries[] = {"paho-mqtt3c", "paho-mqtt3cs", "paho-mqtt3a", "paho-mqtt3as"};
char* eyecatchers[] = {"MQTTAsyncV3_Version", "MQTTAsyncV3_Timestamp", static const char* eyecatchers[] = {"MQTTAsyncV3_Version", "MQTTAsyncV3_Timestamp",
"MQTTClientV3_Version", "MQTTClientV3_Timestamp"}; "MQTTClientV3_Version", "MQTTClientV3_Timestamp"};
char* FindString(char* filename, char* eyecatcher_input); char* FindString(char* filename, const char* eyecatcher_input);
int printVersionInfo(MQTTAsync_nameValue* info); int printVersionInfo(MQTTAsync_nameValue* info);
int loadandcall(char* libname); int loadandcall(char* libname);
void printEyecatchers(char* filename); void printEyecatchers(char* filename);
...@@ -68,43 +68,49 @@ void printEyecatchers(char* filename); ...@@ -68,43 +68,49 @@ void printEyecatchers(char* filename);
* @param eyecatcher_input the eyecatcher string to look for * @param eyecatcher_input the eyecatcher string to look for
* @return the value found - "" if not found * @return the value found - "" if not found
*/ */
char* FindString(char* filename, char* eyecatcher_input) char* FindString(char* filename, const char* eyecatcher_input)
{ {
FILE* infile = NULL; FILE* infile = NULL;
static char value[100]; static char value[100];
char* eyecatcher = eyecatcher_input; const char* eyecatcher = eyecatcher_input;
memset(value, 0, 100); memset(value, 0, 100);
if ((infile = fopen(filename, "rb")) != NULL) if ((infile = fopen(filename, "rb")) != NULL)
{ {
size_t buflen = strlen(eyecatcher); size_t buflen = strlen(eyecatcher);
char* buffer = (char*) malloc(buflen); char* buffer = (char*) malloc(buflen);
int count = 0;
int c = fgetc(infile);
while (feof(infile) == 0) if (buffer != NULL)
{ {
buffer[count++] = c; int c = fgetc(infile);
if (memcmp(eyecatcher, buffer, buflen) == 0)
while (feof(infile) == 0)
{ {
char* ptr = value; int count = 0;
c = fgetc(infile); /* skip space */ buffer[count++] = c;
c = fgetc(infile); if (memcmp(eyecatcher, buffer, buflen) == 0)
while (isprint(c))
{ {
*ptr++ = c; char* ptr = value;
c = fgetc(infile); /* skip space */
c = fgetc(infile); c = fgetc(infile);
while (isprint(c))
{
*ptr++ = c;
c = fgetc(infile);
}
break;
} }
break; if (count == buflen)
} {
if (count == buflen) memmove(buffer, &buffer[1], buflen - 1);
{ count--;
memmove(buffer, &buffer[1], buflen - 1); }
count--; c = fgetc(infile);
} }
c = fgetc(infile); free(buffer);
} }
free(buffer);
fclose(infile);
} }
return value; return value;
} }
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
*******************************************************************************/ *******************************************************************************/
#include "stdio.h" #include <stdio.h>
#include "stdlib.h" #include <stdlib.h>
#include "string.h" #include <string.h>
#include "MQTTAsync.h" #include "MQTTAsync.h"
#if !defined(WIN32) #if !defined(WIN32)
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2012, 2013 IBM Corp. * Copyright (c) 2012, 2017 IBM Corp.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
*******************************************************************************/ *******************************************************************************/
#include "stdio.h" #include <stdio.h>
#include "stdlib.h" #include <stdlib.h>
#include "string.h" #include <string.h>
#include "MQTTAsync.h" #include "MQTTAsync.h"
#if !defined(WIN32) #if !defined(WIN32)
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2012, 2013 IBM Corp. * Copyright (c) 2012, 2017 IBM Corp.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
*******************************************************************************/ *******************************************************************************/
#include "stdio.h" #include <stdio.h>
#include "stdlib.h" #include <stdlib.h>
#include "string.h" #include <string.h>
#include "MQTTClient.h" #include "MQTTClient.h"
#define ADDRESS "tcp://localhost:1883" #define ADDRESS "tcp://localhost:1883"
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2012, 2013 IBM Corp. * Copyright (c) 2012, 2017 IBM Corp.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
*******************************************************************************/ *******************************************************************************/
#include "stdio.h" #include <stdio.h>
#include "stdlib.h" #include <stdlib.h>
#include "string.h" #include <string.h>
#include "MQTTClient.h" #include "MQTTClient.h"
#define ADDRESS "tcp://localhost:1883" #define ADDRESS "tcp://localhost:1883"
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2012, 2013 IBM Corp. * Copyright (c) 2012, 2017 IBM Corp.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
* Ian Craggs - initial contribution * Ian Craggs - initial contribution
*******************************************************************************/ *******************************************************************************/
#include "stdio.h" #include <stdio.h>
#include "stdlib.h" #include <stdlib.h>
#include "string.h" #include <string.h>
#include "MQTTClient.h" #include "MQTTClient.h"
#define ADDRESS "tcp://localhost:1883" #define ADDRESS "tcp://localhost:1883"
......
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