From 7f0f0b65c5a566cc9dfbd47eabf14a122c76a1f2 Mon Sep 17 00:00:00 2001 From: Allan CORNET Date: Tue, 19 Mar 2024 09:02:46 +0100 Subject: [PATCH] fix #1127 - Nelson could crash if an mxn characters is displayed in the variable browser --- CHANGELOG.md | 1 + modules/gui/src/cpp/QtWorkspaceBrowser.cpp | 8 ++++++-- modules/gui/tests/bug_github_issue_#1127.m | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 modules/gui/tests/bug_github_issue_#1127.m diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f8b923ec0..38a0f9a924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - [#1110](http://github.com/nelson-lang/nelson/issues/1110) add help about build and use C/C++ on fly. +- [#1127](http://github.com/nelson-lang/nelson/issues/1127) Nelson could crash if an mxn characters is displayed in the variable browser. - Missing 'zoom in', 'zoom out' icons for help viewer in linux package. - `gcd` without argument returned wrong error message. diff --git a/modules/gui/src/cpp/QtWorkspaceBrowser.cpp b/modules/gui/src/cpp/QtWorkspaceBrowser.cpp index c4fe65d591..3caecd1bb4 100644 --- a/modules/gui/src/cpp/QtWorkspaceBrowser.cpp +++ b/modules/gui/src/cpp/QtWorkspaceBrowser.cpp @@ -420,10 +420,14 @@ QtWorkspaceBrowser::handleLogicalVariable(const ArrayOf* variable) const QString QtWorkspaceBrowser::handleCharVariable(const ArrayOf* variable) const { - if (variable->isScalar()) { + if (variable->isEmpty()) { return "''"; } else { - return wstringToQString(L"\'" + variable->getContentAsWideString() + L"\'"); + if (variable->isRowVector() || variable->isScalar()) { + return wstringToQString(L"\'" + variable->getContentAsWideString() + L"\'"); + } else { + return wstringToQString(variable->getDimensions().toWideString() + L" char"); + } } } //============================================================================= diff --git a/modules/gui/tests/bug_github_issue_#1127.m b/modules/gui/tests/bug_github_issue_#1127.m new file mode 100644 index 0000000000..e0212aa229 --- /dev/null +++ b/modules/gui/tests/bug_github_issue_#1127.m @@ -0,0 +1,19 @@ +%============================================================================= +% Copyright (c) 2017 Allan CORNET (Nelson) +%============================================================================= +% This file is part of the Nelson. +%============================================================================= +% LICENCE_BLOCK_BEGIN +% SPDX-License-Identifier: LGPL-3.0-or-later +% LICENCE_BLOCK_END +%============================================================================= +% <-- Issue URL --> +% https://github.com/nelson-lang/nelson/issues/121 +% <-- Short Description --> +% Nelson could crash if an mxn characters is displayed in the variable browser. +%============================================================================= +% <--GUI MODE--> +A = 'g'; +B = 'Test'; +C = [B;B] +disp(C); \ No newline at end of file