Hi,

At Sat, 15 Jul 2006 00:36:37 +0900,
Justin Bailey wrote in [ruby-core:08223]:
>   puts outer.unpack("P4").first.unpack("P3") # ArgumentError - no associated
> pointer
> 
> I get an error. Now, I think I understand why this happens - pointers have
> to be associated with variables. It would be dangerous to unpack to treat
> any string as a pointer. However, I do think the above is surprising
> behavior. It took me awhile to understand why my nested structures didn't
> seem to work.

Since the result string will be tainted, so the original string
also will be tainted implicitly.  But now I about to think it
should be tainted too.


Index: pack.c =================================================================== RCS file: /cvs/ruby/src/ruby/pack.c,v retrieving revision 1.84 diff -p -U 2 -r1.84 pack.c --- pack.c 9 Jun 2006 21:20:12 -0000 1.84 +++ pack.c 14 Jul 2006 16:16:48 -0000 @@ -1875,6 +1875,10 @@ pack_unpack(VALUE str, VALUE fmt) while (p < pend) { if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t) { - if (len > RSTRING(*p)->len) { - len = RSTRING(*p)->len; + rb_obj_taint(*p); + if (len < RSTRING(*p)->len) { + tmp = rb_tainted_str_new(t, len); + } + else { + tmp = *p; } break; @@ -1885,5 +1889,4 @@ pack_unpack(VALUE str, VALUE fmt) rb_raise(rb_eArgError, "non associated pointer"); } - tmp = rb_tainted_str_new(t, len); } else {
-- Nobu Nakada