From b044d4ad764dcdd43b3ece4a3c1aff4275a05401 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 6 Feb 2020 20:18:19 +0700 Subject: [PATCH] jerry_init: Calculate structure part address more safely. (#3545) GCC 9.2 issues a warning-as-error trying to perform a large memset into what it thinks as a single field of a structure. So, instead of taking an address of that field, perform explicit address calculaton using structure address and offset of that field. Fixes #3544. JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org --- jerry-core/api/jerry.c | 2 +- jerry-core/jcontext/jcontext.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/jerry-core/api/jerry.c b/jerry-core/api/jerry.c index 813aa6c13..b386cf3d0 100644 --- a/jerry-core/api/jerry.c +++ b/jerry-core/api/jerry.c @@ -191,7 +191,7 @@ jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */ JERRY_ASSERT (!(JERRY_CONTEXT (status_flags) & ECMA_STATUS_API_AVAILABLE)); /* Zero out all non-external members. */ - memset (&JERRY_CONTEXT (JERRY_CONTEXT_FIRST_MEMBER), 0, + memset ((char *) &JERRY_CONTEXT_STRUCT + offsetof (jerry_context_t, JERRY_CONTEXT_FIRST_MEMBER), 0, sizeof (jerry_context_t) - offsetof (jerry_context_t, JERRY_CONTEXT_FIRST_MEMBER)); JERRY_CONTEXT (jerry_init_flags) = flags; diff --git a/jerry-core/jcontext/jcontext.h b/jerry-core/jcontext/jcontext.h index a2ce3b49f..9f949014a 100644 --- a/jerry-core/jcontext/jcontext.h +++ b/jerry-core/jcontext/jcontext.h @@ -245,6 +245,7 @@ struct jerry_context_t * This part is for JerryScript which uses external context. */ +#define JERRY_CONTEXT_STRUCT (*jerry_port_get_current_context ()) #define JERRY_CONTEXT(field) (jerry_port_get_current_context ()->field) #if !ENABLED (JERRY_SYSTEM_ALLOCATOR) @@ -274,6 +275,11 @@ struct jmem_heap_t */ extern jerry_context_t jerry_global_context; +/** + * Config-independent name for context. + */ +#define JERRY_CONTEXT_STRUCT (jerry_global_context) + /** * Provides a reference to a field in the current context. */