From 8084c4f9f714707030cde5403b4c2ece72ef7810 Mon Sep 17 00:00:00 2001
From: zbigniew <zbigniewsz@gmail.com>
Date: Thu, 23 Jun 2011 17:46:16 -0500
Subject: [PATCH] string->number accepted out-of-range characters for base > 10
---
runtime.c | 2 +-
tests/library-tests.scm | 6 ++++++
2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/runtime.c b/runtime.c
index 2e01b06..a1b8faa 100644
a
|
b
|
static int from_n_nary(C_char *str, int base, double *r) |
7349 | 7349 | else if(c >= '0' + base) { |
7350 | 7350 | if(base < 10) return 0; |
7351 | 7351 | else if(c < 'a') return 0; |
7352 | | else if(c >= 'a' + base) return 0; |
| 7352 | else if(c >= 'a' + base - 10) return 0; |
7353 | 7353 | else n = n * base + c - 'a' + 10; |
7354 | 7354 | } |
7355 | 7355 | else n = n * base + c - '0'; |
diff --git a/tests/library-tests.scm b/tests/library-tests.scm
index 01974ba..051db8a 100644
a
|
b
|
|
69 | 69 | '("100000" "1012" "200" "112" "52" "44" "40" "35" "32" "2A" "28" "26" "24" "22" "20"))) |
70 | 70 | |
71 | 71 | |
| 72 | ;; string->number conversion |
| 73 | |
| 74 | (assert (= 255 (string->number "ff" 16))) |
| 75 | (assert (not (string->number "fg" 16))) |
| 76 | |
| 77 | |
72 | 78 | ;; fp-math |
73 | 79 | |
74 | 80 | (assert (= (sin 42.0) (fpsin 42.0))) |