--- /home/jfw/build/Scheme/chicken-core/runtime.c 2011-10-05 00:03:16.000000000 +0200 +++ runtime.c 2011-10-06 16:52:21.030542814 +0200 @@ -469,7 +469,7 @@ static int C_fcall hash_string(int len, C_char *str, unsigned int m) C_regparm; static C_word C_fcall lookup(C_word key, int len, C_char *str, C_SYMBOL_TABLE *stable) C_regparm; static double compute_symbol_table_load(double *avg_bucket_len, int *total); -static C_word C_fcall convert_string_to_number(C_char *str, int radix, C_word *fix, double *flo) C_regparm; +static C_word C_fcall convert_string_to_number(C_char *str, int len, int radix, C_word *fix, double *flo) C_regparm; static void C_fcall remark_system_globals(void) C_regparm; static void C_fcall really_remark(C_word *x) C_regparm; static C_word C_fcall intern0(C_char *name) C_regparm; @@ -7270,13 +7270,12 @@ if((n = C_header_size(str)) == 0) { fail: - n = C_SCHEME_FALSE; - goto fini; + return C_SCHEME_FALSE; } if(n >= STRING_BUFFER_SIZE - 1) goto fail; - C_memcpy(sptr = buffer, C_c_string(str), n > (STRING_BUFFER_SIZE - 1) ? STRING_BUFFER_SIZE : n); + C_memcpy(sptr = buffer, C_c_string(str), n); buffer[ n ] = '\0'; while(*sptr == '#') { @@ -7295,7 +7294,7 @@ /* Scan for embedded special characters and do basic sanity checking: */ for(eptr = sptr, rptr = sptr; *eptr != '\0'; ++eptr) { - switch(C_tolower((int)*eptr)) { + switch(*eptr) { case '.': if(periodf || ratf || expf) goto fail; @@ -7318,11 +7317,11 @@ ratf = 1; rptr = eptr+1; break; - case 'e': - case 'd': - case 'f': - case 'l': - case 's': + case 'e': case 'E': + case 'd': case 'D': + case 'f': case 'F': + case 'l': case 'L': + case 's': case 'S': /* Don't set exp flag if we see the "f" in "inf.0" (preceded by 'n') */ /* Other failure modes are handled elsewhere. */ if(radix == 10 && eptr > sptr && C_tolower((int)*(eptr-1)) != 'n') { @@ -7343,15 +7342,13 @@ /* check for rational representation: */ if(rptr != sptr) { if (*(rptr) == '-' || *(rptr) == '+') { - n = C_SCHEME_FALSE; - goto fini; + return C_SCHEME_FALSE; } *(rptr-1) = '\0'; - switch(convert_string_to_number(sptr, radix, &n1, &fn1)) { + switch(convert_string_to_number(sptr, n - (sptr - buffer), radix, &n1, &fn1)) { case 0: - n = C_SCHEME_FALSE; - goto fini; + return C_SCHEME_FALSE; case 1: fn1 = (double)n1; @@ -7362,9 +7359,9 @@ sptr = rptr; } - + /* convert number and return result: */ - switch(convert_string_to_number(sptr, radix, &n, &fn)) { + switch(convert_string_to_number(sptr, n - (sptr - buffer), radix, &n, &fn)) { case 0: /* failed */ n = C_SCHEME_FALSE; break; @@ -7435,13 +7432,12 @@ } -C_regparm C_word C_fcall convert_string_to_number(C_char *str, int radix, C_word *fix, double *flo) +C_regparm C_word C_fcall convert_string_to_number(C_char *str, int len, int radix, C_word *fix, double *flo) { unsigned long ln; C_word n; C_char *eptr, *eptr2; double fn; - int len = C_strlen(str); if(radix == 10) { if (len >= 4 && len <= 6) { /* DEPRECATED, TODO: Change to (len == 4) */ @@ -7471,11 +7467,11 @@ #endif } - if(C_strpbrk(str, "xX\0") != NULL) return 0; + if(C_strpbrk(str, "xX") != NULL) return 0; errno = 0; n = C_strtol(str, &eptr, radix); - + if(((n == LONG_MAX || n == LONG_MIN) && errno == ERANGE) || *eptr != '\0') { if(radix != 10) return from_n_nary(str, radix, flo) ? 2 : 0; @@ -7485,7 +7481,7 @@ if(fn == HUGE_VAL && errno == ERANGE) return 0; else if(eptr2 == str) return 0; - else if(*eptr2 == '\0' || (eptr != eptr2 && !C_strncmp(eptr2, ".0", C_strlen(eptr2)))) { + else if(*eptr2 == '\0' || (eptr != eptr2 && !C_strncmp(eptr2, ".0", len - (eptr2-str)))) { *flo = fn; return 2; } @@ -7493,7 +7489,7 @@ return 0; } else if((n & C_INT_SIGN_BIT) != ((n << 1) & C_INT_SIGN_BIT)) { /* doesn't fit into fixnum? */ - if(*eptr == '\0' || !C_strncmp(eptr, ".0", C_strlen(eptr))) { + if(*eptr == '\0' || !C_strncmp(eptr, ".0", len - (eptr-str))) { *flo = (double)n; return 2; } @@ -8848,7 +8844,7 @@ C_word ln; double fn; - switch (convert_string_to_number(*str, 10, &ln, &fn)) { + switch (convert_string_to_number(*str, C_strlen(*str), 10, &ln, &fn)) { case 0: /* failed */ panic(C_text("invalid encoded numeric literal")); break;