- code cleanup; fixed issues from compiler warnings

pull/202/head
Michael Zillgith 6 years ago
parent 6cbadb4b45
commit 8c1b75b382

@ -134,6 +134,7 @@ CFLAGS += -Wnested-externs
CFLAGS += -Wmissing-declarations
CFLAGS += -Wshadow
CFLAGS += -Wall
CGLAGS += -Wextra
#CFLAGS += -Werror
all: lib

@ -26,26 +26,26 @@ static char _dirname[1000];
static char*
dirname(char* path)
{
char* lastSep = NULL;
char* lastSep = NULL;
int len = strlen(path);
int i = 0;
int len = strlen(path);
int i = 0;
while (i < len) {
if (path[i] == '/' || path[i] == ':' || path[i] == '\\')
lastSep = path + i;
while (i < len) {
if (path[i] == '/' || path[i] == ':' || path[i] == '\\')
lastSep = path + i;
i++;
}
i++;
}
if (lastSep) {
strcpy(_dirname, path);
_dirname[lastSep - path] = 0;
}
else
strcpy("", path);
if (lastSep) {
strcpy(_dirname, path);
_dirname[lastSep - path] = 0;
}
else
strcpy(_dirname, "");
return _dirname;
return _dirname;
}
@ -54,24 +54,24 @@ static char _basename[1000];
static char*
basename(char* path)
{
char* lastSep = NULL;
char* lastSep = NULL;
int len = strlen(path);
int i = 0;
int len = strlen(path);
int i = 0;
while (i < len) {
if (path[i] == '/' || path[i] == ':' || path[i] == '\\')
lastSep = path + i;
while (i < len) {
if (path[i] == '/' || path[i] == ':' || path[i] == '\\')
lastSep = path + i;
i++;
}
i++;
}
if (lastSep)
strcpy(_basename, lastSep + 1);
else
strcpy(_basename, path);
if (lastSep)
strcpy(_basename, lastSep + 1);
else
strcpy(_basename, path);
return _basename;
return _basename;
}
#endif

@ -460,7 +460,7 @@ iedConnection_handleReport(IedConnection self, MmsValue* value)
matchingReport->timestamp = MmsValue_getBinaryTimeAsUtcMs(timeStampValue);
if (DEBUG_IED_CLIENT)
printf("IED_CLIENT: report has timestamp %lu\n", matchingReport->timestamp);
printf("IED_CLIENT: report has timestamp %llu\n", (unsigned long long) matchingReport->timestamp);
inclusionIndex++;
}

