tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.49k stars 418 forks source link

Crash in UE4 if I get string cell value to FString #466

Closed error408 closed 4 years ago

error408 commented 4 years ago

I want use xlnt in UE4, but when I get string cell value to FString, it's always crash. such as: FString key = UTF8_TO_TCHAR(wks->cell(y, x).value<std::string>().c_str()); or FString key = wks->cell(index, KEY_LINE).value<std::string>().c_str(); emmmm。。。

tfussell commented 4 years ago

It's not safe to call c_str on a temporary. wks->cell(y, x).value<std::string>() returns a string which is destructed immediately afterwards so the pointer from c_str points to invalid data when you try to use it. You'll need to store the string object somewhere or make a copy of its data on the stack or heap.