From ee352a7b5c8ce40e3661bddf50e8d5c72d98017d Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Tue, 24 Jan 2023 07:59:49 +0100 Subject: [PATCH] DRAFT lib/m2: time: Fix segfault by allocating timeval struct. Suggested by Meghan Denny . * lib/m2/time.c (__tv): New global variable. (time): Use it to allocate timeval struct. --- lib/m2/time.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/m2/time.c b/lib/m2/time.c index c589de85..45ae1afb 100644 --- a/lib/m2/time.c +++ b/lib/m2/time.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019,2022,2023 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -22,13 +22,16 @@ #include #include +char *__tv; + long time (long* result) { int r; - struct timeval tv; - struct timezone tz; - r = _sys_call2 (SYS_gettimeofday, tv, tz); + if (__tv == 0) + __tv = malloc (sizeof (struct timeval)); + struct timeval *tv = __tv; + r = _sys_call2 (SYS_gettimeofday, tv, 0); if (r != 0) return -1; if (result != 0)