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

Some cppcheck complaint fixes #36

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