fixed findings from static analysis

This commit is contained in:
prozessorkern 2020-12-02 15:47:23 +01:00
parent 6cfd157408
commit ac6ffb9602
5 changed files with 43 additions and 55 deletions

View File

@ -92,24 +92,21 @@ cppcheck:
unittest: $(UNITTEST_TARGET) unittest: $(UNITTEST_TARGET)
- @mkdir -p output/test/unittest/report - @mkdir -p output/test/unittest/report
@echo running test: @echo running test:
@# remove coverage from former run # remove coverage from former run
@-find . -name "*.gcda" -type f -delete @-find . -name "*.gcda" -type f -delete
-$(UNITTEST_TARGET) -$(UNITTEST_TARGET)
@#gcov -o output/test/unittest $(UNITTEST_CPPOBJ) -r src # gcov -o output/test/unittest $(UNITTEST_CPPOBJ) -r src
@# remove report from former run # remove report from former run
-rm -rf $(OBJ_DIR)test/unittest/report/* -rm -rf $(OBJ_DIR)test/unittest/report/*
gcovr --html-details --output $(OBJ_DIR)test/unittest/report/report.html output/test/unittest -f src -f api gcovr --html-details --output $(OBJ_DIR)test/unittest/report/report.html output/test/unittest -f src -f api -d
@#-rm *.gcov
integrationtest: $(INTEGRATIONTEST_TARGET) integrationtest: $(INTEGRATIONTEST_TARGET)
- @mkdir -p output/test/integrationtest/report - @mkdir -p output/test/integrationtest/report
@echo running test: @echo running test:
-$(INTEGRATIONTEST_TARGET) -$(INTEGRATIONTEST_TARGET)
#gcov -o output/test $(TEST_CPPOBJ) -r gcovr --html-details --output $(OBJ_DIR)test/integrationtest/report/report.html output/src -f src -f api -d
gcovr --html-details --output $(OBJ_DIR)test/integrationtest/report/report.html output/src -f src -f api
#-rm *.gcov
example: $(EXAMPLE_TARGET) example: $(EXAMPLE_TARGET)
@echo building example @echo building example

View File

@ -427,6 +427,10 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
utils_terminateInput(inst); utils_terminateInput(inst);
} }
} }
else
{
/* nothing to do here - continue parsing the command */
}
/** -# process byte wise */ /** -# process byte wise */
for (; (inst->byteCounter < size) && (NULL == inst->busyCmd); inst->byteCounter++) for (; (inst->byteCounter < size) && (NULL == inst->busyCmd); inst->byteCounter++)
@ -597,15 +601,15 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
while (NULL != cmd) while (NULL != cmd)
{ {
/** -# compare command and alias string and length */ /** -# compare command and alias string and length */
if ( ((0 == strncmp( inst->buffer, if ( ((cmdLen == strlen(cmd->cmd))
cmd->cmd, && (0 == strncmp( inst->buffer,
cmdLen)) cmd->cmd,
&& (cmdLen == strlen(cmd->cmd))) cmdLen)))
|| ((NULL != cmd->cmdAlias) || ((NULL != cmd->cmdAlias)
&& ((0 == strncmp( inst->buffer, && (cmdLen == strlen(cmd->cmdAlias))
&& (0 == strncmp( inst->buffer,
cmd->cmdAlias, cmd->cmdAlias,
cmdLen)) cmdLen))))
&& (cmdLen == strlen(cmd->cmdAlias)))))
{ {
utils_writeEcho(inst, "\r\n", 2u); utils_writeEcho(inst, "\r\n", 2u);
shellmatta_opt_init(inst, cmdLen + 1u); shellmatta_opt_init(inst, cmdLen + 1u);
@ -819,4 +823,3 @@ shellmatta_retCode_t shellmatta_printf( shellmatta_handle_t handle,
#endif #endif
/** @} */ /** @} */

View File

@ -52,7 +52,7 @@ void autocomplete_run(shellmatta_instance_t *inst)
{ {
/** -# check if command matches the input */ /** -# check if command matches the input */
if( (strlen(cmd->cmd) >= inst->cursor) if( (strlen(cmd->cmd) >= inst->cursor)
&& (0u == memcmp(cmd->cmd, inst->buffer, inst->cursor))) && (0 == strncmp(cmd->cmd, inst->buffer, inst->cursor)))
{ {
/** -# add newline on first find */ /** -# add newline on first find */
if(0u == printedLen) if(0u == printedLen)
@ -67,7 +67,7 @@ void autocomplete_run(shellmatta_instance_t *inst)
/** -# check if command alias matches the input */ /** -# check if command alias matches the input */
if( (NULL != cmd->cmdAlias) if( (NULL != cmd->cmdAlias)
&& (strlen(cmd->cmdAlias) >= inst->cursor) && (strlen(cmd->cmdAlias) >= inst->cursor)
&& (0u == memcmp(cmd->cmdAlias, inst->buffer, inst->cursor))) && (0 == strncmp(cmd->cmdAlias, inst->buffer, inst->cursor)))
{ {
/** -# add newline on first find */ /** -# add newline on first find */
if(0u == printedLen) if(0u == printedLen)
@ -100,7 +100,7 @@ void autocomplete_run(shellmatta_instance_t *inst)
{ {
/** -# check if command matches the input */ /** -# check if command matches the input */
if( (strlen(cmd->cmd) >= inst->cursor) if( (strlen(cmd->cmd) >= inst->cursor)
&& (0u == memcmp(cmd->cmd, inst->buffer, inst->cursor))) && (0 == strncmp(cmd->cmd, inst->buffer, inst->cursor)))
{ {
/** -# store first match */ /** -# store first match */
if(NULL == tempCmd) if(NULL == tempCmd)
@ -126,7 +126,7 @@ void autocomplete_run(shellmatta_instance_t *inst)
/** -# check if command Alias matches the input */ /** -# check if command Alias matches the input */
if( (NULL != cmd->cmdAlias) if( (NULL != cmd->cmdAlias)
&& (strlen(cmd->cmdAlias) >= inst->cursor) && (strlen(cmd->cmdAlias) >= inst->cursor)
&& (0u == memcmp(cmd->cmdAlias, inst->buffer, inst->cursor))) && (0 == strncmp(cmd->cmdAlias, inst->buffer, inst->cursor)))
{ {
/** -# store first match */ /** -# store first match */
if(NULL == tempCmd) if(NULL == tempCmd)

View File

@ -22,18 +22,6 @@
#include "shellmatta.h" #include "shellmatta.h"
#include <stdint.h> #include <stdint.h>
shellmatta_retCode_t shellmatta_opt( shellmatta_handle_t handle,
const char *optionString,
char *option,
char **argument,
uint32_t *argLen);
shellmatta_retCode_t shellmatta_opt_long( shellmatta_handle_t handle,
const shellmatta_opt_long_t *longOptions,
char *option,
char **argument,
uint32_t *argLen);
void shellmatta_opt_init( shellmatta_instance_t *inst, void shellmatta_opt_init( shellmatta_instance_t *inst,
uint32_t argStart); uint32_t argStart);

View File

@ -51,7 +51,7 @@ uint32_t utils_shellItoa(int32_t value, char *buffer, uint32_t base)
char tempBuffer[34u]; char tempBuffer[34u];
uint32_t i; uint32_t i;
uint32_t bufferIdx = 0u; uint32_t bufferIdx = 0u;
char digitValue; int8_t digitValue;
/** -# check the base for plausibility */ /** -# check the base for plausibility */
if((2 <= base) && (16 >= base)) if((2 <= base) && (16 >= base))
@ -68,8 +68,8 @@ uint32_t utils_shellItoa(int32_t value, char *buffer, uint32_t base)
i = 0u; i = 0u;
do do
{ {
digitValue = (char) (value % base); digitValue = (int8_t) (value % base);
tempBuffer[i] = (digitValue < 10) ? ('0' + digitValue) : (('A' - 10) + digitValue); tempBuffer[i] = (digitValue < 10) ? ('0' + digitValue) : ('A' + (digitValue - 10));
value /= base; value /= base;
i ++; i ++;
}while(value > 0); }while(value > 0);
@ -91,7 +91,7 @@ uint32_t utils_shellItoa(int32_t value, char *buffer, uint32_t base)
*/ */
void utils_saveCursorPos(shellmatta_instance_t *inst) void utils_saveCursorPos(shellmatta_instance_t *inst)
{ {
utils_writeEcho(inst, "\x1b[s", 3u); utils_writeEcho(inst, "\x1b" "[s", 3u);
} }
/** /**
@ -100,7 +100,7 @@ void utils_saveCursorPos(shellmatta_instance_t *inst)
*/ */
void utils_restoreCursorPos(shellmatta_instance_t *inst) void utils_restoreCursorPos(shellmatta_instance_t *inst)
{ {
utils_writeEcho(inst, "\x1b[u", 3u); utils_writeEcho(inst, "\x1b" "[u", 3u);
} }
/** /**
@ -110,7 +110,7 @@ void utils_restoreCursorPos(shellmatta_instance_t *inst)
*/ */
void utils_eraseLine(shellmatta_instance_t *inst) void utils_eraseLine(shellmatta_instance_t *inst)
{ {
utils_writeEcho(inst, "\x1b[K", 3u); utils_writeEcho(inst, "\x1b" "[K", 3u);
} }
/** /**
@ -275,22 +275,22 @@ void utils_clearInput(shellmatta_instance_t *inst)
* @return #SHELLMATTA_OK * @return #SHELLMATTA_OK
* #SHELLMATTA_ERROR (buffer overflow) * #SHELLMATTA_ERROR (buffer overflow)
*/ */
static shellmatta_retCode_t helpCmdFct(shellmatta_handle_t handle, const char *arguments, uint32_t length) static shellmatta_retCode_t helpCmdFct(const shellmatta_handle_t handle, const char *arguments, uint32_t length)
{ {
shellmatta_retCode_t ret = SHELLMATTA_OK; shellmatta_retCode_t ret = SHELLMATTA_OK;
shellmatta_instance_t *inst = (shellmatta_instance_t*) handle; const shellmatta_instance_t *inst = (const shellmatta_instance_t*) handle;
shellmatta_cmd_t *cmd = inst->cmdList; shellmatta_cmd_t *cmd = inst->cmdList;
size_t maxCmdLen = 0u; size_t maxCmdLen = 0u;
size_t maxCmdAliasLen = 0u; size_t maxCmdAliasLen = 0u;
size_t maxCmdHelpLen = 0u; size_t maxCmdHelpLen = 0u;
size_t cmdLen = 0u; size_t cmdLen = 0u;
size_t cmdAliasLen = 0u; size_t cmdAliasLen = 0u;
size_t cmdHelpLen = 0u; size_t cmdHelpLen = 0u;
uint32_t tabCnt = 0u; uint32_t tabCnt = 0u;
static const char tabBuffer[] = { ' ', ' ', ' ', ' ', static const char tabBuffer[] = { ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' '}; ' ', ' ', ' ', ' '};
/** -# loop through all commands to determine the lengths of each cmd */ /** -# loop through all commands to determine the lengths of each cmd */
while(NULL != cmd) while(NULL != cmd)