summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 17:30:52 -0500
committerWormHeamer2026-01-02 17:30:52 -0500
commita5996c4727705f3dd48d0b6d5cacc90392dd58d4 (patch)
tree96bbd53bc7759c0697a5224c81248f0b3b6b1fc5
parent4849d0d9b6e2ff83e1c9f9512671de68f9bf177a (diff)
fix memcpy of NULL for zero-length strings
-rw-r--r--str.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/str.h b/str.h
index 0a22242..b5f2889 100644
--- a/str.h
+++ b/str.h
@@ -40,6 +40,7 @@ Str str_replace_end(Str s, Str a, Str b, Arena *m);
/* conversions */
char *str_to_cstr(Str s, Arena *a) {
+ if (!s.n) return "";
char *r = new_arr(a, char, s.n + 1);
memcpy(r, s.s, s.n);
r[s.n] = 0;