From 66d1582c07db57b4a1a1cd0ab7d79f042be80faa Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 17 Oct 2002 07:27:00 +0000 Subject: * object.c (rb_str_to_dbl): RString ptr might be NULL. * object.c (rb_cstr_to_dbl): p pointer might be NULL. * bignum.c (rb_str_to_inum): RString ptr might be NULL. * bignum.c (rb_cstr_to_inum): str pointer might be NULL. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 17 +++++++++++++++++ bignum.c | 26 ++++++++++++++++---------- gc.c | 2 +- lib/net/http.rb | 9 +++++++++ object.c | 19 +++++++++++-------- parse.y | 11 ++++++----- 6 files changed, 60 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7684c87559..6c3dc18905 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,11 +17,28 @@ Wed Oct 16 13:36:29 2002 Nobuyoshi Nakada * variable.c (rb_alias_variable): ditto. +Wed Oct 16 01:03:54 2002 Yukihiro Matsumoto + + * object.c (rb_str_to_dbl): RString ptr might be NULL. + + * object.c (rb_cstr_to_dbl): p pointer might be NULL. + + * bignum.c (rb_str_to_inum): RString ptr might be NULL. + + * bignum.c (rb_cstr_to_inum): str pointer might be NULL. + Sat Oct 12 23:44:11 2002 Nobuyoshi Nakada * win32/win32.c (rb_w32_putc): wrong condition to fill or flush on bccwin32. [ruby-win32:408] +Fri Oct 11 15:58:06 2002 Yukihiro Matsumoto + + * parse.y (arg): rescue modifier is now an operator with + precedence right below assignments. i.e. "a = b rescue c" now + parsed as "a = (b rescue c)", not as "(a = b) rescue c". [new] + [experimental] + Fri Oct 11 06:05:30 2002 Nobuyoshi Nakada * win32/win32.c (rb_w32_fclose, rb_w32_close): use closesocket() diff --git a/bignum.c b/bignum.c index 3cf4544cb4..0d23189955 100644 --- a/bignum.c +++ b/bignum.c @@ -319,6 +319,10 @@ rb_cstr_to_inum(str, base, badcheck) VALUE z; BDIGIT *zds; + if (!str) { + if (badcheck) goto bad; + return INT2FIX(0); + } if (badcheck) { while (ISSPACE(*str)) str++; } @@ -501,16 +505,18 @@ rb_str_to_inum(str, base, badcheck) StringValue(str); s = RSTRING(str)->ptr; - len = RSTRING(str)->len; - if (s[len]) { /* no sentinel somehow */ - char *p = ALLOCA_N(char, len+1); - - MEMCPY(p, s, char, len); - p[len] = '\0'; - s = p; - } - if (badcheck && len != strlen(s)) { - rb_raise(rb_eArgError, "string for Integer contains null byte"); + if (s) { + len = RSTRING(str)->len; + if (s[len]) { /* no sentinel somehow */ + char *p = ALLOCA_N(char, len+1); + + MEMCPY(p, s, char, len); + p[len] = '\0'; + s = p; + } + if (badcheck && len != strlen(s)) { + rb_raise(rb_eArgError, "string for Integer contains null byte"); + } } return rb_cstr_to_inum(s, base, badcheck); } diff --git a/gc.c b/gc.c index a7486aa9f3..0ef797077e 100644 --- a/gc.c +++ b/gc.c @@ -991,7 +991,7 @@ gc_sweep() } } } - for (i = j = 0; j < heaps_used; i++) { + for (i = j = 1; j < heaps_used; i++) { if (heaps_limits[i] == 0) { free(heaps[i]); heaps_used--; diff --git a/lib/net/http.rb b/lib/net/http.rb index 0a1a714a0d..6a906ad11e 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -476,6 +476,11 @@ All arguments named KEY is case-insensitive. : self[ key ] = val sets the header field corresponding to the case-insensitive key. +: fetch( key [,default] ) + + returns the header field corresponding to the case-insensitive key. + returns the default value if there's no header field named key. + : key?( key ) true if key exists. KEY is case insensitive. @@ -923,6 +928,10 @@ module Net @header.delete key.downcase end + def fetch(*args) + @header.fetch(*args) + end + def key?( key ) @header.key? key.downcase end diff --git a/object.c b/object.c index 72805e9d67..f5058548ae 100644 --- a/object.c +++ b/object.c @@ -1031,6 +1031,7 @@ rb_cstr_to_dbl(p, badcheck) char *end; double d; + if (!p) return 0.0; q = p; if (badcheck) { while (ISSPACE(*p)) p++; @@ -1093,15 +1094,17 @@ rb_str_to_dbl(str, badcheck) StringValue(str); s = RSTRING(str)->ptr; len = RSTRING(str)->len; - if (s[len]) { /* no sentinel somehow */ - char *p = ALLOCA_N(char, len+1); + if (s) { + if (s[len]) { /* no sentinel somehow */ + char *p = ALLOCA_N(char, len+1); - MEMCPY(p, s, char, len); - p[len] = '\0'; - s = p; - } - if (badcheck && len != strlen(s)) { - rb_raise(rb_eArgError, "string for Float contains null byte"); + MEMCPY(p, s, char, len); + p[len] = '\0'; + s = p; + } + if (badcheck && len != strlen(s)) { + rb_raise(rb_eArgError, "string for Float contains null byte"); + } } return rb_cstr_to_dbl(s, badcheck); } diff --git a/parse.y b/parse.y index 56332e3125..b9ca1fa96c 100644 --- a/parse.y +++ b/parse.y @@ -282,11 +282,12 @@ static void top_local_setup(); * precedence table */ -%left kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD kRESCUE_MOD +%left kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD %left kOR kAND %right kNOT %nonassoc kDEFINED %right '=' tOP_ASGN +%left kRESCUE_MOD %right '?' ':' %nonassoc tDOT2 tDOT3 %left tOROP @@ -423,10 +424,6 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem $$ = NEW_UNTIL(cond($3), $1, 1); } } - | stmt kRESCUE_MOD stmt - { - $$ = NEW_RESCUE($1, NEW_RESBODY(0,$3,0), 0); - } | klBEGIN { if (in_def || in_single) { @@ -1039,6 +1036,10 @@ arg : lhs '=' arg { $$ = logop(NODE_OR, $1, $3); } + | arg kRESCUE_MOD arg + { + $$ = NEW_RESCUE($1, NEW_RESBODY(0,$3,0), 0); + } | kDEFINED opt_nl {in_defined = 1;} arg { in_defined = 0; -- cgit v1.2.3