Hello LibXL Team,
I found a bug in the Sheet::addSelectionRange() method. The function crashes in xlsx format and has no effect in xls format.
Environment
- LibXL version: 5.2.0 (also tested 4.2.0, same issue)
- OS: Windows 10/11 x64
- Compiler: MSVC 2022 (Visual Studio 17)
- Format: xlsx and xls
Bug Description
xlsx format: CRASH
Calling sheet->addSelectionRange() causes an access violation (0xC0000005) inside libxl.dll. The exception message is:
“Read access violation at address 0x0000000000000000” (null pointer dereference).
xls format: NO EFFECT (silent failure)
No crash, but the selection range is not saved. Opening the file in Excel shows no selection range.
Tested Parameter Formats (all crash in xlsx)
- L"A1"
- L"A1:C5"
- L"$A$1:$C$5"
- L"A1:C5 E1:F3" (multiple ranges)
- L"A1:C5 " (trailing space)
Minimal Reproduction Code
```cpp
#include “libxl.h”
using namespace libxl;
int main()
{
// === xlsx: CRASH ===
Book* book = xlCreateXMLBook();
Sheet* sheet = book->addSheet(L"test");
sheet->writeStr(0, 0, L"hello");
sheet->addSelectionRange(L"A1:C5"); // <-- CRASH HERE (0xC0000005)
book->save(L"test.xlsx");
book->release();
// === xls: NO EFFECT ===
Book\* book2 = xlCreateBook();
Sheet\* sheet2 = book2->addSheet(L"test");
sheet2->writeStr(0, 0, L"hello");
sheet2->addSelectionRange(L"A1:C5"); // <-- no crash, but not saved
book2->save(L"test.xls");
book2->release();
return 0;
}