diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-20 12:50:29 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-20 12:50:29 +0000 |
commit | 43e55c6bc4ef107d1be548ed24a2772f96d36987 (patch) | |
tree | 263291948f5a1df39402026086188a65d05219be /time.c | |
parent | 01dacec2b4f7ec733ebea7b0427fc123542be21e (diff) | |
download | ruby-43e55c6bc4ef107d1be548ed24a2772f96d36987.tar.gz |
* time.c (time_mload): ignore invalid digits in submicro.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -2244,9 +2244,6 @@ time_mload(VALUE time, VALUE str) nsec = usec * 1000; } else { - unsigned char *ptr; - long len; - p &= ~(1UL<<31); gmt = (p >> 30) & 0x1; tm.tm_year = (p >> 14) & 0xffff; @@ -2262,15 +2259,22 @@ time_mload(VALUE time, VALUE str) nsec = usec * 1000; if (submicro != Qnil) { + unsigned char *ptr; + long len; + int digit; ptr = (unsigned char*)StringValuePtr(submicro); len = RSTRING_LEN(submicro); if (0 < len) { - nsec += (ptr[0] >> 4) * 100; - nsec += (ptr[0] & 0xf) * 10; + if (10 <= (digit = ptr[0] >> 4)) goto end_submicro; + nsec += digit * 100; + if (10 <= (digit = ptr[0] & 0xf)) goto end_submicro; + nsec += digit * 10; } if (1 < len) { - nsec += (ptr[1] >> 4); + if (10 <= (digit = ptr[1] >> 4)) goto end_submicro; + nsec += digit; } +end_submicro: ; } } time_overflow_p(&sec, &nsec); |