hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 14d4abd2b8a602420a12b2f4ab1f4e706d7299ee
parent b51e0a6c8aeb386e9b7f1e2ccf505c26ed8e751b
Author: Tom Regner <tomte@tomsdiner.org>
Date:   Wed, 23 Nov 2022 08:00:51 +0000

Fix crash when timezone is unspecified

If neither TZ exists in the env, nor /etc/localtime (or an
equivalent for the system) the TC_LOCAL.zones must not be freed.

Signed-off-by: Tom Regner <tomte@tomsdiner.org>

Diffstat:
Mtime/chrono/timezone.ha | 12+++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/time/chrono/timezone.ha b/time/chrono/timezone.ha @@ -199,14 +199,16 @@ export fn fixedzone(ts: *timescale, daylen: time::duration, z: zone) timezone = // name of both the timezone and its single zero-offset zone. export const LOCAL: locality = &TZ_LOCAL; +def LOCAL_NAME: str = "Local"; + let TZ_LOCAL: timezone = timezone { - name = "Local", + name = LOCAL_NAME, timescale = &utc, daylength = EARTH_DAY, zones = [ zone { zoffset = 0 * time::SECOND, - name = "Local", + name = LOCAL_NAME, abbr = "", dst = false, }, @@ -217,7 +219,11 @@ let TZ_LOCAL: timezone = timezone { @fini fn free_tzdata() void = { free(TZ_LOCAL.transitions); - free(TZ_LOCAL.zones); + switch(TZ_LOCAL.name) { + case LOCAL_NAME => void; + case => + free(TZ_LOCAL.zones); + }; }; @init fn set_local_timezone() void = {