Ticket #619: 0001-string-number-accepted-out-of-range-characters-for-a.patch

File 0001-string-number-accepted-out-of-range-characters-for-a.patch, 1.2 KB (added by Jim Ursetto, 13 years ago)
  • runtime.c

    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) 
    73497349    else if(c >= '0' + base) {
    73507350      if(base < 10) return 0;
    73517351      else if(c < 'a') return 0;
    7352       else if(c >= 'a' + base) return 0;
     7352      else if(c >= 'a' + base - 10) return 0;
    73537353      else n = n * base + c - 'a' + 10;
    73547354    }
    73557355    else n = n * base + c - '0';
  • tests/library-tests.scm

    diff --git a/tests/library-tests.scm b/tests/library-tests.scm
    index 01974ba..051db8a 100644
    a b  
    6969  '("100000" "1012" "200" "112" "52" "44" "40" "35" "32" "2A" "28" "26" "24" "22" "20")))
    7070
    7171
     72;; string->number conversion
     73
     74(assert (= 255 (string->number "ff" 16)))
     75(assert (not (string->number "fg" 16)))
     76
     77
    7278;; fp-math
    7379
    7480(assert (= (sin 42.0) (fpsin 42.0)))