felixguendling / cista

Cista is a simple, high-performance, zero-copy C++ serialization & reflection library.
https://cista.rocks
MIT License
1.74k stars 110 forks source link

When cista::basic_string is reassigned to itself, it yields empty or corrupted contents. #222

Closed ChemistAion closed 2 months ago

ChemistAion commented 2 months ago

Observed even on current HEAD (26.05.024), commit 8255bcd Seems that the issue is caused by reset() invoked with no eq. checks by set_owning(...)

I have checked only cista::raw case so far, here is a minimal reproducible use case:

namespace CISTA = cista::raw;

// case short string
CISTA::string test_short{ "test_short" };
std::string output_short_pre{ test_short };
test_short = test_short;
std::string output_short_post{ test_short };
//test_short is empty now
assert(output_short_pre == output_short_post);

// case long string
CISTA::string test_long{ "test_long_12345678901234567890123456789012" };
std::string output_long_pre{ test_long };
test_long = test_long;
std::string output_long_post{ test_long };
//test_long is filled with "garbage", staring with 0x01, 0x00...
assert(output_long_pre == output_long_post);
felixguendling commented 2 months ago

Thanks! I hope it's fixed now. Let me know if there are more issues.

ChemistAion commented 1 month ago

...works like a charm :relieved: