Skip to content

Commit b044d4a

Browse files
authored
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
1 parent 0d7f26e commit b044d4a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

jerry-core/api/jerry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */
191191
JERRY_ASSERT (!(JERRY_CONTEXT (status_flags) & ECMA_STATUS_API_AVAILABLE));
192192

193193
/* Zero out all non-external members. */
194-
memset (&JERRY_CONTEXT (JERRY_CONTEXT_FIRST_MEMBER), 0,
194+
memset ((char *) &JERRY_CONTEXT_STRUCT + offsetof (jerry_context_t, JERRY_CONTEXT_FIRST_MEMBER), 0,
195195
sizeof (jerry_context_t) - offsetof (jerry_context_t, JERRY_CONTEXT_FIRST_MEMBER));
196196

197197
JERRY_CONTEXT (jerry_init_flags) = flags;

jerry-core/jcontext/jcontext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ struct jerry_context_t
245245
* This part is for JerryScript which uses external context.
246246
*/
247247

248+
#define JERRY_CONTEXT_STRUCT (*jerry_port_get_current_context ())
248249
#define JERRY_CONTEXT(field) (jerry_port_get_current_context ()->field)
249250

250251
#if !ENABLED (JERRY_SYSTEM_ALLOCATOR)
@@ -274,6 +275,11 @@ struct jmem_heap_t
274275
*/
275276
extern jerry_context_t jerry_global_context;
276277

278+
/**
279+
* Config-independent name for context.
280+
*/
281+
#define JERRY_CONTEXT_STRUCT (jerry_global_context)
282+
277283
/**
278284
* Provides a reference to a field in the current context.
279285
*/

0 commit comments

Comments
 (0)