From ad471148ec8763e17f55059aaf85e320175220f2 Mon Sep 17 00:00:00 2001 From: Simon Chenery Date: Tue, 28 Jan 2025 19:51:15 +0100 Subject: Add isEmpty() check to avoid possible OUStringBuffer underflow Avoid accessing invalid index -1 if OUStringBuffer aBuffer is empty. It cannot be guaranteed that callers will always pass strings that result in aBuffer being non-empty. Change-Id: Ied9abf753bcaf2bd1ee618b2431fa35b0bdb5573 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180856 Reviewed-by: Samuel Mehrbrodt Tested-by: Jenkins --- forms/source/xforms/convert.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'forms') diff --git a/forms/source/xforms/convert.cxx b/forms/source/xforms/convert.cxx index c95d5fae6856..98fd3391f220 100644 --- a/forms/source/xforms/convert.cxx +++ b/forms/source/xforms/convert.cxx @@ -328,7 +328,7 @@ OUString Convert::collapseWhitespace( const OUString& _rString ) aBuffer.append( c ); } } - if( aBuffer[ aBuffer.getLength() - 1 ] == u' ' ) + if( !aBuffer.isEmpty() && aBuffer[ aBuffer.getLength() - 1 ] == u' ' ) aBuffer.setLength( aBuffer.getLength() - 1 ); return aBuffer.makeStringAndClear(); } -- cgit