summaryrefslogtreecommitdiffstats
path: root/scilab/modules
diff options
context:
space:
mode:
authorCedric Delamarre <cedric.delamarre@esi-group.com>2021-04-08 13:42:43 +0200
committerClément David <clement.david@esi-group.com>2021-04-12 16:01:24 +0200
commit384754bcc6eadd9c5f91f49d23b6750d5285c6f2 (patch)
tree2d8c0cdd757b911c70369ec0701fe7fa3be04830 /scilab/modules
parent8c60701b51050b48aa565965188c3f4a06ccf479 (diff)
downloadscilab-384754bcc6eadd9c5f91f49d23b6750d5285c6f2.zip
scilab-384754bcc6eadd9c5f91f49d23b6750d5285c6f2.tar.gz
* Bug 16661 fixed: now spzeros and sparse yield correct error messages
Messages about dimensions limitations are not explicit, see https://bugzilla.scilab.org/show_bug.cgi?id=16661 . It also: * restores big sparse features after 5b1796f8 * change error to warning when creating a sparse of size > INT_MAX Change-Id: I750ba1a5b2ba4e2d36876df75fb81fa80e63cfa3
Diffstat (limited to 'scilab/modules')
-rw-r--r--scilab/modules/sparse/sci_gateway/cpp/sci_sparse.cpp17
-rw-r--r--scilab/modules/sparse/sci_gateway/cpp/sci_spzeros.cpp22
-rw-r--r--scilab/modules/sparse/tests/nonreg_tests/bug_16661.tst30
3 files changed, 62 insertions, 7 deletions
diff --git a/scilab/modules/sparse/sci_gateway/cpp/sci_sparse.cpp b/scilab/modules/sparse/sci_gateway/cpp/sci_sparse.cpp
index 69e1028..6cf887a 100644
--- a/scilab/modules/sparse/sci_gateway/cpp/sci_sparse.cpp
+++ b/scilab/modules/sparse/sci_gateway/cpp/sci_sparse.cpp
@@ -24,6 +24,7 @@ extern "C"
24{ 24{
25#include "charEncoding.h" 25#include "charEncoding.h"
26#include "Scierror.h" 26#include "Scierror.h"
27#include "sciprint.h"
27#include "localization.h" 28#include "localization.h"
28} 29}
29 30
@@ -147,17 +148,27 @@ types::Function::ReturnValue sci_sparse(types::typed_list &in, int _piRetCount,
147 return types::Function::Error; 148 return types::Function::Error;
148 } 149 }
149 150
151 if ( pDdims->get(0) > (double) INT_MAX || pDdims->get(1) > (double) INT_MAX)
152 {
153 Scierror(999, _("%s: Wrong values for input argument #%d: Elements must be less than %d.\n"), "sparse", 3,INT_MAX);
154 return types::Function::Error;
155 }
156
150 if (pDdims->get(0) != (double) ( (unsigned int) pDdims->get(0) ) || pDdims->get(1) != (double) ( (unsigned int) pDdims->get(1) )) 157 if (pDdims->get(0) != (double) ( (unsigned int) pDdims->get(0) ) || pDdims->get(1) != (double) ( (unsigned int) pDdims->get(1) ))
151 { 158 {
152 Scierror(999, _("%s: Wrong values for input argument #%d: Positive integers expected.\n"), "sparse", 3); 159 Scierror(999, _("%s: Wrong values for input argument #%d: Positive integers expected.\n"), "sparse", 3);
153 return types::Function::Error; 160 return types::Function::Error;
154 } 161 }
155 162
156 if (pDdims->get(0) * pDdims->get(1) > INT_MAX) 163 if (pDdims->get(0) * pDdims->get(1) > (double) INT_MAX)
157 { 164 {
158 Scierror(999, _("%s: Wrong value for input argument #%d: The maximum total size expected is %d.\n"), "sparse", 3, INT_MAX); 165 // FIXME: should be an error. To fix we need GenericType::m_iSize huger than int
159 return types::Function::Error; 166 if (getWarningMode())
167 {
168 sciprint(_("%s: Warning: You have created a Sparse of size > %d.\nDue to a Scilab limitation, reading or writing values from/to \nthis sparse using a unique index could lead to unexpected behavior."), "sparse", INT_MAX);
169 }
160 } 170 }
171
161 } 172 }
162 173
163 bool alloc = false; 174 bool alloc = false;
diff --git a/scilab/modules/sparse/sci_gateway/cpp/sci_spzeros.cpp b/scilab/modules/sparse/sci_gateway/cpp/sci_spzeros.cpp
index 606347e..3b914c4 100644
--- a/scilab/modules/sparse/sci_gateway/cpp/sci_spzeros.cpp
+++ b/scilab/modules/sparse/sci_gateway/cpp/sci_spzeros.cpp
@@ -21,6 +21,7 @@ extern "C"
21{ 21{
22#include "charEncoding.h" 22#include "charEncoding.h"
23#include "Scierror.h" 23#include "Scierror.h"
24#include "sciprint.h"
24#include "localization.h" 25#include "localization.h"
25} 26}
26 27
@@ -73,22 +74,35 @@ types::Function::ReturnValue sci_spzeros(types::typed_list &in, int _iRetCount,
73 74
74 double dblRows = pDblRows->get(0); 75 double dblRows = pDblRows->get(0);
75 double dblCols = pDblCols->get(0); 76 double dblCols = pDblCols->get(0);
77 if (dblRows > (double) INT_MAX)
78 {
79 Scierror(999, _("%s: Wrong value for input argument #%d: Must be less than %d.\n"), "spzeros", 1,INT_MAX);
80 return types::Function::Error;
81 }
76 if (dblRows != (double) ((unsigned int) dblRows)) 82 if (dblRows != (double) ((unsigned int) dblRows))
77 { 83 {
78 Scierror(999, _("%s: Wrong value for input argument #%d: Scalar positive integer expected.\n"), "spzeros", 1); 84 Scierror(999, _("%s: Wrong value for input argument #%d: Scalar positive integer expected.\n"), "spzeros", 1);
79 return types::Function::Error; 85 return types::Function::Error;
80 } 86 }
81 87
88 if (dblCols > (double) INT_MAX)
89 {
90 Scierror(999, _("%s: Wrong value for input argument #%d: Must be less than %d.\n"), "spzeros", 2,INT_MAX);
91 return types::Function::Error;
92 }
82 if (dblCols != (double) ((unsigned int) dblCols)) 93 if (dblCols != (double) ((unsigned int) dblCols))
83 { 94 {
84 Scierror(999, _("%s: Wrong value for input argument #%d: Scalar positive integer expected.\n"), "spzeros", 2); 95 Scierror(999, _("%s: Wrong value for input argument #%d: Scalar positive integer expected.\n"), "spzeros", 1);
85 return types::Function::Error; 96 return types::Function::Error;
86 } 97 }
87 98
88 if (dblRows * dblCols > INT_MAX) 99 if (dblRows * dblCols > (double) INT_MAX)
89 { 100 {
90 Scierror(999, _("%s: Wrong value for input arguments: The maximum total size expected is %d.\n"), "spzeros", INT_MAX); 101 // FIXME: should be an error. To fix we need GenericType::m_iSize huger than int
91 return types::Function::Error; 102 if (getWarningMode())
103 {
104 sciprint(_("%s: Warning: You have created a Sparse of size > %d.\nDue to a Scilab limitation, reading or writing values from/to \nthis sparse using a unique index could lead to unexpected behavior."), "sparse", INT_MAX);
105 }
92 } 106 }
93 107
94 if (pDblRows->get(0) == 0. || pDblCols->get(0) == 0.) 108 if (pDblRows->get(0) == 0. || pDblCols->get(0) == 0.)
diff --git a/scilab/modules/sparse/tests/nonreg_tests/bug_16661.tst b/scilab/modules/sparse/tests/nonreg_tests/bug_16661.tst
new file mode 100644
index 0000000..8bb3e0e
--- /dev/null
+++ b/scilab/modules/sparse/tests/nonreg_tests/bug_16661.tst
@@ -0,0 +1,30 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2021 - Stéphane MOTTELET
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// <-- CLI SHELL MODE -->
8// <-- NO CHECK REF -->
9//
10// <-- Non-regression test for bug 16661 -->
11//
12// <-- Bugzilla URL -->
13// http://bugzilla.scilab.org/16661
14//
15// <-- Short Description -->
16// x=spzeros(1e10,1e10) yields an incorrect error message
17
18INT_MAX = int32(%inf);
19
20cmd = "spzeros(1e10,1)";
21msg = msprintf(_("%s: Wrong value for input argument #%d: Must be less than %d.\n"),"spzeros",1, INT_MAX)
22assert_checkerror(cmd,msg);
23
24cmd = "spzeros(1,1e10)";
25msg = msprintf(_("%s: Wrong value for input argument #%d: Must be less than %d.\n"),"spzeros",2, INT_MAX)
26assert_checkerror(cmd,msg);
27
28cmd = "sparse([1 1],1,[1e10,1e10])";
29msg = msprintf(_("%s: Wrong values for input argument #%d: Elements must be less than %d.\n"),"sparse",3,INT_MAX)
30assert_checkerror(cmd,msg);