mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Mon Jan 15 16:00:07 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (pack_unpack): should check associated pointer packed by pack("P"). restriction added. Sun Jan 14 21:49:28 2001 Koji Arai <JCA02266@nifty.ne.jp> * sprintf.c (rb_f_sprintf): simple typo. binary base should be 2, not '2'. * re.c (rb_reg_s_last_match): should explicitly return nth match. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ac8a2a31c2
commit
971a4d94f0
14 changed files with 109 additions and 56 deletions
37
pack.c
37
pack.c
|
@ -857,11 +857,11 @@ pack_pack(ary, fmt)
|
|||
while (len-- > 0) {
|
||||
char *t;
|
||||
from = NEXTFROM;
|
||||
if (NIL_P(from)) t = "";
|
||||
else {
|
||||
t = STR2CSTR(from);
|
||||
rb_str_associate(res, from);
|
||||
if (NIL_P(from)) {
|
||||
from = rb_str_new(0, 0);
|
||||
}
|
||||
t = STR2CSTR(from);
|
||||
rb_str_associate(res, from);
|
||||
rb_str_cat(res, (char*)&t, sizeof(char*));
|
||||
}
|
||||
break;
|
||||
|
@ -1611,12 +1611,33 @@ pack_unpack(str, fmt)
|
|||
case 'P':
|
||||
if (sizeof(char *) <= send - s) {
|
||||
char *t;
|
||||
VALUE str = rb_str_new(0, 0);
|
||||
VALUE a, tmp;
|
||||
|
||||
if (!(a = rb_str_associated(str))) {
|
||||
rb_raise(rb_eArgError, "no associated pointer");
|
||||
}
|
||||
memcpy(&t, s, sizeof(char *));
|
||||
s += sizeof(char *);
|
||||
if (t)
|
||||
rb_str_cat(str, t, len);
|
||||
rb_ary_push(ary, str);
|
||||
|
||||
if (t) {
|
||||
VALUE *p, *pend;
|
||||
|
||||
p = RARRAY(a)->ptr;
|
||||
pend = p + RARRAY(a)->len;
|
||||
while (p < pend) {
|
||||
if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t)
|
||||
break;
|
||||
p++;
|
||||
}
|
||||
if (p == pend) {
|
||||
rb_raise(rb_eArgError, "non associated pointer");
|
||||
}
|
||||
tmp = rb_str_new(t, len);
|
||||
}
|
||||
else {
|
||||
tmp = rb_str_new(0, 0);
|
||||
}
|
||||
rb_ary_push(ary, tmp);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue