diff --git a/src/compiler/codegen_c.c b/src/compiler/codegen_c.c index 5e5fe0e6..f9d5bc89 100644 --- a/src/compiler/codegen_c.c +++ b/src/compiler/codegen_c.c @@ -164,8 +164,13 @@ int fb_copy_scope(fb_scope_t *scope, char *buf) buf[0] = '\0'; return -1; } + len = (size_t)scope->prefix.len; - memcpy(buf, scope->prefix.s, len); + if (scope->prefix.s != NULL) { + /* Passing NULL as the 2nd argument to memcpy yields undefined behaviour. */ + memcpy(buf, scope->prefix.s, len); + } + for (name = scope->name; name; name = name->link) { n = (size_t)name->ident->len; memcpy(buf + len, name->ident->text, n);