From 2ed785495eb3c052675c78c738d2cf1325648f9a Mon Sep 17 00:00:00 2001 From: Chin Luh TAN Date: Sat, 14 Mar 2020 02:10:33 -0700 Subject: [PATCH] * Bug 16373 fixed: fix issue of crashing in arm when displaying 0 https://bugzilla.scilab.org/16373 --> a = 1; --> b = 0; --> a a = 1. --> b b = terminate called after throwing an instance of 'std::length_error' what(): basic_string::_M_replace_aux A fatal error has been detected by Scilab. Please check your user-defined functions (or external module ones) should they appear in the stack trace. Otherwise you can report a bug on http://bugzilla.scilab.org/ with: * a sample code which reproduces the issue * the result of [a, b] = getdebuginfo() * the following information: [ubuntu:24308] Signal: Aborted (6) [ubuntu:24308] Signal code: (-6) Change-Id: Ibfcd025545c251164a91ab1c3bcf7c5b08271cbb --- scilab/CHANGES.md | 1 + .../modules/ast/src/cpp/types/tostring_common.cpp | 17 ++++++++++----- .../ast/tests/nonreg_tests/bug_16373.dia.ref | 22 ++++++++++++++++++++ .../modules/ast/tests/nonreg_tests/bug_16373.tst | 18 ++++++++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 scilab/modules/ast/tests/nonreg_tests/bug_16373.dia.ref create mode 100644 scilab/modules/ast/tests/nonreg_tests/bug_16373.tst diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index 58ec4be..05c614b 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -528,3 +528,4 @@ Bug Fixes * [#16323](https://bugzilla.scilab.org/16323): `conj(sparse(x))` was complex when x is real. * [#16325](https://bugzilla.scilab.org/16325): `mgetl` could not read single line data which is greater than ~260,000 characters. * [#16333](https://bugzilla.scilab.org/16333): `tree_show` crashed for an input Xcos block. +* [#16373](https://bugzilla.scilab.org/16373): Scilab Crashed or showing wrong output when running on Arm processor diff --git a/scilab/modules/ast/src/cpp/types/tostring_common.cpp b/scilab/modules/ast/src/cpp/types/tostring_common.cpp index 0df8d0c..55c567d 100644 --- a/scilab/modules/ast/src/cpp/types/tostring_common.cpp +++ b/scilab/modules/ast/src/cpp/types/tostring_common.cpp @@ -106,7 +106,14 @@ void getDoubleFormat(double _dblVal, DoubleFormat * _pDF) if (dblEnt == 0) { //[-1, 1] - iNbDigit = (int)std::fabs(std::floor(std::log10(dblAbs))); + if (dblAbs == 0) + { + iNbDigit = -1; + } + else + { + iNbDigit = (int)std::fabs(std::floor(std::log10(dblAbs))); + } if (iNbDigit >= (iPrecNeeded - 2) || _pDF->bExp) { @@ -180,8 +187,8 @@ void getComplexFormat(double _dblR, double _dblI, int *_piTotalWidth, DoubleForm { getDoubleFormat(_dblR, _pDFR); getDoubleFormat(_dblI, _pDFI); - - *_piTotalWidth = _pDFR->iWidth + _pDFI->iWidth + 2*(_pDFR->bPrintBlank ? BLANK_SIZE : 0) + BLANK_SIZE + SIZE_SYMBOL_I; + + *_piTotalWidth = _pDFR->iWidth + _pDFI->iWidth + 2 * (_pDFR->bPrintBlank ? BLANK_SIZE : 0) + BLANK_SIZE + SIZE_SYMBOL_I; } void addDoubleValue(std::wostringstream * _postr, double _dblVal, DoubleFormat * _pDF) @@ -297,11 +304,11 @@ void addDoubleValue(std::wostringstream * _postr, double _dblVal, DoubleFormat * // trim or append trailing zeros, if applicable if (_pDF->bPrintPoint == false) { - iWidth = 1+str.length(); + iWidth = 1 + str.length(); } else if (std::atof(str.data()) != fabs(_dblVal) && _pDF->bPrintTrailingZeros == true) { - str.append(std::max(0, (ConfigVariable::getFormatSize() - (int)str.length()))-1, '0'); + str.append(std::max(0, (ConfigVariable::getFormatSize() - (int)str.length())) - 1, '0'); } wchar_t* pwstData = to_wide_string(str.data()); diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_16373.dia.ref b/scilab/modules/ast/tests/nonreg_tests/bug_16373.dia.ref new file mode 100644 index 0000000..6dc97d4 --- /dev/null +++ b/scilab/modules/ast/tests/nonreg_tests/bug_16373.dia.ref @@ -0,0 +1,22 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2019 - Chin Luh TAN +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 16373 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/16373 +// +// <-- Short Description --> +//fix issue of crashing in arm when displaying 0 + +a = 0 + a = + + 0. + diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_16373.tst b/scilab/modules/ast/tests/nonreg_tests/bug_16373.tst new file mode 100644 index 0000000..d16568a --- /dev/null +++ b/scilab/modules/ast/tests/nonreg_tests/bug_16373.tst @@ -0,0 +1,18 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2019 - Chin Luh TAN +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 16373 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/16373 +// +// <-- Short Description --> +//fix issue of crashing in arm when displaying 0 + +a = 0 -- 1.7.9.5