Skip to content

Commit

Permalink
Avoid using sizeof('\0') to compute size for NUL-terminator.
Browse files Browse the repository at this point in the history
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 наб <[email protected]>
who also proposed this patch.
  • Loading branch information
Filip Strömbäck committed Dec 19, 2023
1 parent e2f9497 commit cb9241b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion code/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down
2 changes: 1 addition & 1 deletion code/eventcom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down

0 comments on commit cb9241b

Please sign in to comment.