Browse Source

fixed findings from static analysis

prozessorkern 4 years ago
parent
commit
ac6ffb9602
5 changed files with 43 additions and 55 deletions
  1. 7 10
      makefile
  2. 11 8
      src/shellmatta.c
  3. 4 4
      src/shellmatta_autocomplete.c
  4. 0 12
      src/shellmatta_opt.h
  5. 21 21
      src/shellmatta_utils.c

+ 7 - 10
makefile

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

+ 11 - 8
src/shellmatta.c

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

+ 4 - 4
src/shellmatta_autocomplete.c

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

+ 0 - 12
src/shellmatta_opt.h

@@ -22,18 +22,6 @@
 #include "shellmatta.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,
                                             uint32_t argStart);
 

+ 21 - 21
src/shellmatta_utils.c

@@ -51,7 +51,7 @@ uint32_t utils_shellItoa(int32_t value, char *buffer, uint32_t base)
     char tempBuffer[34u];
     uint32_t i;
     uint32_t bufferIdx = 0u;
-    char digitValue;
+    int8_t digitValue;
 
     /** -# check the base for plausibility */
     if((2 <= base) && (16 >= base))
@@ -68,8 +68,8 @@ uint32_t utils_shellItoa(int32_t value, char *buffer, uint32_t base)
         i = 0u;
         do
         {
-            digitValue = (char) (value % base);
-            tempBuffer[i] = (digitValue < 10) ? ('0' + digitValue) : (('A' - 10) + digitValue);
+            digitValue = (int8_t) (value % base);
+            tempBuffer[i] = (digitValue < 10) ? ('0' + digitValue) : ('A' + (digitValue - 10));
             value /= base;
             i ++;
         }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)
 {
-    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)
 {
-    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)
 {
-    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
  *              #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_instance_t   *inst = (shellmatta_instance_t*) handle;
-    shellmatta_cmd_t        *cmd = inst->cmdList;
-    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;
-    static const char       tabBuffer[] = { ' ', ' ', ' ', ' ',
-                                            ' ', ' ', ' ', ' ',
-                                            ' ', ' ', ' ', ' ',
-                                            ' ', ' ', ' ', ' '};
+    shellmatta_retCode_t        ret = SHELLMATTA_OK;
+    const shellmatta_instance_t *inst = (const shellmatta_instance_t*) handle;
+    shellmatta_cmd_t            *cmd = inst->cmdList;
+    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;
+    static const char           tabBuffer[] = { ' ', ' ', ' ', ' ',
+                                                ' ', ' ', ' ', ' ',
+                                                ' ', ' ', ' ', ' ',
+                                                ' ', ' ', ' ', ' '};
 
     /** -# loop through all commands to determine the lengths of each cmd */
     while(NULL != cmd)