From c5d736349a04f5e856f061ee35676a7d899434b4 Mon Sep 17 00:00:00 2001 From: Anais AUBERT Date: Thu, 30 Apr 2015 12:32:03 +0200 Subject: [PATCH] fix xclick getcolor() //clic on a color or close cross, it should not segfault Change-Id: Id776d6ffa0b1982963b2c3fbab35040bc238f223 --- scilab/modules/api_scilab/src/cpp/api_string.cpp | 43 +++++++++++--------- scilab/modules/graphics/sci_gateway/c/sci_xclick.c | 5 +-- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/scilab/modules/api_scilab/src/cpp/api_string.cpp b/scilab/modules/api_scilab/src/cpp/api_string.cpp index be1d71d..4ec70ed 100644 --- a/scilab/modules/api_scilab/src/cpp/api_string.cpp +++ b/scilab/modules/api_scilab/src/cpp/api_string.cpp @@ -2,6 +2,7 @@ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab * Copyright (C) 2009 - DIGITEO - Antoine ELIAS * Copyright (C) 2009-2011 - DIGITEO - Allan CORNET + * Copyright (C) 2015 - Scilab Enterprises - Anais AUBERT * * This file must be used under the terms of the CeCILL. * This source file is licensed as described in the file COPYING, which @@ -771,34 +772,36 @@ int createSingleString(void* _pvCtx, int _iVar, const char* _pstStrings) int allocSingleString(void* _pvCtx, int _iVar, int _iLen, const char** _pstStrings) { SciErr sciErr = sciErrInit(); -#if 0 - int iNewPos = Top - Rhs + _iVar; - int iAddr = *Lstk(iNewPos); - int* piAddr = NULL; - int* piOffset = NULL; - char* pstString = NULL; - int iFreeSpace = iadr(*Lstk(Bot)) - (iadr(*Lstk(Top))); + GatewayStruct* pGstr = (GatewayStruct*)_pvCtx; + typed_list in = *pGstr->m_pIn; + InternalType** out = pGstr->m_pOut; + String *pStr = NULL; - if (_iLen + 2 > iFreeSpace) + + char* pstStrings = new char[_iLen]; + + memset(pstStrings, ' ', _iLen); + _pstStrings[0] = pstStrings; + if (_pstStrings == NULL) { - addStackSizeError(&sciErr, ((StrCtx*)_pvCtx)->pstName, _iLen + 2); + addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocate variable"), "allocSingleString"); return sciErr.iErr; } - getNewVarAddressFromPosition(_pvCtx, iNewPos, &piAddr); + pStr = new String(pstStrings); - piAddr[0] = sci_strings; - piAddr[1] = 1; - piAddr[2] = 1; - piAddr[3] = 0; + if (pStr == NULL) + { + addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocate variable"), "allocSingleString"); + return sciErr.iErr; + } - piOffset = piAddr + 4; - piOffset[0] = 1; //Always 1 - piOffset[1] = _iLen + 1; - pstString = (char*)(piOffset + 2); //2 offsets -#endif - return 0; + int rhs = _iVar - *getNbInputArgument(_pvCtx); + out[rhs - 1] = pStr; + + + return sciErr.iErr; } /*--------------------------------------------------------------------------*/ diff --git a/scilab/modules/graphics/sci_gateway/c/sci_xclick.c b/scilab/modules/graphics/sci_gateway/c/sci_xclick.c index 2ed3e13..9ace862 100644 --- a/scilab/modules/graphics/sci_gateway/c/sci_xclick.c +++ b/scilab/modules/graphics/sci_gateway/c/sci_xclick.c @@ -162,16 +162,15 @@ int sci_xclick(char *fname, void *pvApiCtx) if (nbOutputArgument(pvApiCtx) >= 5) { - char* strRep = NULL; + char *strRep = NULL; AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5; istr = (int)strlen(menuCallback); - if (allocSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 5, istr * one, (const char**)&strRep)) + if (allocSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 5, istr * one, &strRep)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } - strncpy(strRep, menuCallback, istr); } -- 1.7.9.5