summaryrefslogtreecommitdiffstats
path: root/scilab/modules/core
diff options
context:
space:
mode:
authorBernard HUGUENEY <bernard.hugueney@scilab.org>2010-04-19 13:43:08 +0200
committerBernard HUGUENEY <bernard.hugueney@scilab.org>2010-04-19 13:44:16 +0200
commit469d891612dd9f60a1e3bed8c89abe48b7ece3a6 (patch)
treec291b382d912c7f5289a6e49f7624a85158807c9 /scilab/modules/core
parent388a3f48470ad6896f60e24752241687486c9a3e (diff)
downloadscilab-469d891612dd9f60a1e3bed8c89abe48b7ece3a6.zip
scilab-469d891612dd9f60a1e3bed8c89abe48b7ece3a6.tar.gz
Fix #6931
Was assuming valid (length<nlgh) names in namstr, now truncates when needed. Change-Id: Ic484e58cc49dbf28c1be9975de2c1bbc9702de2c
Diffstat (limited to 'scilab/modules/core')
-rw-r--r--scilab/modules/core/src/cpp/namstr.cpp7
-rw-r--r--scilab/modules/core/tests/nonreg_tests/bug_6931.dia.ref19
-rw-r--r--scilab/modules/core/tests/nonreg_tests/bug_6931.tst22
3 files changed, 45 insertions, 3 deletions
diff --git a/scilab/modules/core/src/cpp/namstr.cpp b/scilab/modules/core/src/cpp/namstr.cpp
index 3dba511..f681894 100644
--- a/scilab/modules/core/src/cpp/namstr.cpp
+++ b/scilab/modules/core/src/cpp/namstr.cpp
@@ -11,7 +11,7 @@
11 */ 11 */
12#include "machine.h" /* C2F */ 12#include "machine.h" /* C2F */
13#include "stack-def.h" /* nsiz, nlgh */ 13#include "stack-def.h" /* nsiz, nlgh */
14 14#include <algorithm>
15extern "C" 15extern "C"
16{ 16{
17 void C2F(namstr)(int* id, int* str, int* n, char* job); 17 void C2F(namstr)(int* id, int* str, int* n, char* job);
@@ -72,8 +72,9 @@ void C2F(namstr)(int* id,int* str, int* n, char* job)
72 { /* str -> id */ 72 { /* str -> id */
73 /* n (<= nsiz*4 = nlgh) int in str packed into id */ 73 /* n (<= nsiz*4 = nlgh) int in str packed into id */
74 unsigned int j; 74 unsigned int j;
75 /* a full id contains 4 ints from str, so we have *n/4 full ids the remaing are padded with blanks */ 75 /* a full id contains 4 ints from str, so we have *n/4 full ids the remaing are padded with blanks
76 unsigned const int full_ids((*n)/4); 76 we can get *n > nlgh (we truncate @ nsiz ids) */
77 unsigned const int full_ids(std::min(*n/4, nsiz));
77 78
78 for (j= 0; j!=full_ids; ++j) 79 for (j= 0; j!=full_ids; ++j)
79 { /* str int are signed bytes in fact, we pack them using shifts */ 80 { /* str int are signed bytes in fact, we pack them using shifts */
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_6931.dia.ref b/scilab/modules/core/tests/nonreg_tests/bug_6931.dia.ref
new file mode 100644
index 0000000..1ca5236
--- /dev/null
+++ b/scilab/modules/core/tests/nonreg_tests/bug_6931.dia.ref
@@ -0,0 +1,19 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Bernard HUGUENEY
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// <-- Non-regression test for bug 6931 -->
8//
9// <-- Bugzilla URL -->
10// http://bugzilla.scilab.org/show_bug.cgi?id=6931
11//
12// <-- Short Description -->
13// Crash when using a name with size > nlgh (=24)
14//
15A = '';
16for i=1:128
17 A=A+'t';
18 exists(sprintf('%s',A));
19end
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_6931.tst b/scilab/modules/core/tests/nonreg_tests/bug_6931.tst
new file mode 100644
index 0000000..9d2194c
--- /dev/null
+++ b/scilab/modules/core/tests/nonreg_tests/bug_6931.tst
@@ -0,0 +1,22 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Bernard HUGUENEY
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7
8// <-- Non-regression test for bug 6931 -->
9//
10// <-- Bugzilla URL -->
11// http://bugzilla.scilab.org/show_bug.cgi?id=6931
12//
13// <-- Short Description -->
14// Crash when using a name with size > nlgh (=24)
15//
16
17A = '';
18for i=1:128
19 A=A+'t';
20 exists(sprintf('%s',A));
21end
22