Bug 170234 - Error in getDataArray method
Summary: Error in getDataArray method
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
25.8.3.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-01-05 15:00 UTC by Vladimir Sokolinskiy
Modified: 2026-01-11 10:49 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Sokolinskiy 2026-01-05 15:00:04 UTC
Create a new file and execute the macro:

Sub Test()
  Dim oCell as Object, arr
  oCell = ThisComponent.Sheets(0).getCellByPosition(0, 0)
  
  oCell.String = Chr(9) & "0" & Chr(10)  
  arr = oCell.getDataArray()

  Msgbox Asc(Mid(oCell.String, 1, 1)) ' Shows 9
  Msgbox Asc(Mid(oCell.String, 2, 1)) ' Shows 48
  Msgbox Asc(Mid(oCell.String, 3, 1)) ' Shows 10
  
  Msgbox Asc(Mid(arr(0)(0), 1, 1))    ' Shows 1  : incorrect
  Msgbox Asc(Mid(arr(0)(0), 2, 1))    ' Shows 48 : correct
  Msgbox Asc(Mid(arr(0)(0), 3, 1))    ' Shows 10 : correct
End Sub

The macro shows that the getDataArray method incorrectly returns the value of cell A1. The first character has been changed from U+0009 to U+0001.
Comment 1 Werner Tietz 2026-01-05 18:29:10 UTC
confirmed

```
doc = XSCRIPTCONTEXT.getDocument()
cell = doc.Sheets[0][0,0]
cell.String = "\t0\n"
cell.DataArray[0][0] == cell.String

>False
```
Comment 2 Julien Nabet 2026-01-11 10:49:34 UTC
With this patch, it works:
diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index 89a4622f8f41..a971f7ac4e6a 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -121,9 +121,6 @@ OUString ScEditUtil::GetMultilineString( const EditTextObject& rEdit )
 
 OUString ScEditUtil::GetString( const EditTextObject& rEditText, const ScDocument& rDoc )
 {
-    if( !rEditText.HasField())
-        return GetMultilineString( rEditText );
-
     static std::mutex aMutex;
     std::scoped_lock aGuard( aMutex);
     // ScFieldEditEngine is needed to resolve field contents.

But these lines had been added with this patch:
commit fb32f28a2b7f0c33533592b855ead127b858040c
Author: Luboš Luňák <l.lunak@collabora.com>
Date:   Tue May 29 10:00:31 2018 +0200

    avoid using EditEngine in ScEditUtils::GetString() if possible
    
    According to 1ecdc7aaf66 it is really needed only for resolving fields,
    so if there's no field, simply concatenate the contents, as used to
    be the case before that commit. This should be faster and also safer
    in the case of Calc's threading enabled.

So perhaps there's a proper way to fix this.


Just for info, here's part of bt:
#0  lcl_GetDelimitedString (rEdit=..., c=10 '\n') at /home/julien/lo/libreoffice/sc/source/core/tool/editutil.cxx:98
#1  0x00007f4cc6b9edd5 in ScEditUtil::GetMultilineString (rEdit=...) at /home/julien/lo/libreoffice/sc/source/core/tool/editutil.cxx:119
#2  0x00007f4cc6b9efbf in ScEditUtil::GetString (rEditText=..., rDoc=...) at /home/julien/lo/libreoffice/sc/source/core/tool/editutil.cxx:125
#3  0x00007f4cc6233928 in (anonymous namespace)::getStringImpl<ScRefCellValue> (rCell=..., rDoc=...) at /home/julien/lo/libreoffice/sc/source/core/data/cellvalue.cxx:200
#4  0x00007f4cc6233868 in ScRefCellValue::getString (this=0x7fff6ba745a0, rDoc=...) at /home/julien/lo/libreoffice/sc/source/core/data/cellvalue.cxx:660
#5  0x00007f4cc6d3567d in ScRangeToSequence::FillMixedArray (rAny=uno::Any(void), rDoc=..., rRange=..., bAllowNV=true) at /home/julien/lo/libreoffice/sc/source/core/tool/rangeseq.cxx:277
#6  0x00007f4cc7767feb in ScCellRangeObj::getDataArray (this=0x564009cdb830) at /home/julien/lo/libreoffice/sc/source/ui/unoobj/cellsuno.cxx:4895