From 727ec81eb0bc6639f47a4bc41c53afde90f797b4 Mon Sep 17 00:00:00 2001 From: Clement David Date: Tue, 31 Mar 2020 15:16:11 +0200 Subject: [PATCH] * bug #16399 fixed - zeros() with empty list extraction failed. Change-Id: Idd22687b2d32d49acf031fbe10e5433002fb6e4b --- scilab/CHANGES.md | 1 + .../sci_gateway/cpp/elem_func_gw.cpp | 7 ++++--- .../tests/unit_tests/zeros.tst | 9 +++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index e53564a..818eb9f 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -269,6 +269,7 @@ Bug Fixes * [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2. * [#16350](https://bugzilla.scilab.org/16350): in if/while conditions, the empty sparse boolean was considered as TRUE. * [#16365](https://bugzilla.scilab.org/16365): `median(m,"r")` and `median(m,"c")` yielded wrong results (6.1.0 regression) +* [#16399](https://bugzilla.scilab.org/16399): `mtlb_zeros([])` was crashing Scilab. * [#16401](https://bugzilla.scilab.org/16401): global `external_object_java` class was crashing Scilab. * [#16403](https://bugzilla.scilab.org/16403): 1D extraction of matrix with implicit index had wrong dimensions. diff --git a/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw.cpp b/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw.cpp index f8f7946..2207cef 100644 --- a/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw.cpp +++ b/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw.cpp @@ -306,9 +306,10 @@ types::Function::ReturnValue zerosOrOnesFromValue(types::typed_list& in, int _iR bool alloc = false; int size = (int)in.size(); - types::InternalType* it = in[size - 1]; - if (size > 1 && it->isString()) + if (size > 1 && in[size - 1]->isString()) { + types::InternalType* it = in[size - 1]; + // get optional type string wchar_t* pType = it->getAs()->get()[0]; auto f = mapOfTypes.find(pType); @@ -350,7 +351,7 @@ types::Function::ReturnValue zerosOrOnesFromValue(types::typed_list& in, int _iR switch (reftype) { case types::InternalType::ScilabInt8: - { + { types::Int8* pOut = new types::Int8(iDims, piDims); std::fill(pOut->get(), pOut->get() + pOut->getSize(), value); out.push_back(pOut); diff --git a/scilab/modules/elementary_functions/tests/unit_tests/zeros.tst b/scilab/modules/elementary_functions/tests/unit_tests/zeros.tst index 58aa06b..f930499 100644 --- a/scilab/modules/elementary_functions/tests/unit_tests/zeros.tst +++ b/scilab/modules/elementary_functions/tests/unit_tests/zeros.tst @@ -13,10 +13,19 @@ res(2,3,4) = 0; computed = list([], 1, 10, list(2,3), list(2,3,4)); expected = list([], 0, 0, [0 0 0;0 0 0], res); +assert_checkequal(zeros(), 0); for i = 1:size(computed) assert_checkequal(zeros(computed(i)(:)), expected(i)); end +// by list extraction +l = list(1, 2, 3) +assert_checkequal(zeros(l(1:0)), 0); +assert_checkequal(zeros(l(1:1)), 0); +assert_checkequal(zeros(l(1:2)), [0, 0]); +assert_checkequal(zeros(l(1:3)), matrix([0, 0, 0, 0, 0, 0] , 1, 2, 3)); + + data = rand(4, 3, 2) * 1000; dataz = zeros(data); -- 1.7.9.5