about summary refs log tree commit homepage
path: root/ext/posix_mq/posix_mq.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-02-22 15:32:40 -0800
committerEric Wong <normalperson@yhbt.net>2011-02-22 15:39:42 -0800
commit5f1578c0d17b05f5158e467bd3abf18565fe1b4b (patch)
treeb210653369612e3e5360a31eaa42501a8181de2c /ext/posix_mq/posix_mq.c
parenta5491670078b045ced2641649a6cfceee2cade10 (diff)
downloadruby_posix_mq-5f1578c0d17b05f5158e467bd3abf18565fe1b4b.tar.gz
RSTRING_PTR may contain '\0' bytes which makes it unsuitable
for mq_unlink() and mq_open()
Diffstat (limited to 'ext/posix_mq/posix_mq.c')
-rw-r--r--ext/posix_mq/posix_mq.c11
1 files changed, 2 insertions, 9 deletions
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");