From: Pierre-Aime Agnel Date: Tue, 25 Mar 2014 15:00:31 +0000 (+0100) Subject: bug 13272: fixed csvRead when looking for comments on a csv file without comments X-Git-Tag: 5.5.0~252 X-Git-Url: http://gitweb.scilab.org/?p=scilab.git;a=commitdiff_plain;h=c505edafeef5e50cedda0541c573c425c8fa6b3e bug 13272: fixed csvRead when looking for comments on a csv file without comments Change-Id: Ib0f5797abbb6a5ee6c144cf92591bba163b403d2 --- diff --git a/scilab/CHANGES_5.5.X b/scilab/CHANGES_5.5.X index 8b38c0f..ebf735f 100644 --- a/scilab/CHANGES_5.5.X +++ b/scilab/CHANGES_5.5.X @@ -821,6 +821,8 @@ Scilab Bug Fixes * Bug #13271 fixed - plot2d with logarithmic scale and %nan value freezed Scilab. +* Bug #13272 fixed - Error when reading CSV files with comment option on a CSV file without comment fixed. + * Bug #13280 fixed - Axes were not always displayed correctly after figure resizing. diff --git a/scilab/modules/spreadsheet/sci_gateway/c/sci_csvRead.c b/scilab/modules/spreadsheet/sci_gateway/c/sci_csvRead.c index ab29e3d..317aef7 100644 --- a/scilab/modules/spreadsheet/sci_gateway/c/sci_csvRead.c +++ b/scilab/modules/spreadsheet/sci_gateway/c/sci_csvRead.c @@ -42,6 +42,7 @@ int sci_csvRead(char *fname, unsigned long fname_len) { SciErr sciErr; int iErr = 0; + int iErrEmpty = 0; char *filename = NULL; char *separator = NULL; @@ -431,7 +432,15 @@ int sci_csvRead(char *fname, unsigned long fname_len) } else { - sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, result->nbComments, 1, result->pstrComments); + if (result->nbComments > 0) + { + sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, result->nbComments, 1, result->pstrComments); + } + else + { + iErrEmpty = createEmptyMatrix(pvApiCtx, Rhs+2); + sciErr.iErr = iErrEmpty; + } } if (sciErr.iErr) { diff --git a/scilab/modules/spreadsheet/tests/nonreg_tests/bug_13272.dia.ref b/scilab/modules/spreadsheet/tests/nonreg_tests/bug_13272.dia.ref new file mode 100644 index 0000000..de52d64 --- /dev/null +++ b/scilab/modules/spreadsheet/tests/nonreg_tests/bug_13272.dia.ref @@ -0,0 +1,24 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014 - Scilab Enterprises - Pierre-Aime Agnel +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 13272 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=13272 +// +// <-- Short Description --> +// csvRead does not return in error when looking for comments on a csv file where no comment is present +// csvRead returns an empty matrix for comment in this case +//Creating a test CSV file +dummyFile = TMPDIR + filesep() + "bug_13272.csv"; +csvWrite(['1', '', '3'; '', '', '6'], dummyFile); +//Files does not contain 7 as a comment +iErr = execstr("[M, comment] = csvRead(dummyFile, "","", ""."", ""string"", [], ""/7/"")", "errcatch"); +assert_checkequal(iErr, 0); +assert_checktrue(isempty(comment)); diff --git a/scilab/modules/spreadsheet/tests/nonreg_tests/bug_13272.tst b/scilab/modules/spreadsheet/tests/nonreg_tests/bug_13272.tst new file mode 100644 index 0000000..265c828 --- /dev/null +++ b/scilab/modules/spreadsheet/tests/nonreg_tests/bug_13272.tst @@ -0,0 +1,27 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014 - Scilab Enterprises - Pierre-Aime Agnel +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 13272 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=13272 +// +// <-- Short Description --> +// csvRead does not return in error when looking for comments on a csv file where no comment is present +// csvRead returns an empty matrix for comment in this case + +//Creating a test CSV file +dummyFile = TMPDIR + filesep() + "bug_13272.csv"; +csvWrite(['1', '', '3'; '', '', '6'], dummyFile); + +//Files does not contain 7 as a comment +iErr = execstr("[M, comment] = csvRead(dummyFile, "","", ""."", ""string"", [], ""/7/"")", "errcatch"); + +assert_checkequal(iErr, 0); +assert_checktrue(isempty(comment));