summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-04 13:42:47 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-04 13:42:47 +0000
commitfd6dd50f95ebdee32870eda101394e7aa7cb629c (patch)
tree4acdf8e00ad015f9754186424def475fb9699b5a /time.c
parent6ae3cf02f7eb051011b8d47623500641edd9cf14 (diff)
time.c: avoid taking a pointer to a member of packed struct
clang 4.0.0 emitted a warning: "taking address of packed member 'subsecx' of class or structure 'vtm' may result in an unaligned pointer value [-Waddress-of-packed-member]". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/time.c b/time.c
index 2d9bf04559..d9a2156874 100644
--- a/time.c
+++ b/time.c
@@ -835,10 +835,12 @@ gmtimew_noleapsecond(wideval_t timew, struct vtm *vtm)
int wday;
VALUE timev;
wideval_t timew2, w, w2;
+ VALUE subsecx;
vtm->isdst = 0;
- split_second(timew, &timew2, &vtm->subsecx);
+ split_second(timew, &timew2, &subsecx);
+ vtm->subsecx = subsecx;
wdivmod(timew2, WINT2FIXWV(86400), &w2, &w);
timev = w2v(w2);
@@ -1992,8 +1994,15 @@ time_init_1(int argc, VALUE *argv, VALUE time)
vtm.min = NIL_P(v[4]) ? 0 : obj2ubits(v[4], 6);
- vtm.subsecx = INT2FIX(0);
- vtm.sec = NIL_P(v[5]) ? 0 : obj2subsecx(v[5], &vtm.subsecx);
+ if (NIL_P(v[5])) {
+ vtm.sec = 0;
+ vtm.subsecx = INT2FIX(0);
+ }
+ else {
+ VALUE subsecx;
+ vtm.sec = obj2subsecx(v[5], &subsecx);
+ vtm.subsecx = subsecx;
+ }
vtm.isdst = VTM_ISDST_INITVAL;
vtm.utc_offset = Qnil;
@@ -2530,6 +2539,7 @@ static void
time_arg(int argc, VALUE *argv, struct vtm *vtm)
{
VALUE v[8];
+ VALUE subsecx = INT2FIX(0);
vtm->year = INT2FIX(0);
vtm->mon = 0;
@@ -2583,16 +2593,22 @@ time_arg(int argc, VALUE *argv, struct vtm *vtm)
vtm->min = NIL_P(v[4])?0:obj2ubits(v[4], 6);
if (!NIL_P(v[6]) && argc == 7) {
- vtm->sec = NIL_P(v[5])?0:obj2ubits(v[5],6);
- vtm->subsecx = usec2subsecx(v[6]);
+ vtm->sec = NIL_P(v[5])?0:obj2ubits(v[5],6);
+ subsecx = usec2subsecx(v[6]);
}
else {
/* when argc == 8, v[6] is timezone, but ignored */
- vtm->sec = NIL_P(v[5])?0:obj2subsecx(v[5], &vtm->subsecx);
+ if (NIL_P(v[5])) {
+ vtm->sec = 0;
+ }
+ else {
+ vtm->sec = obj2subsecx(v[5], &subsecx);
+ }
}
+ vtm->subsecx = subsecx;
validate_vtm(vtm);
- RB_GC_GUARD(vtm->subsecx);
+ RB_GC_GUARD(subsecx);
}
static int