From 480a21f435d2917190c087206bbffbd3d532824a Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 1 Sep 2018 06:19:05 +0000 Subject: RSTRING_PTR may not be terminated in the future git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/date/date_strptime.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ext/date/date_strptime.c') diff --git a/ext/date/date_strptime.c b/ext/date/date_strptime.c index 877baea435..4383eb6fa1 100644 --- a/ext/date/date_strptime.c +++ b/ext/date/date_strptime.c @@ -79,14 +79,17 @@ read_digits(const char *s, VALUE *n, size_t width) { size_t l; - l = strspn(s, "0123456789"); + if (!width) + return 0; + + l = 0; + while (ISDIGIT(s[l])) { + if (++l == width) break; + } if (l == 0) return 0; - if (width < l) - l = width; - if ((4 * l * sizeof(char)) <= (sizeof(long)*CHAR_BIT)) { const char *os = s; long v; -- cgit v1.2.3