From 9514abc2da3525ef4314a8fcf70982ad07319e51 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 19 May 2020 12:42:20 -0300 Subject: Cleaner definition for 'TString' Use a variable-sized array to store string contents at the end of a structure 'TString', instead of raw memory. --- lstring.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lstring.h') diff --git a/lstring.h b/lstring.h index 56896867..a413a9d3 100644 --- a/lstring.h +++ b/lstring.h @@ -19,7 +19,11 @@ #define MEMERRMSG "not enough memory" -#define sizelstring(l) (sizeof(TString) + ((l) + 1) * sizeof(char)) +/* +** Size of a TString: Size of the header plus space for the string +** itself (including final '\0'). +*/ +#define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char)) #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ (sizeof(s)/sizeof(char))-1)) -- cgit v1.2.3-55-g6feb