bug-mes
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] mescc: Fix length calculation of initialized array with unspecif


From: Michael Forney
Subject: [PATCH] mescc: Fix length calculation of initialized array with unspecified length.
Date: Sat, 13 Apr 2024 12:38:39 -0700

Consider the following definition:

        char a[] = {1, 2, 3};

The initializer is parsed as

        ((initzer (initzer-list
                (initzer (p-expr (fixed "1")))
                (initzer (p-expr (fixed "2")))
                (initzer (p-expr (fixed "3"))))))

so (cadar init) is

        (initzer-list
                (initzer (p-expr (fixed "1")))
                (initzer (p-expr (fixed "2")))
                (initzer (p-expr (fixed "3"))))

We want to determine the number of items in the initializer, which
is (length (cdadar init)), not (length (cadar init)).

Using cadar causes the length of the array to be one too large and
incorrect evaluation of sizeof.

* module/mescc/compile.scm (init-declr->info): Fix length calculation
  of initialized array with unspecified length.
---
 module/mescc/compile.scm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/module/mescc/compile.scm b/module/mescc/compile.scm
index 06a2aab2..251854be 100644
--- a/module/mescc/compile.scm
+++ b/module/mescc/compile.scm
@@ -2401,7 +2401,7 @@
      (let* ((strings (init->strings init info))
             (info (if (null? strings) info
                       (clone info #:globals (append (.globals info) strings))))
-            (count (length (cadar init)))
+            (count (length (cdadar init)))
             (type (make-c-array type count)))
        (if (.function info) (local->info type name o init info)
            (global->info storage type name o init info))))
-- 
2.44.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]