summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-12-25 16:19:33 +0900
committerNARUSE, Yui <naruse@airemix.jp>2021-12-25 18:39:24 +0900
commitcd50457455a7a1af5e0bcf896ce019b891038708 (patch)
treeb0969d0f453d332386b2272a3d05058ba58c4e83 /time.c
parente6e24ee502714b80723d81b3bc555a707747fda3 (diff)
Raise proper exception when month argument is not a name
https://bugs.ruby-lang.org/issues/17485#change-89871 (cherry picked from commit 0867b638aff9ec192ca420a44ffa5a77c892e8f2)
Diffstat (limited to 'time.c')
-rw-r--r--time.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/time.c b/time.c
index 8f044e1e59..77f42fc89a 100644
--- a/time.c
+++ b/time.c
@@ -2789,9 +2789,10 @@ month_arg(VALUE arg)
return obj2ubits(arg, 4);
}
+ mon = 0;
VALUE s = rb_check_string_type(arg);
if (!NIL_P(s) && RSTRING_LEN(s) > 0) {
- mon = 0;
+ arg = s;
for (i=0; i<12; i++) {
if (RSTRING_LEN(s) == 3 &&
STRNCASECMP(months[i], RSTRING_PTR(s), 3) == 0) {
@@ -2799,15 +2800,8 @@ month_arg(VALUE arg)
break;
}
}
- if (mon == 0) {
- char c = RSTRING_PTR(s)[0];
-
- if ('0' <= c && c <= '9') {
- mon = obj2ubits(s, 4);
- }
- }
}
- else {
+ if (mon == 0) {
mon = obj2ubits(arg, 4);
}
return mon;