static void updatel(TokenDef* token);
static void replace_lu_llu(TokenDef* token);
static void replace_ld_lld(TokenDef* token);
+static void print_nan_or_inf(wchar_t* pwstTemp, double dblVal, const wchar_t* token, int pos, int width);
#define NanString L"Nan"
#define InfString L"Inf"
wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput, types::typed_list &in, int* _piOutputRows, int* _piNewLine)
{
wchar_t** pwstOutput = nullptr;
- int rhs = in.size();
+ int rhs = static_cast<int>(in.size());
wchar_t* pwstFirstOutput = nullptr;
*_piNewLine = 0;
int col = 0;
wchar_t* pwstPercent = wcsstr(tok->pwstToken, L"%");
if (pwstPercent != nullptr && percentpercent == false)
{
+ int offset = 1;
//looking for flags
if (*(pwstPercent + 1) == L'-' ||
*(pwstPercent + 1) == L'+' ||
*(pwstPercent + 1) == L'#' ||
*(pwstPercent + 1) == L'0')
{
- pwstPercent++;
+ offset = 2;
}
//looking for width
- if (*(pwstPercent + 1) == L'*')
+ if (*(pwstPercent + offset) == L'*')
{
if (itPos == inPos.end())
{
else
{
//number
- if (iswdigit(*(pwstPercent + 1)))
+ if (iswdigit(*(pwstPercent + offset)))
{
tok->width = os_wtoi(pwstPercent + 1);
- while (iswdigit(*(pwstPercent + 1)))
+ while (iswdigit(*(pwstPercent + offset)))
{
pwstPercent++;
}
}
}
+ pwstPercent += (offset - 1);
+
//looking for precision
if (*(pwstPercent + 1) == L'.')
{
}
wchar_t wcType = *(pwstPercent + 1);
- tok->typePos = (pwstPercent + 1) - tok->pwstToken;
+ tok->typePos = static_cast<int>((pwstPercent + 1) - tok->pwstToken);
switch (wcType)
{
}
else
{
- wchar_t* newToken = replace_with_ls(tok);
-
- if (std::isnan(dblVal))
- {
- os_swprintf(pwstTemp, bsiz, newToken, NanString);
- }
- else if (std::signbit(dblVal))
- {
- os_swprintf(pwstTemp, bsiz, newToken, NegInfString);
- }
- else
- {
- os_swprintf(pwstTemp, bsiz, newToken, InfString);
- }
-
- delete[] newToken;
+ print_nan_or_inf(pwstTemp, dblVal, token, tok->typePos, tok->width);
}
oFirstOutput << pwstTemp;
}
else
{
- wchar_t* newToken = replace_with_ls(tok);
-
- if (std::isnan(dblVal))
- {
- os_swprintf(pwstTemp, bsiz, newToken, NanString);
- }
- else
- {
- if (std::signbit(dblVal))
- {
- os_swprintf(pwstTemp, bsiz, newToken, NegInfString);
- }
- else
- {
- os_swprintf(pwstTemp, bsiz, newToken, InfString);
- }
- }
-
- delete[] newToken;
+ print_nan_or_inf(pwstTemp, dblVal, token, tok->typePos, tok->width);
}
oFirstOutput << pwstTemp;
}
else
{
- wchar_t* newToken = replace_with_ls(tok);
-
- if (std::isnan(dblVal))
- {
- os_swprintf(pwstTemp, bsiz, newToken, NanString);
- }
- else
- {
- if (std::signbit(dblVal))
- {
- os_swprintf(pwstTemp, bsiz, newToken, NegInfString);
- }
- else
- {
- os_swprintf(pwstTemp, bsiz, newToken, InfString);
- }
- }
-
- delete[] newToken;
+ print_nan_or_inf(pwstTemp, dblVal, token, tok->typePos, tok->width);
}
oFirstOutput << pwstTemp;
// skip LF
tmpToken = ++lf;
// if not at the end of token, continue with same token
- if(lf - tok->pwstToken < wcslen(tok->pwstToken))
+ if(static_cast<size_t>(lf - tok->pwstToken) < wcslen(tok->pwstToken))
{
continue;
}
}
#endif
}
+/*--------------------------------------------------------------------------*/
+static void print_nan_or_inf(wchar_t* pwstTemp, double dblVal, const wchar_t* token, int pos, int width)
+{
+ int sizeTotal = (int)wcslen(token);
+ wchar_t* pwstToken = new wchar_t[sizeTotal + 2]{ 0 };
+
+ if (width)
+ {
+ os_swprintf(pwstToken, sizeTotal + 2, L"%%%dls%ls", width, token + pos + 1);
+ }
+ else
+ {
+ os_swprintf(pwstToken, sizeTotal + 2, L"%%ls%ls", token + pos + 1);
+ }
+
+ if (std::isnan(dblVal))
+ {
+ os_swprintf(pwstTemp, bsiz, pwstToken, NanString);
+ }
+ else if (std::signbit(dblVal))
+ {
+ os_swprintf(pwstTemp, bsiz, pwstToken, NegInfString);
+ }
+ else
+ {
+ os_swprintf(pwstTemp, bsiz, pwstToken, InfString);
+ }
+
+ delete[] pwstToken;
+
+}
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2020 - ESI Group - Clement DAVID
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+
+// <-- Non-regression test for bug 14742 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=14742
+//
+// <-- ENGLISH IMPOSED -->
+
+// <-- Short Description -->
+// Wrong display of Inf or Nan
+//
+
+assert_checkequal(" Nan", msprintf('%4.1f',%nan));
+assert_checkequal(" Inf", msprintf('%4.1f',%inf));
+assert_checkequal("-Inf", msprintf('%4.1f',-%inf));
+
+assert_checkequal("Nan ", msprintf('%-4.1f',%nan));
+assert_checkequal("Inf ", msprintf('%-4.1f',%inf));
+assert_checkequal("-Inf", msprintf('%-4.1f',-%inf));
+
+assert_checkequal("Nan", msprintf('%1.1f',%nan));
+assert_checkequal("Inf", msprintf('%1.1f',%inf));
+assert_checkequal("-Inf", msprintf('%1.1f',-%inf));
+
+assert_checkequal("Nan", msprintf('%-1.1f',%nan));
+assert_checkequal("Inf", msprintf('%-1.1f',%inf));
+assert_checkequal("-Inf", msprintf('%-1.1f',-%inf));
+
+F="%10.3f";
+assert_checkequal(" 3.000 Nan 5.000", msprintf(F+F+F, [3,%nan,5]));
+assert_checkequal(" 3.000 Inf 5.000", msprintf(F+F+F, [3,%inf,5]));
+assert_checkequal(" 3.000 -Inf 5.000", msprintf(F+F+F, [3,-%inf,5]));
+
+F="%-10.3f";
+assert_checkequal("3.000 Nan 5.000 ", msprintf(F+F+F, [3,%nan,5]));
+assert_checkequal("3.000 Inf 5.000 ", msprintf(F+F+F, [3,%inf,5]));
+assert_checkequal("3.000 -Inf 5.000 ", msprintf(F+F+F, [3,-%inf,5]));
+
+
+assert_checkequal(["a = Inf";"b = Inf"], msprintf("a = %f\nb = %f", %inf, %inf));
+assert_checkequal(["a = Nan";"b = Nan"], msprintf("a = %f\nb = %f", %nan, %nan));
+
+assert_checkequal(["a = Inf";"b = Inf"], msprintf("a = %f\nb = %f\n", %inf, %inf));
+assert_checkequal(["a = Nan";"b = Nan"], msprintf("a = %f\nb = %f\n", %nan, %nan));
+
+assert_checkequal("Inffoo", msprintf("%ffoo\n", %inf));
+assert_checkequal("Nanfoo", msprintf("%ffoo\n", %nan));
+
+assert_checkequal("fooInf", msprintf("foo%f\n", %inf));
+assert_checkequal("fooNan", msprintf("foo%f\n", %nan));
+
+assert_checkequal("fooInfbar", msprintf("foo%fbar\n", %inf));
+assert_checkequal("fooNanbar", msprintf("foo%fbar\n", %nan));
+