ruby-changes:53408
From: shyouhei <ko1@a...>
Date: Thu, 8 Nov 2018 14:06:55 +0900 (JST)
Subject: [ruby-changes:53408] shyouhei:r65624 (trunk): avoid (size_t)--
shyouhei 2018-11-08 14:06:52 +0900 (Thu, 08 Nov 2018) New Revision: 65624 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65624 Log: avoid (size_t)-- The decrements overflow and these variables remain ~0 when leaving the while loops. They are not fatal by accident, but better replace with ordinal for loops. See also: https://travis-ci.org/ruby/ruby/jobs/452218871#L3246 Modified files: trunk/st.c trunk/util.c Index: util.c =================================================================== --- util.c (revision 65623) +++ util.c (revision 65624) @@ -35,8 +35,12 @@ ruby_scan_oct(const char *start, size_t https://github.com/ruby/ruby/blob/trunk/util.c#L35 { register const char *s = start; register unsigned long retval = 0; + size_t i; - while (len-- && *s >= '0' && *s <= '7') { + for (i = 0; i < len; i++) { + if ((s[0] < '0') || ('7' <= s[0])) { + break; + } retval <<= 3; retval |= *s++ - '0'; } Index: st.c =================================================================== --- st.c (revision 65623) +++ st.c (revision 65624) @@ -2036,8 +2036,9 @@ int https://github.com/ruby/ruby/blob/trunk/st.c#L2036 st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n) { char c1, c2; + int i; - while (n--) { + for (i = 0; i < n; i++) { c1 = *s1++; c2 = *s2++; if (c1 == '\0' || c2 == '\0') { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/