From 378b8e97850e6fc849af7729855472cd79f0cb7e Mon Sep 17 00:00:00 2001 From: Roman Venediktov Date: Wed, 26 Jun 2024 15:11:18 +0200 Subject: [PATCH] Fix [0] arrays --- runtime/runtime.c | 6 ++++-- runtime/runtime_common.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/runtime/runtime.c b/runtime/runtime.c index 6476736aa..ddcae6d17 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -463,7 +463,8 @@ extern void *Lsubstring (aint* args /*void *subj, aint p, aint l*/) { r = (data *)alloc_string(ll); pop_extra_root((void**)&args[0]); - strncpy(r->contents, (char *)args[0] + pp, ll); + char *r_contents = r->contents; + strncpy(r_contents, (char *)args[0] + pp, ll); POST_GC(); @@ -751,7 +752,8 @@ extern void *Bstring (aint* args/*void *p*/) { push_extra_root((void**)&args[0]); s = LmakeString(BOX(n)); pop_extra_root((void**)&args[0]); - strncpy((char *)&TO_DATA(s)->contents, (char*)args[0], n + 1); // +1 because of '\0' in the end of C-strings + char *s_contents = (char *)&TO_DATA(s)->contents; + strncpy(s_contents, (char*)args[0], n + 1); // +1 because of '\0' in the end of C-strings POST_GC(); diff --git a/runtime/runtime_common.h b/runtime/runtime_common.h index cdeb70f09..e69b132f3 100644 --- a/runtime/runtime_common.h +++ b/runtime/runtime_common.h @@ -79,7 +79,7 @@ typedef struct { // last bit is used as MARK-BIT, the rest are used to store address where object should move // last bit can be used because due to alignment we can assume that last two bits are always 0's ptrt forward_address; - char contents[0]; + char contents[]; } data; typedef struct { @@ -95,7 +95,7 @@ typedef struct { // last bit can be used because due to alignment we can assume that last two bits are always 0's ptrt forward_address; auint tag; - char contents[0]; + char contents[]; } sexp; #endif