[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Fix allocation size for C_s_a_i_digits_to_integer
From: |
megane |
Subject: |
Re: [PATCH] Fix allocation size for C_s_a_i_digits_to_integer |
Date: |
Mon, 18 Nov 2019 16:46:25 +0200 |
User-agent: |
mu4e 1.0; emacs 25.1.1 |
Jani Hakala <address@hidden> writes:
> Hi,
>
> I found out that there seems to be two similar cases in srfi-4.scm
Thanks for the great work!
Attached is a patch for this.
>From 804f461b413a49ff5021f742ba289f12d282144b Mon Sep 17 00:00:00 2001
From: megane <address@hidden>
Date: Mon, 18 Nov 2019 16:02:20 +0200
Subject: [PATCH] Fix allocation sizes for u32vector-ref, s32vector-ref
The c functions might ultimately call C_bignum1, which needs 5 words.
Found by Jani Hakala.
---
c-platform.scm | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/c-platform.scm b/c-platform.scm
index 87f36698..e291e978 100644
--- a/c-platform.scm
+++ b/c-platform.scm
@@ -78,6 +78,7 @@
(define default-units '(library eval))
(define words-per-flonum 4)
+(define min-words-per-bignum 5)
(eq-inline-operator "C_eqp")
(membership-test-operators
@@ -1074,8 +1075,8 @@
(rewrite 'srfi-4#s16vector-ref 2 2 "C_u_i_s16vector_ref" #f)
(rewrite 'srfi-4#s16vector-ref 2 2 "C_i_s16vector_ref" #t)
-(rewrite 'srfi-4#u32vector-ref 16 2 "C_a_i_u32vector_ref" #t words-per-flonum)
-(rewrite 'srfi-4#s32vector-ref 16 2 "C_a_i_s32vector_ref" #t words-per-flonum)
+(rewrite 'srfi-4#u32vector-ref 16 2 "C_a_i_u32vector_ref" #t
min-words-per-bignum)
+(rewrite 'srfi-4#s32vector-ref 16 2 "C_a_i_s32vector_ref" #t
min-words-per-bignum)
(rewrite 'srfi-4#f32vector-ref 16 2 "C_a_u_i_f32vector_ref" #f
words-per-flonum)
(rewrite 'srfi-4#f32vector-ref 16 2 "C_a_i_f32vector_ref" #t words-per-flonum)
--
2.17.1
>
> (define u32vector-ref
> (getter-with-setter
> (lambda (x i) (##core#inline_allocate ("C_a_i_u32vector_ref" 4) 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))
> s32vector-set!
> "(chicken.srfi-4#s32vector-ref v)))
>
>
> Since C_a_i_u32vector_ref and C_a_i_s32vector_ref may end up calling
> bignum1, there should probably be 5 bytes allocated instead of 4.
>
> I found this by compiling chicken with gcc -fsanitize=address
> -fsanitize=aligment, and by linking also related libraries. Address
> sanitizer then reported potential problems.
>
> Jani