fix printf with index outside token 92/21392/3
Antoine ELIAS [Sun, 23 Feb 2020 21:07:45 +0000 (22:07 +0100)]
Change-Id: Ieffb203eef642a0b8a7f2f68d5217e9a6067418e

scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp
scilab/modules/string/src/cpp/os_wtoi.cpp

index b084143..23b31e7 100644 (file)
@@ -134,10 +134,14 @@ wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput,
             wchar_t* pwstDollar = wcsstr(pwstStart + (token.size() == 0 ? 0 : 1), L"$");
             if (pwstDollar != nullptr && (pwstDollar - pwstFirstOutput) < end)
             {
-                argumentPos.push_back(os_wtoi(pwstStart + 1) - 1);
-                start = pwstDollar - pwstFirstOutput;
-                pwstFirstOutput[start] = L'%';
-                positioned = true;
+                int index = os_wtoi(pwstStart + 1);
+                if (index > 0)
+                {
+                    argumentPos.push_back(index - 1);
+                    start = pwstDollar - pwstFirstOutput;
+                    pwstFirstOutput[start] = L'%';
+                    positioned = true;
+                }
             }
         }
 
index 34cddae..ac0d7ef 100644 (file)
@@ -26,7 +26,7 @@ int os_wtoi(const wchar_t *_pwcsSource)
 {
     std::wstring wstr(_pwcsSource);
     std::wistringstream wstrm(wstr);
-    int num;
+    int num = 0;
     wstrm >> num;
     return num;
 }