aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-06-24 12:53:12 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-06-24 12:53:12 -0400
commitc09a4eece687c23846b922ec2ec8740859aaa210 (patch)
tree1d8e303262eb57190e5f8a49d4393555bea5ca3e /src
parent389132400b6d3c1f7c767aaf3546d19e93909eb3 (diff)
Revert "Do text deserialization in chunks to avoid possible memory issues"
(Breaks with unicode text) This reverts commit 389132400b6d3c1f7c767aaf3546d19e93909eb3.
Diffstat (limited to 'src')
-rw-r--r--src/stdlib/text.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/stdlib/text.c b/src/stdlib/text.c
index 8b01529d..2107c1df 100644
--- a/src/stdlib/text.c
+++ b/src/stdlib/text.c
@@ -1617,19 +1617,13 @@ public void Text$serialize(const void *obj, FILE *out, Table_t *pointers, const
public void Text$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info)
{
(void)info;
- int64_t len = 0;
+ int64_t len = -1;
Int64$deserialize(in, &len, pointers, &Int64$info);
- if (len < 0)
- fail("Invalid text length during deserialization!");
- Text_t text = EMPTY_TEXT;
- while (text.length < len) {
- static char chunk[1024] = {};
- size_t chunk_size = MIN(sizeof(chunk), (size_t)(len - text.length));
- if (fread(chunk, sizeof(char), chunk_size, in) != chunk_size)
- fail("Not enough data in stream to deserialize");
- text = concat2(text, Text$from_strn(chunk, chunk_size));
- }
- *(Text_t*)out = text;
+ char *buf = GC_MALLOC_ATOMIC((size_t)len+1);
+ if (fread(buf, sizeof(char), (size_t)len, in) != (size_t)len)
+ fail("Not enough data in stream to deserialize");
+ buf[len+1] = '\0';
+ *(Text_t*)out = Text$from_strn(buf, (size_t)len);
}
public const TypeInfo_t Text$info = {