chicken-hackers
[Top][All Lists]
Advanced

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

[PATCH] Fix too small memory allocations


From: Jani Hakala
Subject: [PATCH] Fix too small memory allocations
Date: Tue, 26 Nov 2019 12:56:12 +0200
User-agent: Gnus/5.130013 (Ma Gnus v0.13) Emacs/25.1 (gnu/linux)

Hi,

This patch probably fixes #1637

Jani

>From 9c6d8617c9391abfd400914a0f0733f749e10900 Mon Sep 17 00:00:00 2001
From: Jani Hakala <address@hidden>
Date: Wed, 20 Nov 2019 21:37:03 +0200
Subject: [PATCH] Fix too small memory allocations

Memory allocation problems were detected by AddressSanitizer provided
by gcc 9.2.1. When lolevel-tests.scm was run, AddressSanitizer pointed
out bignum1 and bignum2 related problems in library.scm and srfi-4.scm.
---
 c-platform.scm | 7 +++++--
 library.scm    | 4 ++--
 srfi-4.scm     | 4 ++--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/c-platform.scm b/c-platform.scm
index 61a4ac87..7d763b07 100644
--- a/c-platform.scm
+++ b/c-platform.scm
@@ -968,8 +968,11 @@
 (rewrite 'chicken.memory#pointer-f32-set! 2 2 "C_u_i_pointer_f32_set" #f)
 (rewrite 'chicken.memory#pointer-f64-set! 2 2 "C_u_i_pointer_f64_set" #f)
 
-(rewrite 'chicken.memory#pointer-u32-ref 16 1 "C_a_u_i_pointer_u32_ref" #f 
words-per-flonum)
-(rewrite 'chicken.memory#pointer-s32-ref 16 1 "C_a_u_i_pointer_s32_ref" #f 
words-per-flonum)
+;; on 32-bit platforms, 32-bit integers do not always fit in a word,
+;; bignum1 and bignum wrapper (5 words) may be used instead
+(rewrite 'chicken.memory#pointer-u32-ref 16 1 "C_a_u_i_pointer_u32_ref" #f 5)
+(rewrite 'chicken.memory#pointer-s32-ref 16 1 "C_a_u_i_pointer_s32_ref" #f 5)
+
 (rewrite 'chicken.memory#pointer-f32-ref 16 1 "C_a_u_i_pointer_f32_ref" #f 
words-per-flonum)
 (rewrite 'chicken.memory#pointer-f64-ref 16 1 "C_a_u_i_pointer_f64_ref" #f 
words-per-flonum)
 
diff --git a/library.scm b/library.scm
index e52d1452..7b8c577a 100644
--- a/library.scm
+++ b/library.scm
@@ -2468,7 +2468,7 @@ EOF
                    (end (or hashes digits)))
               (and-let* ((end)
                          (num (##core#inline_allocate
-                              ("C_s_a_i_digits_to_integer" 5)
+                              ("C_s_a_i_digits_to_integer" 6)
                               str start (car end) radix neg?)))
                 (when hashes            ; Eeewww. Feeling dirty yet?
                   (set! seen-hashes? #t)
@@ -2482,7 +2482,7 @@ EOF
                    (and-let* ((start (if sign (fx+ start 1) start))
                               (end (scan-digits start)))
                      (cons (##core#inline_allocate
-                           ("C_s_a_i_digits_to_integer" 5)
+                           ("C_s_a_i_digits_to_integer" 6)
                            str start (car end) radix (eq? sign 'neg))
                            (cdr end)))))))
          (scan-decimal-tail             ; The part after the decimal dot
diff --git a/srfi-4.scm b/srfi-4.scm
index 6faaa475..537d8288 100644
--- a/srfi-4.scm
+++ b/srfi-4.scm
@@ -209,13 +209,13 @@ EOF
    
 (define u32vector-ref
   (getter-with-setter
-   (lambda (x i) (##core#inline_allocate ("C_a_i_u32vector_ref" 4) x i))
+   (lambda (x i) (##core#inline_allocate ("C_a_i_u32vector_ref" 5) x i))
    u32vector-set!
    "(chicken.srfi-4#u32vector-ref v i)"))
 
 (define s32vector-ref
   (getter-with-setter
-   (lambda (x i) (##core#inline_allocate ("C_a_i_s32vector_ref" 4) x i))
+   (lambda (x i) (##core#inline_allocate ("C_a_i_s32vector_ref" 5) x i))
    s32vector-set!
    "(chicken.srfi-4#s32vector-ref v i)"))
 
-- 
2.20.1


reply via email to

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