From 5f1578c0d17b05f5158e467bd3abf18565fe1b4b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 22 Feb 2011 15:32:40 -0800 Subject: use StringValueCStr for paths RSTRING_PTR may contain '\0' bytes which makes it unsuitable for mq_unlink() and mq_open() --- ext/posix_mq/posix_mq.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'ext/posix_mq/posix_mq.c') diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c index c02d697..01b5dbd 100644 --- a/ext/posix_mq/posix_mq.c +++ b/ext/posix_mq/posix_mq.c @@ -346,9 +346,6 @@ static VALUE init(int argc, VALUE *argv, VALUE self) rb_scan_args(argc, argv, "13", &name, &oflags, &mode, &attr); - if (TYPE(name) != T_STRING) - rb_raise(rb_eArgError, "name must be a string"); - switch (TYPE(oflags)) { case T_NIL: x.oflags = O_RDONLY; @@ -375,7 +372,7 @@ static VALUE init(int argc, VALUE *argv, VALUE self) rb_raise(rb_eArgError, "flags must be an int, :r, :w, or :wr"); } - x.name = RSTRING_PTR(name); + x.name = StringValueCStr(name); x.argc = 2; switch (TYPE(mode)) { @@ -434,12 +431,8 @@ static VALUE init(int argc, VALUE *argv, VALUE self) */ static VALUE s_unlink(VALUE self, VALUE name) { - mqd_t rv; - - if (TYPE(name) != T_STRING) - rb_raise(rb_eArgError, "argument must be a string"); + mqd_t rv = mq_unlink(StringValueCStr(name)); - rv = mq_unlink(RSTRING_PTR(name)); if (rv == MQD_INVALID) rb_sys_fail("mq_unlink"); -- cgit v1.2.3-24-ge0c7