improved style and fixed some cppcheck findings

This commit is contained in:
prozessorkern 2021-01-24 00:10:43 +01:00
parent c7f238c005
commit eb524436ce
5 changed files with 31 additions and 36 deletions

View File

@ -193,8 +193,8 @@ shellmatta_retCode_t shellmatta_addCmd(shellmatta_handle_t handle, shellmatta_cm
shellmatta_cmd_t **prevCmd;
bool cmdPlaced = false;
shellmatta_retCode_t ret = SHELLMATTA_OK;
int cmdDiff = 0;
int aliasDiff = 0;
int cmdDiff;
int aliasDiff;
/** -# check parameters for plausibility */
if( (NULL != inst)
@ -232,7 +232,7 @@ shellmatta_retCode_t shellmatta_addCmd(shellmatta_handle_t handle, shellmatta_cm
{
ret = SHELLMATTA_DUPLICATE;
}
else if(0 < cmdDiff)
else if(cmdDiff > 0)
{
cmd->next = tempCmd;
*prevCmd = cmd;
@ -289,8 +289,7 @@ shellmatta_retCode_t shellmatta_removeCmd(shellmatta_handle_t handle, shellmatta
while(NULL != tempCmd)
{
/** -# compare command strings to find the command to delete */
if (0 == strcmp( tempCmd->cmd,
cmd->cmd)
if (0 == strcmp(tempCmd->cmd, cmd->cmd)
&& (strlen(tempCmd->cmd) == strlen(cmd->cmd)))
{
/** -# first command removed */
@ -344,7 +343,7 @@ shellmatta_retCode_t shellmatta_configure( shellmatta_handle_t handle,
/** -# check parameters for plausibility */
if( (NULL != inst)
&& (SHELLMATTA_MAGIC == inst->magic)
&& ((mode == SHELLMATTA_MODE_INSERT) || (mode == SHELLMATTA_MODE_OVERWRITE)))
&& ((SHELLMATTA_MODE_INSERT == mode) || (SHELLMATTA_MODE_OVERWRITE == mode)))
{
inst->mode = mode;
inst->echoEnabled = echoEnabled;
@ -602,14 +601,10 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
{
/** -# compare command and alias string and length */
if ( ((cmdLen == strlen(cmd->cmd))
&& (0 == strncmp( inst->buffer,
cmd->cmd,
cmdLen)))
&& (0 == strncmp(inst->buffer, cmd->cmd, cmdLen)))
|| ((NULL != cmd->cmdAlias)
&& (cmdLen == strlen(cmd->cmdAlias))
&& (0 == strncmp( inst->buffer,
cmd->cmdAlias,
cmdLen))))
&& (0 == strncmp(inst->buffer, cmd->cmdAlias, cmdLen))))
{
utils_writeEcho(inst, "\r\n", 2u);
shellmatta_opt_init(inst, cmdLen + 1u);
@ -643,7 +638,7 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
}
}
if ((cmdExecuted == 0u) && (inst->inputCount > 0))
if ((0u == cmdExecuted) && (inst->inputCount > 0))
{
inst->write("\r\nCommand: ", 11u);
inst->write(inst->buffer, inst->inputCount);

View File

@ -34,16 +34,16 @@ void autocomplete_run(shellmatta_instance_t *inst)
shellmatta_cmd_t *cmd = inst->cmdList;
char *tempCmd = NULL;
uint32_t minLen = 0u;
uint32_t sizeDiff = 0u;
bool exactMatch = true;
uint32_t printedLen = 0u;
uint32_t tempCursor = 0u;
uint32_t sizeDiff;
uint32_t tempCursor;
/** -# increase the tab counter to print all matching commands next time */
inst->tabCounter++;
/** -# on douple tab show all matching commands */
if (1u < inst->tabCounter)
if (inst->tabCounter > 1u)
{
inst->tabCounter = 0u;

View File

@ -142,7 +142,7 @@ static bool compareLastCommand(shellmatta_instance_t *inst)
bool history_navigate(shellmatta_instance_t *inst, int32_t cnt)
{
bool ret = true;
uint32_t tempReadIdx = 0u;
uint32_t tempReadIdx;
while((cnt > 0) && (true == ret))
{
@ -259,7 +259,7 @@ void history_restoreCmd(shellmatta_instance_t *inst)
utils_clearInput(inst);
anythingToRestore = true;
}
while((ret == true) && (byte != 0u))
while((true == ret) && (0u != byte))
{
inst->buffer[inst->inputCount] = byte;
inst->inputCount ++;

View File

@ -51,7 +51,7 @@ static shellmatta_retCode_t findNextHunk(shellmatta_instance_t *inst)
&& (((' ' != inst->buffer[newOffset]) && ('\0' != inst->buffer[newOffset])) || '\0' != quotation))
{
/** -# check for new quotation */
if((('\'' == inst->buffer[newOffset]) || ('"' == inst->buffer[newOffset])) && (quotation == '\0'))
if((('\'' == inst->buffer[newOffset]) || ('"' == inst->buffer[newOffset])) && ('\0' == quotation))
{
quotation = inst->buffer[newOffset];
exeptionOffset ++;
@ -211,7 +211,7 @@ static shellmatta_retCode_t parseLongOpt( shellmatta_instance_t *inst,
}
}
/** -# check for correct syntax for long options */
else if((3u <= inst->optionParser.len) && ('-' == buffer[0u]) && ('-' == buffer[1u]))
else if((inst->optionParser.len >= 3u) && ('-' == buffer[0u]) && ('-' == buffer[1u]))
{
/** -# search for long option in option list */
for(i = 0u; ('\0' != longOptions[i].paramShort) && ('\0' == *option); i ++)

View File

@ -54,10 +54,10 @@ uint32_t utils_shellItoa(int32_t value, char *buffer, uint32_t base)
int8_t digitValue;
/** -# check the base for plausibility */
if((2 <= base) && (16 >= base))
if((base >= 2) && (base <= 16))
{
/** -# check for sign */
if(0 > value)
if(value < 0)
{
value = value * (-1);
buffer[0u] = '-';
@ -283,10 +283,10 @@ static shellmatta_retCode_t helpCmdFct(const shellmatta_handle_t handle, const c
size_t maxCmdLen = 0u;
size_t maxCmdAliasLen = 0u;
size_t maxCmdHelpLen = 0u;
size_t cmdLen = 0u;
size_t cmdAliasLen = 0u;
size_t cmdHelpLen = 0u;
uint32_t tabCnt = 0u;
size_t cmdLen;
size_t cmdAliasLen;
size_t cmdHelpLen;
uint32_t tabCnt;
static const char tabBuffer[] = { ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ',