- 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 += -Wmissing-declarations
CFLAGS += -Wshadow CFLAGS += -Wshadow
CFLAGS += -Wall CFLAGS += -Wall
CGLAGS += -Wextra
#CFLAGS += -Werror #CFLAGS += -Werror
all: lib all: lib

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

@ -460,7 +460,7 @@ iedConnection_handleReport(IedConnection self, MmsValue* value)
matchingReport->timestamp = MmsValue_getBinaryTimeAsUtcMs(timeStampValue); matchingReport->timestamp = MmsValue_getBinaryTimeAsUtcMs(timeStampValue);
if (DEBUG_IED_CLIENT) 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++; inclusionIndex++;
} }

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

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

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

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

@ -964,12 +964,13 @@ CHOICE_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
void void
CHOICE_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { 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) if(!td || !ptr)
return; return;
asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics;
int present;
/* /*
* Figure out which CHOICE element is encoded. * 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, 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_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
asn_dec_rval_t rv; 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 */ asn_TYPE_member_t *elm = td->elements; /* Single one */
void *st = *sptr; void *st = *sptr;
asn_anonymous_set_ *list; 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 if(td->per_constraints) ct = &td->per_constraints->size;
else ct = 0; else ct = 0;
if(ct && ct->flags & APC_EXTENSIBLE) { if(ct && (ct->flags & APC_EXTENSIBLE)) {
int value = per_get_few_bits(pd, 1); int value = per_get_few_bits(pd, 1);
if(value < 0) _ASN_DECODE_STARVED; if(value < 0) _ASN_DECODE_STARVED;
if(value) ct = 0; /* Not restricted! */ 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() */ nelems = -1; /* Allow uper_get_length() */
} while(repeat); } while(repeat);
rv.code = RC_OK;
rv.consumed = 0;
return rv; return rv;
} }

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

@ -244,36 +244,6 @@ mmsMsg_parseDataElement(Data_t* dataElement)
printf("MMS CLIENT: error parsing data element (invalid structure size)!\n"); 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 { else {
if (dataElement->present == Data_PR_integer) { if (dataElement->present == Data_PR_integer) {

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

Loading…
Cancel
Save