- removed some warnings and code cleanup

pull/309/head
Michael Zillgith 5 years ago
parent de2ce1d008
commit 4f0667b597

@ -122,7 +122,7 @@ LIB_SOURCES = $(call get_sources,$(LIB_SOURCE_DIRS))
LIB_OBJS = $(call src_to,.o,$(LIB_SOURCES)) LIB_OBJS = $(call src_to,.o,$(LIB_SOURCES))
CFLAGS += -std=gnu99 CFLAGS += -std=gnu99
#CFLAGS += -Wno-error=format CFLAGS += -Wno-error=format
CFLAGS += -Wstrict-prototypes CFLAGS += -Wstrict-prototypes
ifneq ($(HAL_IMPL), WIN32) ifneq ($(HAL_IMPL), WIN32)
@ -136,6 +136,8 @@ CFLAGS += -Wmissing-declarations
CFLAGS += -Wshadow CFLAGS += -Wshadow
CFLAGS += -Wall CFLAGS += -Wall
CFLAGS += -Wextra CFLAGS += -Wextra
CFLAGS += -Wno-format
#CFLAGS += -Wconditional-uninitialized
#CFLAGS += -Werror #CFLAGS += -Werror
all: lib all: lib

@ -125,7 +125,7 @@ getInterfaceIndex(int sock, const char* deviceName)
{ {
struct ifreq ifr; struct ifreq ifr;
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ); strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);
if (ioctl(sock, SIOCGIFINDEX, &ifr) == -1) { if (ioctl(sock, SIOCGIFINDEX, &ifr) == -1) {
if (DEBUG_SOCKET) if (DEBUG_SOCKET)
@ -163,7 +163,7 @@ Ethernet_getInterfaceMACAddress(const char* interfaceId, uint8_t* addr)
memset(&buffer, 0x00, sizeof(buffer)); memset(&buffer, 0x00, sizeof(buffer));
strncpy(buffer.ifr_name, interfaceId, IFNAMSIZ); strncpy(buffer.ifr_name, interfaceId, IFNAMSIZ - 1);
ioctl(sock, SIOCGIFHWADDR, &buffer); ioctl(sock, SIOCGIFHWADDR, &buffer);

@ -83,7 +83,7 @@ EthernetHandleSet_removeSocket(EthernetHandleSet self, const EthernetSocket sock
* The function will return after \p timeoutMs ms if no data is pending. * The function will return after \p timeoutMs ms if no data is pending.
* *
* \param self the HandleSet instance * \param self the HandleSet instance
* \param timeout in milliseconds (ms) * \param timeoutMs in milliseconds (ms)
* \return It returns the number of sockets on which data is pending * \return It returns the number of sockets on which data is pending
* or 0 if no data is pending on any of the monitored connections. * or 0 if no data is pending on any of the monitored connections.
* The function shall return -1 if a socket error occures. * The function shall return -1 if a socket error occures.
@ -145,7 +145,7 @@ Ethernet_setProtocolFilter(EthernetSocket ethSocket, uint16_t etherType);
* *
* \param ethSocket the ethernet socket handle * \param ethSocket the ethernet socket handle
* \param buffer the buffer to copy the message to * \param buffer the buffer to copy the message to
* \param the maximum size of the buffer * \param bufferSize the maximum size of the buffer
* *
* \return size of message received in bytes * \return size of message received in bytes
*/ */

@ -62,7 +62,7 @@ SerialPort_create(const char* interfaceName, int baudRate, uint8_t dataBits, cha
self->lastSentTime = 0; self->lastSentTime = 0;
self->timeout.tv_sec = 0; self->timeout.tv_sec = 0;
self->timeout.tv_usec = 100000; /* 100 ms */ self->timeout.tv_usec = 100000; /* 100 ms */
strncpy(self->interfaceName, interfaceName, 100); strncpy(self->interfaceName, interfaceName, 99);
self->lastError = SERIAL_PORT_ERROR_NONE; self->lastError = SERIAL_PORT_ERROR_NONE;
} }

@ -1,7 +1,7 @@
/* /*
* linked_list.h * linked_list.h
* *
* Copyright 2013-2018 Michael Zillgith * Copyright 2013-2021 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -153,7 +153,7 @@ LinkedList_getNext(LinkedList self);
/** /**
* \brief Get the last element in the list. * \brief Get the last element in the list.
* *
* \param listElement the LinkedList instance * \param self the LinkedList instance
*/ */
LIB61850_API LinkedList LIB61850_API LinkedList
LinkedList_getLastElement(LinkedList self); LinkedList_getLastElement(LinkedList self);

@ -271,7 +271,7 @@ getCharWeight(int c)
{ {
static bool initialized = false; static bool initialized = false;
static char lookupTable[LT_MAX_CHARS + 1]; static char lookupTable[LT_MAX_CHARS + 1];
static char* charOrder = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz$_0123456789"; static const char* charOrder = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz$_0123456789";
if (!initialized) { if (!initialized) {
int ltIndex; int ltIndex;

@ -574,7 +574,7 @@ parseGoosePayload(GooseReceiver self, uint8_t* buffer, int apduLength)
uint32_t timeAllowedToLive = 0; uint32_t timeAllowedToLive = 0;
uint32_t stNum = 0; uint32_t stNum = 0;
uint32_t sqNum = 0; uint32_t sqNum = 0;
uint32_t confRev; uint32_t confRev = 0;
bool simulation = false; bool simulation = false;
bool ndsCom = false; bool ndsCom = false;
GooseSubscriber matchingSubscriber = NULL; GooseSubscriber matchingSubscriber = NULL;

@ -1191,7 +1191,7 @@ IedConnection_readObject(IedConnection self, IedClientError* error, const char*
return NULL; return NULL;
} }
MmsError mmsError; MmsError mmsError = MMS_ERROR_NONE;
/* check if item ID contains an array "(..)" */ /* check if item ID contains an array "(..)" */
char* brace = strchr(itemId, '('); char* brace = strchr(itemId, '(');
@ -2482,22 +2482,20 @@ IedConnection_getLogicalNodeDirectory(IedConnection self, IedClientError* error,
LinkedList device = LinkedList_getNext(self->logicalDevices); LinkedList device = LinkedList_getNext(self->logicalDevices);
bool deviceFound = false; ICLogicalDevice* ld = NULL;
ICLogicalDevice* ld;
while (device != NULL) { while (device != NULL) {
ld = (ICLogicalDevice*) device->data; ICLogicalDevice* ldCandidate = (ICLogicalDevice*) device->data;
if (strcmp(logicalDeviceName, ld->name) == 0) { if (strcmp(logicalDeviceName, ldCandidate->name) == 0) {
deviceFound = true; ld = ldCandidate;
break; break;
} }
device = LinkedList_getNext(device); device = LinkedList_getNext(device);
} }
if (!deviceFound) { if (ld == NULL) {
*error = IED_ERROR_OBJECT_REFERENCE_INVALID; *error = IED_ERROR_OBJECT_REFERENCE_INVALID;
return NULL; return NULL;
} }
@ -2630,22 +2628,20 @@ IedConnection_getLogicalNodeVariables(IedConnection self, IedClientError* error,
LinkedList device = LinkedList_getNext(self->logicalDevices); LinkedList device = LinkedList_getNext(self->logicalDevices);
bool deviceFound = false; ICLogicalDevice* ld = NULL;
ICLogicalDevice* ld;
while (device != NULL) { while (device != NULL) {
ld = (ICLogicalDevice*) device->data; ICLogicalDevice* ldCandidate = (ICLogicalDevice*) device->data;
if (strcmp(logicalDeviceName, ld->name) == 0) { if (strcmp(logicalDeviceName, ldCandidate->name) == 0) {
deviceFound = true; ld = ldCandidate;
break; break;
} }
device = LinkedList_getNext(device); device = LinkedList_getNext(device);
} }
if (!deviceFound) { if (ld == NULL) {
*error = IED_ERROR_OBJECT_REFERENCE_INVALID; *error = IED_ERROR_OBJECT_REFERENCE_INVALID;
return NULL; return NULL;
} }
@ -2731,22 +2727,20 @@ getDataDirectory(IedConnection self, IedClientError* error,
LinkedList device = LinkedList_getNext(self->logicalDevices); LinkedList device = LinkedList_getNext(self->logicalDevices);
bool deviceFound = false; ICLogicalDevice* ld = NULL;
ICLogicalDevice* ld;
while (device != NULL) { while (device != NULL) {
ld = (ICLogicalDevice*) device->data; ICLogicalDevice* ldCandidate = (ICLogicalDevice*) device->data;
if (strcmp(logicalDeviceName, ld->name) == 0) { if (strcmp(logicalDeviceName, ldCandidate->name) == 0) {
deviceFound = true; ld = ldCandidate;
break; break;
} }
device = LinkedList_getNext(device); device = LinkedList_getNext(device);
} }
if (!deviceFound) { if (ld == NULL) {
*error = IED_ERROR_OBJECT_REFERENCE_INVALID; *error = IED_ERROR_OBJECT_REFERENCE_INVALID;
return NULL; return NULL;
} }
@ -2900,22 +2894,20 @@ getDataDirectoryByFc(IedConnection self, IedClientError* error,
LinkedList device = LinkedList_getNext(self->logicalDevices); LinkedList device = LinkedList_getNext(self->logicalDevices);
bool deviceFound = false; ICLogicalDevice* ld = NULL;
ICLogicalDevice* ld;
while (device != NULL) { while (device != NULL) {
ld = (ICLogicalDevice*) device->data; ICLogicalDevice* ldCandidate = (ICLogicalDevice*) device->data;
if (strcmp(logicalDeviceName, ld->name) == 0) { if (strcmp(logicalDeviceName, ldCandidate->name) == 0) {
deviceFound = true; ld = ldCandidate;
break; break;
} }
device = LinkedList_getNext(device); device = LinkedList_getNext(device);
} }
if (!deviceFound) { if (ld == NULL) {
*error = IED_ERROR_OBJECT_REFERENCE_INVALID; *error = IED_ERROR_OBJECT_REFERENCE_INVALID;
return NULL; return NULL;
} }

@ -678,10 +678,12 @@ operateControl(ControlObject* self, MmsValue* value, uint64_t currentTime, bool
static void static void
resetAddCause(ControlObject* self) resetAddCause(ControlObject* self)
{ {
if (self) {
self->addCauseValue = ADD_CAUSE_UNKNOWN; self->addCauseValue = ADD_CAUSE_UNKNOWN;
MmsValue_setInt32(self->addCause, self->addCauseValue); MmsValue_setInt32(self->addCause, self->addCauseValue);
} }
}
static void static void
executeControlTask(MmsMapping* self, ControlObject* controlObject, uint64_t currentTimeInMs) executeControlTask(MmsMapping* self, ControlObject* controlObject, uint64_t currentTimeInMs)
@ -1869,6 +1871,7 @@ Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, char* vari
{ {
MmsDataAccessError indication = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; MmsDataAccessError indication = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED;
IEC61850_ServiceError serviceError = IEC61850_SERVICE_ERROR_NO_ERROR; IEC61850_ServiceError serviceError = IEC61850_SERVICE_ERROR_NO_ERROR;
ControlObject* controlObject = NULL;
if (DEBUG_IED_SERVER) if (DEBUG_IED_SERVER)
printf("IED_SERVER: writeAccessControlObject: %s\n", variableIdOrig); printf("IED_SERVER: writeAccessControlObject: %s\n", variableIdOrig);
@ -1935,7 +1938,7 @@ Control_writeAccessControlObject(MmsMapping* self, MmsDomain* domain, char* vari
goto free_and_return; goto free_and_return;
} }
ControlObject* controlObject = Control_lookupControlObject(self, domain, lnName, objectName); controlObject = Control_lookupControlObject(self, domain, lnName, objectName);
if (controlObject == NULL) { if (controlObject == NULL) {
indication = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; indication = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED;

@ -1410,7 +1410,7 @@ convertIPv4AddressStringToByteArray(const char* clientAddressString, uint8_t ipV
{ {
int addrElementCount = 0; int addrElementCount = 0;
char* separator = (char*) clientAddressString; const char* separator = clientAddressString;
while (separator != NULL && addrElementCount < 4) { while (separator != NULL && addrElementCount < 4) {
int intVal = atoi(separator); int intVal = atoi(separator);

@ -37,15 +37,15 @@ BerEncoder_encodeLength(uint32_t length, uint8_t* buffer, int bufPos)
else if (length < 65535) { else if (length < 65535) {
buffer[bufPos++] = 0x82; buffer[bufPos++] = 0x82;
buffer[bufPos++] = length / 256; buffer[bufPos++] = (uint8_t) (length / 256);
buffer[bufPos++] = length % 256; buffer[bufPos++] = (uint8_t) (length % 256);
} }
else { else {
buffer[bufPos++] = 0x83; buffer[bufPos++] = 0x83;
buffer[bufPos++] = length / 0x10000; buffer[bufPos++] = (uint8_t) (length / 0x10000);
buffer[bufPos++] = (length & 0xffff) / 0x100; buffer[bufPos++] = (uint8_t) ((length & 0xffff) / 0x100);
buffer[bufPos++] = length % 256; buffer[bufPos++] = (uint8_t) (length % 256);
} }
return bufPos; return bufPos;
@ -80,13 +80,13 @@ BerEncoder_encodeStringWithTag(uint8_t tag, const char* string, uint8_t* buffer,
buffer[bufPos++] = tag; buffer[bufPos++] = tag;
if (string != NULL) { if (string != NULL) {
int length = strlen(string); int length = (int) strlen(string);
bufPos = BerEncoder_encodeLength(length, buffer, bufPos); bufPos = BerEncoder_encodeLength((uint32_t) length, buffer, bufPos);
int i; int i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
buffer[bufPos++] = string[i]; buffer[bufPos++] = (uint8_t) string[i];
} }
} }
else else
@ -316,8 +316,7 @@ int
BerEncoder_encodeFloat(uint8_t* floatValue, uint8_t formatWidth, uint8_t exponentWidth, BerEncoder_encodeFloat(uint8_t* floatValue, uint8_t formatWidth, uint8_t exponentWidth,
uint8_t* buffer, int bufPos) uint8_t* buffer, int bufPos)
{ {
/* TODO operate on encoding buffer directly */ uint8_t* valueBuffer = buffer + bufPos;
uint8_t valueBuffer[9];
int byteSize = formatWidth / 8; int byteSize = formatWidth / 8;
@ -332,9 +331,7 @@ BerEncoder_encodeFloat(uint8_t* floatValue, uint8_t formatWidth, uint8_t exponen
BerEncoder_revertByteOrder(valueBuffer + 1, byteSize); BerEncoder_revertByteOrder(valueBuffer + 1, byteSize);
#endif #endif
for (i = 0; i < byteSize + 1; i++) { bufPos = bufPos + 1 + byteSize;
buffer[bufPos++] = valueBuffer[i];
}
return bufPos; return bufPos;
} }

@ -418,7 +418,7 @@ AcseConnection_init(AcseConnection* self, AcseAuthenticator authenticator, void*
AcseIndication AcseIndication
AcseConnection_parseMessage(AcseConnection* self, ByteBuffer* message) AcseConnection_parseMessage(AcseConnection* self, ByteBuffer* message)
{ {
AcseIndication indication; AcseIndication indication = ACSE_ERROR;
uint8_t* buffer = message->buffer; uint8_t* buffer = message->buffer;

@ -70,7 +70,7 @@ ber_check_tags(asn_codec_ctx_t *opt_codec_ctx,
ssize_t tag_len; ssize_t tag_len;
ssize_t len_len; ssize_t len_len;
ber_tlv_tag_t tlv_tag; ber_tlv_tag_t tlv_tag;
ber_tlv_len_t tlv_len; ber_tlv_len_t tlv_len = -1;
ber_tlv_len_t limit_len = -1; ber_tlv_len_t limit_len = -1;
int expect_00_terminators = 0; int expect_00_terminators = 0;
int tlv_constr = -1; /* If CHOICE, opt_tlv_form is not given */ int tlv_constr = -1; /* If CHOICE, opt_tlv_form is not given */

@ -654,7 +654,7 @@ void
MmsValue_setInt16(MmsValue* self, int16_t integer) MmsValue_setInt16(MmsValue* self, int16_t integer)
{ {
if (self->type == MMS_INTEGER) { if (self->type == MMS_INTEGER) {
if (Asn1PrimitiveValue_getMaxSize(self->value.integer) >= 1) { if (Asn1PrimitiveValue_getMaxSize(self->value.integer) >= 2) {
BerInteger_setInt32(self->value.integer, (int32_t) integer); BerInteger_setInt32(self->value.integer, (int32_t) integer);
} }
} }

@ -1,7 +1,7 @@
/* /*
* mms_access_result.c * mms_access_result.c
* *
* Copyright 2013, 2016 Michael Zillgith * Copyright 2013-2021 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -329,7 +329,7 @@ exit_with_error:
int int
MmsValue_encodeMmsData(MmsValue* self, uint8_t* buffer, int bufPos, bool encode) MmsValue_encodeMmsData(MmsValue* self, uint8_t* buffer, int bufPos, bool encode)
{ {
int size; int size = 0;
switch (self->type) { switch (self->type) {
case MMS_BOOLEAN: case MMS_BOOLEAN:
@ -446,4 +446,3 @@ MmsValue_encodeMmsData(MmsValue* self, uint8_t* buffer, int bufPos, bool encode)
else else
return size; return size;
} }

@ -438,10 +438,10 @@ mmsServer_handleGetNameListRequest(
int objectScope = -1; int objectScope = -1;
char* domainId = NULL; char* domainId = NULL;
int domainIdLength; int domainIdLength = 0;
char* continueAfter = NULL; char* continueAfter = NULL;
int continueAfterLength; int continueAfterLength = 0;
while (bufPos < maxBufPos) { while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++]; uint8_t tag = buffer[bufPos++];

@ -705,7 +705,7 @@ IsoServer_startListeningThreadless(IsoServer self)
int int
IsoServer_waitReady(IsoServer self, unsigned int timeoutMs) IsoServer_waitReady(IsoServer self, unsigned int timeoutMs)
{ {
int result; int result = -1;
if (getState(self) == ISO_SVR_STATE_RUNNING) { if (getState(self) == ISO_SVR_STATE_RUNNING) {
@ -717,8 +717,6 @@ IsoServer_waitReady(IsoServer self, unsigned int timeoutMs)
printf("ISO_SERVER: internal error - no handleset!\n"); printf("ISO_SERVER: internal error - no handleset!\n");
} }
} else {
result = -1;
} }
return result; return result;

@ -22,6 +22,7 @@
*/ */
#include "stack_config.h" #include "stack_config.h"
#include <inttypes.h>
#include "libiec61850_platform_includes.h" #include "libiec61850_platform_includes.h"
@ -355,8 +356,10 @@ parseASDU(SVReceiver self, SVSubscriber subscriber, uint8_t* buffer, int length)
if (SVSubscriber_ASDU_hasDatSet(&asdu)) if (SVSubscriber_ASDU_hasDatSet(&asdu))
printf("SV_SUBSCRIBER: DatSet: %s\n", asdu.datSet); printf("SV_SUBSCRIBER: DatSet: %s\n", asdu.datSet);
#ifdef PRIu64
if (SVSubscriber_ASDU_hasRefrTm(&asdu)) if (SVSubscriber_ASDU_hasRefrTm(&asdu))
printf("SV_SUBSCRIBER: RefrTm[ns]: %llu\n", SVSubscriber_ASDU_getRefrTmAsNs(&asdu)); printf("SV_SUBSCRIBER: RefrTm[ns]: %"PRIu64"\n", SVSubscriber_ASDU_getRefrTmAsNs(&asdu));
#endif
if (SVSubscriber_ASDU_hasSmpMod(&asdu)) if (SVSubscriber_ASDU_hasSmpMod(&asdu))
printf("SV_SUBSCRIBER: SmpMod: %d\n", SVSubscriber_ASDU_getSmpMod(&asdu)); printf("SV_SUBSCRIBER: SmpMod: %d\n", SVSubscriber_ASDU_getSmpMod(&asdu));
if (SVSubscriber_ASDU_hasSmpRate(&asdu)) if (SVSubscriber_ASDU_hasSmpRate(&asdu))
@ -455,7 +458,6 @@ static void
parseSVMessage(SVReceiver self, int numbytes) parseSVMessage(SVReceiver self, int numbytes)
{ {
int bufPos; int bufPos;
bool subscriberFound = false;
uint8_t* buffer = self->buffer; uint8_t* buffer = self->buffer;
if (numbytes < 22) return; if (numbytes < 22) return;
@ -507,25 +509,24 @@ parseSVMessage(SVReceiver self, int numbytes)
printf("SV_SUBSCRIBER: APDU length: %i\n", apduLength); printf("SV_SUBSCRIBER: APDU length: %i\n", apduLength);
} }
/* check if there is a matching subscriber */ /* check if there is a matching subscriber */
#if (CONFIG_MMS_THREADLESS_STACK == 0) #if (CONFIG_MMS_THREADLESS_STACK == 0)
Semaphore_wait(self->subscriberListLock); Semaphore_wait(self->subscriberListLock);
#endif #endif
LinkedList element = LinkedList_getNext(self->subscriberList); SVSubscriber subscriber = NULL;
SVSubscriber subscriber; LinkedList element = LinkedList_getNext(self->subscriberList);
while (element != NULL) { while (element != NULL) {
subscriber = (SVSubscriber) LinkedList_getData(element); SVSubscriber subscriberElem = (SVSubscriber) LinkedList_getData(element);
if (subscriber->appId == appId) { if (subscriberElem->appId == appId) {
if (self->checkDestAddr) { if (self->checkDestAddr) {
if (memcmp(dstAddr, subscriber->ethAddr, 6) == 0) { if (memcmp(dstAddr, subscriberElem->ethAddr, 6) == 0) {
subscriberFound = true; subscriber = subscriberElem;
break; break;
} }
else else
@ -533,11 +534,10 @@ parseSVMessage(SVReceiver self, int numbytes)
printf("SV_SUBSCRIBER: Checking ethernet dest address failed!\n"); printf("SV_SUBSCRIBER: Checking ethernet dest address failed!\n");
} }
else { else {
subscriberFound = true; subscriber = subscriberElem;
break; break;
} }
} }
element = LinkedList_getNext(element); element = LinkedList_getNext(element);
@ -547,8 +547,7 @@ parseSVMessage(SVReceiver self, int numbytes)
Semaphore_post(self->subscriberListLock); Semaphore_post(self->subscriberListLock);
#endif #endif
if (subscriber)
if (subscriberFound)
parseSVPayload(self, subscriber, buffer + bufPos, apduLength); parseSVPayload(self, subscriber, buffer + bufPos, apduLength);
else { else {
if (DEBUG_SV_SUBSCRIBER) if (DEBUG_SV_SUBSCRIBER)

Loading…
Cancel
Save