From 972b0109a4cf31bdf350e1493804f1e86b15af20 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 16 Oct 2016 19:22:29 -0500 Subject: [PATCH] Fix a problem where zero-initializing a one-byte array would crash the system. Also, generate better code for zero-initializing small arrays. The problem was that the code would call the library routine ~ZERO with a size of 1, but it only works properly with a size of 2 or more. While adding a check here, I also changed it to not call ~ZERO for other small arrays (<=10 bytes), since it is generally more efficient to just initialize them directly. The initializations in the following are examples that could trigger the problem: int main(void) { struct { int i; char s[1]; } foo = {1, 0}; char arr[2][1] = {2}; } --- Parser.pas | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Parser.pas b/Parser.pas index 8ad9749..9837d81 100644 --- a/Parser.pas +++ b/Parser.pas @@ -3662,7 +3662,9 @@ procedure DoStatement; with iPtr^.itree^ do if token.kind = intconst then if token.ival = 0 then - ZeroFill := true; + {don't call ~ZERO for very small arrays} + if elements * itype^.size > 10 then + ZeroFill := true; end; {ZeroFill}