ruby-changes:53414
From: shyouhei <ko1@a...>
Date: Thu, 8 Nov 2018 15:23:01 +0900 (JST)
Subject: [ruby-changes:53414] shyouhei:r65630 (trunk): avoid (size_t)-- (2nd try)
shyouhei 2018-11-08 15:22:57 +0900 (Thu, 08 Nov 2018) New Revision: 65630 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65630 Log: avoid (size_t)-- (2nd try) 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 65629) +++ util.c (revision 65630) @@ -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 65629) +++ st.c (revision 65630) @@ -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; + size_t 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/