1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/socket/ancdata.c (bsock_sendmsg_internal): avoid misalignment.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-02-18 12:35:22 +00:00
parent d89e09b308
commit 34152d654a
2 changed files with 18 additions and 11 deletions

View file

@ -1,4 +1,8 @@
Wed Feb 18 12:09:43 2009 Tanaka Akira <akr@fsij.org>
Wed Feb 18 21:34:30 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/ancdata.c (bsock_sendmsg_internal): avoid misalignment.
Wed Feb 18 21:09:43 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/ancdata.c (bsock_recvmsg_internal): reduce code on
environments which have no control message.

View file

@ -899,7 +899,8 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
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 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
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) {
/*