From 3990f0f2731c2289eaefefc9aff5bdcaee6c3289 Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 18 Jun 2023 18:23:13 +0200 Subject: fix memory bugs --- ir.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'ir.c') diff --git a/ir.c b/ir.c index d214f55..08966a3 100644 --- a/ir.c +++ b/ir.c @@ -183,10 +183,12 @@ union ref mkdatref(const char *name, uint siz, uint align, const void *bytes, uint n, bool deref) { struct irdat dat = { .align = align, .siz = siz, .name = name }; - if (siz <= 8) memcpy(dat.sdat, bytes, n < siz ? n : siz); - else { - while (((uchar *)bytes)[n-1] == 0) --n; /* nip trailing zeroes */ - if (n) vpushn(&dat.dat, bytes, n); + if (bytes) { + if (siz <= 8) memcpy(dat.sdat, bytes, n < siz ? n : siz); + else { + while (((uchar *)bytes)[n-1] == 0) --n; /* nip trailing zeroes */ + if (n) vpushn(&dat.dat, bytes, n); + } } if (!name) { extern const char *intern(const char *); -- cgit v1.2.3