@ -1925,9 +1925,7 @@ IedConnection_getFile(IedConnection self, IedClientError* error, const char* fil
clientFileReadHandler.retVal = true;
clientFileReadHandler.byteReceived = 0;
bool continueRead = true;
while (continueRead == true) {
while (true) {
bool moreFollows =
MmsConnection_fileRead(self->connection, &mmsError, frsmId, mmsFileReadHandler,
&clientFileReadHandler);

@ -22,6 +22,7 @@
*/
#include "iec61850_common.h"
#include "iec61850_common_internal.h"
#include "libiec61850_platform_includes.h"

@ -2186,7 +2186,10 @@ removeAllGIReportsFromReportBuffer(ReportBuffer* reportBuffer)
reportBuffer->oldestReport = currentReport->next;
}
else {
lastReport->next = currentReport->next;
if (lastReport != NULL)
lastReport->next = currentReport->next;
else
lastReport = currentReport;
}
#if (DEBUG_IED_SERVER == 1)

@ -1261,13 +1261,15 @@ OCTET_STRING_encode_uper(asn_TYPE_descriptor_t *td,
asn_enc_rval_t er;
int ct_extensible = ct->flags & APC_EXTENSIBLE;
int inext = 0; /* Lies not within extension root */
int sizeinunits = st->size;
int sizeinunits;
const uint8_t *buf;
int ret;
if(!st || !st->buf)
_ASN_ENCODE_FAILED;
sizeinunits = st->size;
if(unit_bits == 1) {
sizeinunits = sizeinunits * 8 - (st->bits_unused & 0x07);
}
@ -1387,38 +1389,41 @@ OCTET_STRING_print_utf8(asn_TYPE_descriptor_t *td, const void *sptr,
}
void
OCTET_STRING_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only) {
OCTET_STRING_t *st = (OCTET_STRING_t *)sptr;
asn_OCTET_STRING_specifics_t *specs = td->specifics
? (asn_OCTET_STRING_specifics_t *)td->specifics
: &asn_DEF_OCTET_STRING_specs;
asn_struct_ctx_t *ctx = (asn_struct_ctx_t *)
((char *)st + specs->ctx_offset);
struct _stack *stck;
if(!td || !st)
return;
if(st->buf) {
FREEMEM(st->buf);
}
/*
* Remove decode-time stack.
*/
stck = (struct _stack *)ctx->ptr;
if(stck) {
while(stck->tail) {
struct _stack_el *sel = stck->tail;
stck->tail = sel->prev;
FREEMEM(sel);
}
FREEMEM(stck);
}
if(!contents_only) {
FREEMEM(st);
}
OCTET_STRING_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only)
{
OCTET_STRING_t *st = (OCTET_STRING_t*) sptr;
if ((td == NULL) || (st == NULL))
return;
asn_OCTET_STRING_specifics_t *specs = td->specifics
? (asn_OCTET_STRING_specifics_t*) td->specifics
:
&asn_DEF_OCTET_STRING_specs;
asn_struct_ctx_t *ctx = (asn_struct_ctx_t*)
((char*) st + specs->ctx_offset);
struct _stack *stck;
if (st->buf) {
FREEMEM(st->buf);
}
/*
* Remove decode-time stack.
*/
stck = (struct _stack*) ctx->ptr;
if (stck) {
while (stck->tail) {
struct _stack_el *sel = stck->tail;
stck->tail = sel->prev;
FREEMEM(sel);
}
FREEMEM(stck);
}
if (!contents_only) {
FREEMEM(st);
}
}
/*

@ -964,12 +964,13 @@ CHOICE_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
void
CHOICE_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) {
asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics;
int present;
if(!td || !ptr)
return;
asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics;
int present;
/*
* Figure out which CHOICE element is encoded.
*/

@ -841,7 +841,14 @@ asn_dec_rval_t
SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_dec_rval_t rv;
asn_SET_OF_specifics_t *specs = (asn_SET_OF_specifics_t *)td->specifics;
rv.code = RC_OK;
rv.consumed = 0;
if (td == NULL)
return rv;
asn_SET_OF_specifics_t *specs = (asn_SET_OF_specifics_t *)td->specifics;
asn_TYPE_member_t *elm = td->elements; /* Single one */
void *st = *sptr;
asn_anonymous_set_ *list;
@ -866,7 +873,7 @@ SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
else if(td->per_constraints) ct = &td->per_constraints->size;
else ct = 0;
if(ct && ct->flags & APC_EXTENSIBLE) {
if(ct && (ct->flags & APC_EXTENSIBLE)) {
int value = per_get_few_bits(pd, 1);
if(value < 0) _ASN_DECODE_STARVED;
if(value) ct = 0; /* Not restricted! */
@ -905,8 +912,6 @@ SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
nelems = -1; /* Allow uper_get_length() */
} while(repeat);
rv.code = RC_OK;
rv.consumed = 0;
return rv;
}

@ -1273,7 +1273,8 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
if (bufPos == -1)
goto exit_with_error;
uint32_t invokeId;
bool hasInvokeId = false;
uint32_t invokeId = 0;
while (bufPos < payload->size) {
@ -1291,6 +1292,14 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
goto exit_with_error;
if (extendedTag) {
if (hasInvokeId == false) {
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: invalid message received - missing invoke ID!\n");
goto exit_with_error;
}
switch (nestedTag)
{
@ -1351,6 +1360,8 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: received request with invokeId: %i\n", invokeId);
hasInvokeId = true;
self->lastInvokeId = invokeId;
break;
@ -3376,7 +3387,8 @@ MmsConnection_readJournalTimeRangeAsync(MmsConnection self, MmsError* mmsError,
if ((MmsValue_getType(startTime) != MMS_BINARY_TIME) ||
(MmsValue_getType(endTime) != MMS_BINARY_TIME)) {
*mmsError = MMS_ERROR_INVALID_ARGUMENTS;
if (mmsError)
*mmsError = MMS_ERROR_INVALID_ARGUMENTS;
goto exit_function;
}
@ -3447,7 +3459,8 @@ MmsConnection_readJournalStartAfterAsync(MmsConnection self, MmsError* mmsError,
if ((MmsValue_getType(timeSpecification) != MMS_BINARY_TIME) ||
(MmsValue_getType(entrySpecification) != MMS_OCTET_STRING)) {
*mmsError = MMS_ERROR_INVALID_ARGUMENTS;
if (mmsError)
*mmsError = MMS_ERROR_INVALID_ARGUMENTS;
goto exit_function;
}

@ -244,36 +244,6 @@ mmsMsg_parseDataElement(Data_t* dataElement)
printf("MMS CLIENT: error parsing data element (invalid structure size)!\n");
}
}
else if (dataElement->present == Data_PR_array) {
int componentCount = dataElement->choice.array->list.count;
if (componentCount > 0) {
value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue));
value->type = MMS_ARRAY;
value->value.structure.size = componentCount;
value->value.structure.components = (MmsValue**) GLOBAL_CALLOC(componentCount, sizeof(MmsValue*));
int i;
for (i = 0; i < componentCount; i++) {
value->value.structure.components[i] =
mmsMsg_parseDataElement(dataElement->choice.array->list.array[i]);
if (value->value.structure.components[i] == NULL) {
MmsValue_delete(value);
value = NULL;
break;
}
}
}
else {
if (DEBUG_MMS_CLIENT)
printf("MMS CLIENT: error parsing data element (invalid array size)!\n");
}
}
else {
if (dataElement->present == Data_PR_integer) {

@ -257,10 +257,11 @@ getNameListDomainSpecific(MmsServerConnection connection, char* domainName)
#if (MMS_DATA_SET_SERVICE == 1)
static LinkedList
createStringsFromNamedVariableList(LinkedList nameList, LinkedList variableLists)
createStringsFromNamedVariableList(LinkedList variableLists)
{
nameList = LinkedList_create();
LinkedList nameList = LinkedList_create();
LinkedList variableListsElement = LinkedList_getNext(variableLists);
while (variableListsElement != NULL) {
MmsNamedVariableList variableList =
(MmsNamedVariableList) variableListsElement->data;
@ -285,7 +286,7 @@ getNamedVariableListsDomainSpecific(MmsServerConnection connection, char* domain
if (domain != NULL) {
LinkedList variableLists = MmsDomain_getNamedVariableLists(domain);
nameList = createStringsFromNamedVariableList(nameList, variableLists);
nameList = createStringsFromNamedVariableList(variableLists);
}
return nameList;
@ -300,7 +301,7 @@ getNamedVariableListsVMDSpecific(MmsServerConnection connection)
LinkedList variableLists = MmsDevice_getNamedVariableLists(device);
nameList = createStringsFromNamedVariableList(nameList, variableLists);
nameList = createStringsFromNamedVariableList(variableLists);
return nameList;
}
@ -313,7 +314,7 @@ getNamedVariableListAssociationSpecific(MmsServerConnection connection)
LinkedList variableLists = MmsServerConnection_getNamedVariableLists(connection);
nameList = createStringsFromNamedVariableList(nameList, variableLists);
nameList = createStringsFromNamedVariableList(variableLists);
return nameList;
}

Loading…
Cancel
Save