Coverity: Core module errors fixed 11/18211/6 6.0.0-beta-2
Dhruv Khattar [Thu, 2 Jun 2016 18:56:32 +0000 (23:56 +0530)]
Change-Id: I7a1bd9aa470f0fc557a04cf1caa42360f8bd98f6

scilab/modules/core/includes/timer.hxx
scilab/modules/core/sci_gateway/cpp/sci_fieldnames.cpp
scilab/modules/core/src/c/backtrace.c
scilab/modules/core/src/c/getmemory.c
scilab/modules/core/src/c/getmodules.c
scilab/modules/core/src/c/loadversion.c
scilab/modules/core/src/cpp/InitScilab.cpp

index 1d8abe9..dbdea1b 100644 (file)
@@ -128,6 +128,7 @@ public:
     {
         // Print an optional message, something like "Checking timer t";
         double t = elapsed_time();
+        std::streamsize ss = std::cout.precision();
         if (_msg.empty() == false)
         {
             std::wcerr << L"[" << _msg << L"]" << L" : ";
@@ -135,7 +136,9 @@ public:
         std::wcerr << L"Elapsed time ["
                    << std::setiosflags(std::ios::fixed)
                    << std::setprecision(3)
-                   << t << L"] milliseconds"
+                   << t
+                   << std::setprecision(ss)
+                   << L"] milliseconds"
                    << std::endl;
 
         if (_bRestart == true)
index f22ebc6..d6c3af6 100644 (file)
@@ -108,7 +108,16 @@ types::Function::ReturnValue sci_fieldnames(types::typed_list &in, int _iRetCoun
         }
     }
 
-    types::String *pAllFields = pIT->getAs<types::String>();
+    types::String *pAllFields;
+    if (pIT)
+    {
+        pAllFields = pIT->getAs<types::String>();
+    }
+    else
+    {
+        Scierror(999, _("Could not retrieve sub-type.\n"));
+        return types::Function::Error;
+    }
     wchar_t **pwcsAllStrings =  pAllFields->get();
     // shift to forget first value corresponding to type.
     //    ++pwcsAllStrings;
index 4c10bd8..e0523e7 100644 (file)
@@ -149,7 +149,7 @@ sci_backtrace_t *sci_backtrace_create(void)
                 bt->s_file[i] = infos->dli_fname ? strdup(infos->dli_fname) : strdup(" ");
 
                 // we calculate the relative address in the library
-                snprintf(buffer, 32, "%p", p - infos->dli_fbase);
+                snprintf(buffer, 32, "%p", (void*)(p - infos->dli_fbase));
                 bt->s_addr[i] = strdup(buffer);
             }
         }
index baa7e16..24b670f 100644 (file)
@@ -135,7 +135,8 @@ int getfreememory(void)
                 {
                     case 'g':
                     case 'G':
-                        free *= kooctet;
+                        free *= kooctet*kooctet;
+                        break;
                     case 'm':
                     case 'M':
                         free *= kooctet;
@@ -143,6 +144,7 @@ int getfreememory(void)
                     case 'o':
                     case 'O':
                         free /= kooctet;
+                        break;
                 }
                 return (int)free;
             }
index 3cb13fd..7035212 100644 (file)
@@ -170,11 +170,8 @@ static BOOL AppendModules(char *xmlfilename)
             if (doc == NULL)
             {
                 printf(_("Error: Could not parse file %s.\n"), xmlfilename);
-                if (encoding)
-                {
-                    FREE(encoding);
-                    encoding = NULL;
-                }
+                FREE(encoding);
+                encoding = NULL;
                 return bOK;
             }
 
@@ -263,11 +260,8 @@ static BOOL AppendModules(char *xmlfilename)
         {
             printf(_("Error: Not a valid module file %s (encoding not '%s') Encoding '%s' found.\n"), xmlfilename, "utf-8", encoding);
         }
-        if (encoding)
-        {
-            FREE(encoding);
-            encoding = NULL;
-        }
+        FREE(encoding);
+        encoding = NULL;
     }
     return bOK;
 }
index ed0d3d0..95b5f93 100644 (file)
@@ -52,11 +52,8 @@ BOOL getversionmodule(wchar_t* _pwstModule,
         filename_VERSION_module = (char*)MALLOC(sizeof(char) * len);
         sprintf(filename_VERSION_module, FORMATVERSIONFILENAME, SciPath, pstModule);
         FREE(pstModule);
-        if (SciPath)
-        {
-            FREE(SciPath);
-            SciPath = NULL;
-        }
+        FREE(SciPath);
+        SciPath = NULL;
 
         if (FileExist(filename_VERSION_module))
         {
@@ -148,12 +145,16 @@ BOOL getversionmodule(wchar_t* _pwstModule,
                     *sci_version_minor = version_minor;
                     *sci_version_maintenance = version_maintenance;
                     *sci_version_revision = version_revision;
-                    wcscpy(_pwstSciVersionString, pwstSciVersionString);
                     if (pwstSciVersionString)
                     {
+                        wcscpy(_pwstSciVersionString, pwstSciVersionString);
                         FREE(pwstSciVersionString);
                         pwstSciVersionString = NULL;
                     }
+                    else
+                    {
+                        _pwstSciVersionString = NULL;
+                    }
                 }
                 else
                 {
@@ -177,11 +178,8 @@ BOOL getversionmodule(wchar_t* _pwstModule,
                 fprintf(stderr, _("Error: Not a valid version file %s (encoding not 'utf-8') Encoding '%s' found\n"), filename_VERSION_module, encoding);
             }
 
-            if (encoding)
-            {
-                FREE(encoding);
-                encoding = NULL;
-            }
+            FREE(encoding);
+            encoding = NULL;
             bOK = TRUE;
         }
         else
@@ -194,12 +192,8 @@ BOOL getversionmodule(wchar_t* _pwstModule,
             wcscpy(_pwstSciVersionString, L"");
             bOK = TRUE;
         }
-
-        if (filename_VERSION_module)
-        {
-            FREE(filename_VERSION_module);
-            filename_VERSION_module = NULL;
-        }
+        FREE(filename_VERSION_module);
+        filename_VERSION_module = NULL;
     }
     return bOK;
 }
index 4c2f1a8..36f0677 100644 (file)
@@ -602,6 +602,7 @@ void* scilabReadAndExecCommand(void* param)
         {
             scilabWriteW(parser.getErrorMessage());
             ThreadManagement::UnlockParser();
+            FREE(command);
             continue;
         }
 
@@ -988,6 +989,7 @@ static int batchMain(ScilabEngineInfo* _pSEI)
 #endif
     int ret = parser->getExitStatus();
     delete parser;
+    FREE(pwstFileName);
     return ret;
 }