ruby-changes:10832
From: akr <ko1@a...>
Date: Wed, 18 Feb 2009 21:35:32 +0900 (JST)
Subject: [ruby-changes:10832] Ruby:r22402 (trunk): * ext/socket/ancdata.c (bsock_sendmsg_internal): avoid misalignment.
akr 2009-02-18 21:35:22 +0900 (Wed, 18 Feb 2009) New Revision: 22402 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22402 Log: * ext/socket/ancdata.c (bsock_sendmsg_internal): avoid misalignment. Modified files: trunk/ChangeLog trunk/ext/socket/ancdata.c Index: ChangeLog =================================================================== --- ChangeLog (revision 22401) +++ ChangeLog (revision 22402) @@ -1,5 +1,9 @@ -Wed Feb 18 12:09:43 2009 Tanaka Akira <akr@f...> +Wed Feb 18 21:34:30 2009 Tanaka Akira <akr@f...> + * ext/socket/ancdata.c (bsock_sendmsg_internal): avoid misalignment. + +Wed Feb 18 21:09:43 2009 Tanaka Akira <akr@f...> + * ext/socket/ancdata.c (bsock_recvmsg_internal): reduce code on environments which have no control message. Index: ext/socket/ancdata.c =================================================================== --- ext/socket/ancdata.c (revision 22401) +++ ext/socket/ancdata.c (revision 22402) @@ -899,7 +899,8 @@ int level, type; VALUE cdata; long oldlen; - struct cmsghdr *cmh; + struct cmsghdr cmh; + char *cmsg; size_t cspace; v = rb_check_convert_type(elt, T_ARRAY, "Array", "to_ary"); if (!NIL_P(v)) { @@ -921,15 +922,17 @@ oldlen = RSTRING_LEN(controls_str); cspace = CMSG_SPACE(RSTRING_LEN(cdata)); rb_str_resize(controls_str, oldlen + cspace); - cmh = (struct cmsghdr *)(RSTRING_PTR(controls_str)+oldlen); - memset((char *)cmh, 0, cspace); - cmh->cmsg_level = level; - cmh->cmsg_type = type; - cmh->cmsg_len = CMSG_LEN(RSTRING_LEN(cdata)); - MEMCPY(CMSG_DATA(cmh), RSTRING_PTR(cdata), char, RSTRING_LEN(cdata)); - last_level = cmh->cmsg_level; - last_type = cmh->cmsg_type; - last_pad = cspace - cmh->cmsg_len; + cmsg = RSTRING_PTR(controls_str)+oldlen; + memset((char *)cmsg, 0, cspace); + memset((char *)&cmh, 0, sizeof(cmh)); + cmh.cmsg_level = level; + cmh.cmsg_type = type; + cmh.cmsg_len = CMSG_LEN(RSTRING_LEN(cdata)); + MEMCPY(cmsg, &cmh, char, sizeof(cmh)); + MEMCPY(cmsg+((char*)CMSG_DATA(&cmh)-(char*)&cmh), RSTRING_PTR(cdata), char, RSTRING_LEN(cdata)); + last_level = cmh.cmsg_level; + last_type = cmh.cmsg_type; + last_pad = cspace - cmh.cmsg_len; } if (last_pad) { /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/