summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStéphane Mottelet <stephane.mottelet@utc.fr>2019-06-20 10:53:06 +0200
committerClément DAVID <clement.david@esi-group.com>2019-07-24 11:22:05 +0200
commit8fcb322b6d7d675cc2f67eba9e81a178d2534349 (patch)
tree65ef105b31a1bade3607037806a73a6ca6a59a4e
parentedaf386bc36a4c6efee23dfe1f5a28f9d053272f (diff)
downloadscilab-8fcb322b6d7d675cc2f67eba9e81a178d2534349.zip
scilab-8fcb322b6d7d675cc2f67eba9e81a178d2534349.tar.gz
* Bug 15715 fixed: now %nan indexes do not crash Scilab
http://bugzilla.scilab.org/show_bug.cgi?id=15715 Change-Id: Ic3958e233c34548a1b873cda84ae3f42f962e16a
-rw-r--r--scilab/CHANGES.md1
-rw-r--r--scilab/modules/ast/src/cpp/types/types_tools.cpp41
-rw-r--r--scilab/modules/ast/tests/nonreg_tests/bug_15715.tst28
3 files changed, 50 insertions, 20 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index 0b2f115..79f2f24 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -160,6 +160,7 @@ Bug Fixes
160* [#15248](http://bugzilla.scilab.org/show_bug.cgi?id=15248): `lsq()`was leaking memory. 160* [#15248](http://bugzilla.scilab.org/show_bug.cgi?id=15248): `lsq()`was leaking memory.
161* [#15577](http://bugzilla.scilab.org/show_bug.cgi?id=15577): `edit` did not accept a line number as text, as with `edit linspace 21`. 161* [#15577](http://bugzilla.scilab.org/show_bug.cgi?id=15577): `edit` did not accept a line number as text, as with `edit linspace 21`.
162* [#15668](http://bugzilla.scilab.org/show_bug.cgi?id=15668): `save(filename)` saved all predefined Scilab constants %e %pi etc.. (regression) 162* [#15668](http://bugzilla.scilab.org/show_bug.cgi?id=15668): `save(filename)` saved all predefined Scilab constants %e %pi etc.. (regression)
163* [#15715](http://bugzilla.scilab.org/show_bug.cgi?id=15715): `%nan` indices crashed Scilab.
163* [#15812](http://bugzilla.scilab.org/show_bug.cgi?id=15812): On assigning variables the source variable may become become corrupted 164* [#15812](http://bugzilla.scilab.org/show_bug.cgi?id=15812): On assigning variables the source variable may become become corrupted
164* [#15840](http://bugzilla.scilab.org/show_bug.cgi?id=15840): `grand(1,"prm",m)` yielded an unsqueezed size([size(m) 1]) hypermatrix 165* [#15840](http://bugzilla.scilab.org/show_bug.cgi?id=15840): `grand(1,"prm",m)` yielded an unsqueezed size([size(m) 1]) hypermatrix
165* [#15964](http://bugzilla.scilab.org/show_bug.cgi?id=15954): A complex empty sparse matrix could be obtained after insertion. 166* [#15964](http://bugzilla.scilab.org/show_bug.cgi?id=15954): A complex empty sparse matrix could be obtained after insertion.
diff --git a/scilab/modules/ast/src/cpp/types/types_tools.cpp b/scilab/modules/ast/src/cpp/types/types_tools.cpp
index 8f132da..023cce5 100644
--- a/scilab/modules/ast/src/cpp/types/types_tools.cpp
+++ b/scilab/modules/ast/src/cpp/types/types_tools.cpp
@@ -396,7 +396,7 @@ bool getImplicitIndex(GenericType* _pRef, typed_list* _pArgsIn, std::vector<int>
396 } 396 }
397 397
398 double val = start - 1; 398 double val = start - 1;
399 std::generate(idx.begin(), idx.end(), [&val, step]{ double s = val; val += step; return (int)s; }); 399 std::generate(idx.begin(), idx.end(), [&val, step] { double s = val; val += step; return (int)s; });
400 400
401 lstIdx.push_back(idx); 401 lstIdx.push_back(idx);
402 finalSize *= size; 402 finalSize *= size;
@@ -530,10 +530,10 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
530 { 530 {
531 int size = pCurrentArg->getSize(); 531 int size = pCurrentArg->getSize();
532 double* dbl = pCurrentArg->get(); 532 double* dbl = pCurrentArg->get();
533 double minIndex = _pRef==NULL || _pRef->isList()==false ? 1 : 0; 533 double minIndex = _pRef == NULL || _pRef->isList() == false ? 1 : 0;
534 for (int j = 0; j < size; ++j) 534 for (int j = 0; j < size; ++j)
535 { 535 {
536 if (dbl[j] < minIndex) 536 if (dbl[j] < minIndex || isnan(dbl[j]))
537 { 537 {
538 if (pCurrentArg->isDeletable()) 538 if (pCurrentArg->isDeletable())
539 { 539 {
@@ -557,8 +557,8 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
557 if (_pRef == NULL) 557 if (_pRef == NULL)
558 { 558 {
559 if (pIL->getStep()->isDouble() && 559 if (pIL->getStep()->isDouble() &&
560 ((getIndex(pIL->getStep()) > 0 && pIL->getStart()->isDouble() && getIndex(pIL->getStart()) < 1) || 560 ((getIndex(pIL->getStep()) > 0 && pIL->getStart()->isDouble() && getIndex(pIL->getStart()) < 1) ||
561 (getIndex(pIL->getStep()) < 0 && pIL->getEnd()->isDouble() && getIndex(pIL->getEnd()) < 1))) 561 (getIndex(pIL->getStep()) < 0 && pIL->getEnd()->isDouble() && getIndex(pIL->getEnd()) < 1)))
562 { 562 {
563 pCurrentArg = NULL; 563 pCurrentArg = NULL;
564 } 564 }
@@ -572,42 +572,43 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
572 } 572 }
573 } 573 }
574 else 574 else
575 { //evalute polynom with "MaxDim" 575 {
576 //evalute polynom with "MaxDim"
576 int iMaxDim = _pRef->getAs<GenericType>()->getVarMaxDim(i, iDims); 577 int iMaxDim = _pRef->getAs<GenericType>()->getVarMaxDim(i, iDims);
577 #if defined(_SCILAB_DEBUGREF_) 578#if defined(_SCILAB_DEBUGREF_)
578 Double* pdbl = new Double(iMaxDim); 579 Double* pdbl = new Double(iMaxDim);
579 #else 580#else
580 Double dbl(iMaxDim); 581 Double dbl(iMaxDim);
581 #endif 582#endif
582 if (pIL->getStart()->isPoly()) 583 if (pIL->getStart()->isPoly())
583 { 584 {
584 Polynom *poPoly = pIL->getStart()->getAs<types::Polynom>(); 585 Polynom *poPoly = pIL->getStart()->getAs<types::Polynom>();
585 #if defined(_SCILAB_DEBUGREF_) 586#if defined(_SCILAB_DEBUGREF_)
586 pIL->setStart(poPoly->evaluate(pdbl)); 587 pIL->setStart(poPoly->evaluate(pdbl));
587 #else 588#else
588 pIL->setStart(poPoly->evaluate(&dbl)); 589 pIL->setStart(poPoly->evaluate(&dbl));
589 #endif 590#endif
590 } 591 }
591 if (pIL->getStep()->isPoly()) 592 if (pIL->getStep()->isPoly())
592 { 593 {
593 Polynom *poPoly = pIL->getStep()->getAs<types::Polynom>(); 594 Polynom *poPoly = pIL->getStep()->getAs<types::Polynom>();
594 #if defined(_SCILAB_DEBUGREF_) 595#if defined(_SCILAB_DEBUGREF_)
595 pIL->setStep(poPoly->evaluate(pdbl)); 596 pIL->setStep(poPoly->evaluate(pdbl));
596 #else 597#else
597 pIL->setStep(poPoly->evaluate(&dbl)); 598 pIL->setStep(poPoly->evaluate(&dbl));
598 #endif 599#endif
599 } 600 }
600 if (pIL->getEnd()->isPoly()) 601 if (pIL->getEnd()->isPoly())
601 { 602 {
602 Polynom *poPoly = pIL->getEnd()->getAs<types::Polynom>(); 603 Polynom *poPoly = pIL->getEnd()->getAs<types::Polynom>();
603 #if defined(_SCILAB_DEBUGREF_) 604#if defined(_SCILAB_DEBUGREF_)
604 pIL->setEnd(poPoly->evaluate(pdbl)); 605 pIL->setEnd(poPoly->evaluate(pdbl));
605 #else 606#else
606 pIL->setEnd(poPoly->evaluate(&dbl)); 607 pIL->setEnd(poPoly->evaluate(&dbl));
607 #endif 608#endif
608 } 609 }
609 610
610 #if defined(_SCILAB_DEBUGREF_) 611#if defined(_SCILAB_DEBUGREF_)
611 pdbl->killMe(); 612 pdbl->killMe();
612#endif 613#endif
613 } 614 }
@@ -626,7 +627,7 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
626 else if (pIT->isString()) 627 else if (pIT->isString())
627 { 628 {
628 String* pStr = pIT->getAs<String>(); 629 String* pStr = pIT->getAs<String>();
629 if(!_pRef) 630 if (!_pRef)
630 { 631 {
631 bUndefine = true; 632 bUndefine = true;
632 continue; 633 continue;
diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_15715.tst b/scilab/modules/ast/tests/nonreg_tests/bug_15715.tst
new file mode 100644
index 0000000..f465121
--- /dev/null
+++ b/scilab/modules/ast/tests/nonreg_tests/bug_15715.tst
@@ -0,0 +1,28 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2019 - Stéphane MOTTELET
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7//
8// <-- CLI SHELL MODE -->
9// <-- NO CHECK REF -->
10//
11// <-- Non-regression test for bug 15715 -->
12//
13// <-- Bugzilla URL -->
14// http://bugzilla.scilab.org/15715
15//
16// <-- Short Description -->
17// Referencing a 2D array with one valid index and %nan for the second index causes a crash
18
19A = eye(3,3);
20message = msprintf(gettext("Invalid index.\n"));
21
22assert_checkerror("A(%nan,1)",message)
23assert_checkerror("A(%nan,%nan)",message)
24assert_checkerror("A(1,%nan)",message)
25assert_checkerror("A(%nan,%nan)=1",message)
26assert_checkerror("A(%nan,1)=1",message)
27assert_checkerror("A(1,%nan)=1",message)
28