atilaneves / cerealed

Powerful binary serialisation library for D
BSD 3-Clause "New" or "Revised" License
92 stars 3 forks source link

Deserialization of string from mutable buffer leads to unexpected behaviour #19

Closed tchaloupka closed 5 years ago

tchaloupka commented 5 years ago

Here is the test case:

import cerealed;

struct Foo { string value; }

auto data = Foo("bar").cerealise;
auto f1 = data.decerealise!Foo;
assert(f1.value == "bar");
//f1.value = f1.value.idup;

auto data2 = Foo("baz").cerealise;
data[] = data2[];
auto f2 = data.decerealise!Foo;
assert(f2.value == "baz");
//f2.value = f2.value.idup;
assert(f1.value == "bar");

When string is deserialized it points to the original muttable buffer so when other data come to it, string is modified even though it's immutable.