ruby-changes:45042
From: nobu <ko1@a...>
Date: Mon, 19 Dec 2016 17:36:27 +0900 (JST)
Subject: [ruby-changes:45042] nobu:r57115 (trunk): time.c: refine error message
nobu 2016-12-19 17:36:21 +0900 (Mon, 19 Dec 2016) New Revision: 57115 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57115 Log: time.c: refine error message * time.c (validate_vtm): separate validation failure messages for each members. Modified files: trunk/time.c Index: time.c =================================================================== --- time.c (revision 57114) +++ time.c (revision 57115) @@ -2514,15 +2514,18 @@ validate_zone_name(VALUE zone_name) https://github.com/ruby/ruby/blob/trunk/time.c#L2514 static void validate_vtm(struct vtm *vtm) { - if ( vtm->mon < 1 || vtm->mon > 12 - || vtm->mday < 1 || vtm->mday > 31 - || vtm->hour < 0 || vtm->hour > 24 - || (vtm->hour == 24 && (vtm->min > 0 || vtm->sec > 0)) - || vtm->min < 0 || vtm->min > 59 - || vtm->sec < 0 || vtm->sec > 60 - || lt(vtm->subsecx, INT2FIX(0)) || ge(vtm->subsecx, INT2FIX(TIME_SCALE)) - || (!NIL_P(vtm->utc_offset) && (validate_utc_offset(vtm->utc_offset), 0))) - rb_raise(rb_eArgError, "argument out of range"); +#define validate_vtm_range(mem, b, e) \ + ((vtm->mem < b || vtm->mem > e) ? \ + rb_raise(rb_eArgError, #mem" out of range") : (void)0) + validate_vtm_range(mon, 1, 12); + validate_vtm_range(mday, 1, 31); + validate_vtm_range(hour, 0, 24); + validate_vtm_range(min, 0, (vtm->hour == 24 ? 0 : 59)); + validate_vtm_range(sec, 0, (vtm->hour == 24 ? 0 : 60)); + if (lt(vtm->subsecx, INT2FIX(0)) || ge(vtm->subsecx, INT2FIX(TIME_SCALE))) + rb_raise(rb_eArgError, "subsecx out of range"); + if (!NIL_P(vtm->utc_offset)) validate_utc_offset(vtm->utc_offset); +#undef validate_vtm_range } static void -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/