From cb9241bc6c05b309c8321995c4bdc5f80cce5560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Str=C3=B6mb=C3=A4ck?= Date: Tue, 19 Dec 2023 18:20:49 +0900 Subject: [PATCH] Avoid using `sizeof('\0')` to compute size for NUL-terminator. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The expression `sizeof('\0')` evaluates to `sizeof(int)`, which does not reflect the intent in the code. It has been replaced with `1 /* NUL */` for clarity. This issue was originally reported by наб who also proposed this patch. --- code/event.h | 2 +- code/eventcom.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/event.h b/code/event.h index 954b315b77..358064d9e7 100644 --- a/code/event.h +++ b/code/event.h @@ -84,7 +84,7 @@ extern Word EventKindControl; size_t _string_len = (length); \ size_t size; \ AVER(_string_len <= EventStringLengthMAX); \ - size = offsetof(Event##name##Struct, f1) + _string_len + sizeof('\0'); \ + size = offsetof(Event##name##Struct, f1) + _string_len + 1 /* NUL */; \ EVENT_BEGIN(name, size) \ _event->f0 = (p0); \ (void)mps_lib_memcpy(_event->f1, (string), _string_len); \ diff --git a/code/eventcom.h b/code/eventcom.h index 75886be3d9..243570da6b 100644 --- a/code/eventcom.h +++ b/code/eventcom.h @@ -91,7 +91,7 @@ typedef void *EventFP; /* pointer to C object */ typedef Addr EventFA; /* address on the heap */ typedef Word EventFW; /* word */ typedef unsigned EventFU; /* unsigned integer */ -typedef char EventFS[EventStringLengthMAX + sizeof('\0')]; /* string */ +typedef char EventFS[EventStringLengthMAX + 1 /* NUL */]; /* string */ typedef double EventFD; /* double */ typedef unsigned char EventFB; /* Boolean */