unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#24908: Possible unboxing bug in master triggered by (format)
@ 2016-11-09 13:17 Daniel Llorens
  2016-12-09 13:11 ` bug#24908: workaround daniel.llorens
  2016-12-15 11:59 ` bug#24908: closing Daniel Llorens
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Llorens @ 2016-11-09 13:17 UTC (permalink / raw)
  To: 24908


(format #f "~2f" 9.9) fails in master. You can try different combinations, it doesn't fail when it rounds down or there're more spaces for example.

The first bad commit is 0f2f5949a21572fad8355473200c7adc6d74f882 'Better unboxing' on the master branch.

See the full error below. 18446744073709551615 is 2^64-1 of course so it looks like bad signedness somewhere.

Regards

	Daniel


> guile -c '(use-modules (ice-9 format)) (format #f "~2f" 9.9)'
Backtrace:./meta/guile -c '(use-modules (ice-9 format)) (format #f "~2f" 9.9)'
Backtrace:
           8 (apply-smob/1 #<catch-closure 1105c20>)
In ice-9/boot-9.scm:
    704:2  7 (call-with-prompt ("prompt") #<procedure 110a060 at ic…> …)
In ice-9/eval.scm:
    608:8  6 (_ #(#(#<directory (guile-user) 110cf30>)))
In ice-9/command-line.scm:
   181:18  5 (_ #<input: string 1119f50>)
In unknown file:
           4 (eval (format #f "~2f" 9.9) #<directory (guile-user) 11…>)
In ice-9/format.scm:
  1590:19  3 (format #f "~2f" 9.9)
   316:19  2 (format:format-work "~2f" (9.9))
  1142:30  1 (format:out-fixed #f _ _)
  1525:37  0 (format:fn-round _)

ice-9/format.scm:1525:37: In procedure format:fn-round:
ice-9/format.scm:1525:37: In procedure string-ref: Value out of range: 18446744073709551615






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#24908: workaround
  2016-11-09 13:17 bug#24908: Possible unboxing bug in master triggered by (format) Daniel Llorens
@ 2016-12-09 13:11 ` daniel.llorens
  2016-12-09 13:11   ` bug#24908: [PATCH] Workaround for bug #24908 daniel.llorens
  2016-12-15 11:59 ` bug#24908: closing Daniel Llorens
  1 sibling, 1 reply; 4+ messages in thread
From: daniel.llorens @ 2016-12-09 13:11 UTC (permalink / raw)
  To: 24908

I can't fix the compiler, so just patch format:fn-round. Includes a
test.






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#24908: [PATCH] Workaround for bug #24908
  2016-12-09 13:11 ` bug#24908: workaround daniel.llorens
@ 2016-12-09 13:11   ` daniel.llorens
  0 siblings, 0 replies; 4+ messages in thread
From: daniel.llorens @ 2016-12-09 13:11 UTC (permalink / raw)
  To: 24908; +Cc: Daniel Llorens

From: Daniel Llorens <daniel.llorens@bluewin.ch>

* module/ice-9/format.scm (format:fn-round): Don't let i become
  negative.
* test-suite/tests/format.test: Regression test for "~2f".
---
 module/ice-9/format.scm      | 15 ++++++++-------
 test-suite/tests/format.test |  6 +++++-
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/module/ice-9/format.scm b/module/ice-9/format.scm
index 1ef4cb5ef..d3066a527 100644
--- a/module/ice-9/format.scm
+++ b/module/ice-9/format.scm
@@ -1510,11 +1510,12 @@
            (set! format:fn-len (- format:fn-len n)))
         (string-set! format:fn-str (- i n) (string-ref format:fn-str i))))
 
+    ;; carry i+1 to work around bug #24908
     (define (format:fn-round digits)    ; round format:fn-str
       (set! digits (+ digits format:fn-dot))
-      (do ((i digits (- i 1))		; "099",2 -> "10"
+      (do ((i (+ digits 1) (- i 1))	; "099",2 -> "10"
            (c 5))                       ; "023",2 -> "02"
-          ((or (= c 0) (< i 0))         ; "999",2 -> "100"
+          ((or (= c 0) (<= i 0))        ; "999",2 -> "100"
            (if (= c 1)			; "005",2 -> "01"
                (begin			; carry overflow
                  (set! format:fn-len digits)
@@ -1522,12 +1523,12 @@
                  (string-set! format:fn-str 0 #\1)
                  (set! format:fn-dot (+ format:fn-dot 1)))
                (set! format:fn-len digits)))
-        (set! c (+ (- (char->integer (string-ref format:fn-str i))
+        (set! c (+ (- (char->integer (string-ref format:fn-str (- i 1)))
                       format:zero-ch) c))
-        (string-set! format:fn-str i (integer->char
-                                      (if (< c 10) 
-                                          (+ c format:zero-ch)
-                                          (+ (- c 10) format:zero-ch))))
+        (string-set! format:fn-str (- i 1) (integer->char
+                                            (if (< c 10)
+                                              (+ c format:zero-ch)
+                                              (+ (- c 10) format:zero-ch))))
         (set! c (if (< c 10) 0 1))))
 
     (define (format:fn-out modifier add-leading-zero?)
diff --git a/test-suite/tests/format.test b/test-suite/tests/format.test
index cc31942cc..8aab7e96b 100644
--- a/test-suite/tests/format.test
+++ b/test-suite/tests/format.test
@@ -112,7 +112,11 @@
   ;; in guile prior to 1.6.9 and 1.8.1, leading zeros were incorrectly
   ;; stripped, moving the decimal point and giving "25.0" here
   (pass-if "string 02.5"
-    (string=? "2.5" (format #f "~f" "02.5"))))
+    (string=? "2.5" (format #f "~f" "02.5")))
+
+  ;; regression against bug #24908
+  (pass-if "2f"
+    (string=? "10." (format #f "~2f" 9.9))))
 
 ;;;
 ;;; ~h
-- 
2.11.0






^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#24908: closing
  2016-11-09 13:17 bug#24908: Possible unboxing bug in master triggered by (format) Daniel Llorens
  2016-12-09 13:11 ` bug#24908: workaround daniel.llorens
@ 2016-12-15 11:59 ` Daniel Llorens
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Llorens @ 2016-12-15 11:59 UTC (permalink / raw)
  To: 24908-close


Fixed in 2660c0b3c86bf76fab465c200a5ca20fb37cf811.






^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-12-15 11:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-09 13:17 bug#24908: Possible unboxing bug in master triggered by (format) Daniel Llorens
2016-12-09 13:11 ` bug#24908: workaround daniel.llorens
2016-12-09 13:11   ` bug#24908: [PATCH] Workaround for bug #24908 daniel.llorens
2016-12-15 11:59 ` bug#24908: closing Daniel Llorens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).