Re: [PATCH] Fix allocation size for C_s_a_i_digits_to_integer

2019-11-18 Thread megane

Jani Hakala  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 
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



Re: [PATCH] Fix allocation size for C_s_a_i_digits_to_integer

2019-11-17 Thread Jani Hakala


Hi,

I found out that there seems to be two similar cases in srfi-4.scm

(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



[PATCH] Fix allocation size for C_s_a_i_digits_to_integer

2019-11-17 Thread Peter Bex
Hi all,

Here's a fix for the allocation size for C_s_a_i_digits_to_integer.
It was marked as needing 5 words, but it will need 6 words at most.

This was reported by jjhoo on IRC, found by running CHICKEN under
Valgrind.  Potentially this may fix #1637.

Cheers,
Peter
From ba1253332d42e1296513d29ac85d201fab9c8e46 Mon Sep 17 00:00:00 2001
From: Peter Bex 
Date: Sun, 17 Nov 2019 12:54:19 +0100
Subject: [PATCH] Fix allocation size for C_s_a_i_digits_to_integer

Found by jjhoo using Valgrind: C_bignum2 needs 4 words (header, sign
and the two digit words), plus the 2 words for the bignum wrapper.
---
 library.scm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/library.scm b/library.scm
index 29b85878..c501ab6e 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
-- 
2.20.1



signature.asc
Description: PGP signature