summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-11-18 14:17:10 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-12-16 22:52:59 +0900
commit635fc5f7fc88a2344118e7a156ff1b2644d0de0c (patch)
treee19a290c77b7085e3e00afc86b95e03e85fffc75 /time.c
parent9515179d74f2d9934c1b2c69879d72254d940f85 (diff)
downloadruby-635fc5f7fc88a2344118e7a156ff1b2644d0de0c.tar.gz
[Feature #18033] Make more conformant with C standard
Diffstat (limited to 'time.c')
-rw-r--r--time.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/time.c b/time.c
index bd147a1878..de24690ff7 100644
--- a/time.c
+++ b/time.c
@@ -2523,9 +2523,10 @@ time_init_parse(rb_execution_context_t *ec, VALUE klass, VALUE str, VALUE zone,
rb_raise(rb_eArgError, "year must be 2 or 4+ digits: %.*s", (int)ndigits, ptr - ndigits);
}
do {
-#define peek_n(c, n) ((ptr + n < end) && ((unsigned char)ptr[n] == (c)))
+#define peekable_p(n) ((ptrdiff_t)(n) < (end - ptr))
+#define peek_n(c, n) (peekable_p(n) && ((unsigned char)ptr[n] == (c)))
#define peek(c) peek_n(c, 0)
-#define peekc_n(n) ((ptr + n < end) ? (int)(unsigned char)ptr[n] : -1)
+#define peekc_n(n) (peekable_p(n) ? (int)(unsigned char)ptr[n] : -1)
#define peekc() peekc_n(0)
#define expect_two_digits(x) (x = two_digits(ptr + 1, end, &ptr, #x))
if (!peek('-')) break;