From 2201229b4aebd2ebb08eae05ff197f0adfd4f4e5 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 20 Jul 2005 01:08:13 +0000 Subject: [PATCH] * variable.c (rb_class_path): need to adjust snprintf() len for teminating NUL. [ruby-dev:26581] * error.c (syserr_initialize): don't use str before StringValue() check. [ruby-dev:26579] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ error.c | 6 ++++-- object.c | 12 ++++++------ struct.c | 4 ++-- variable.c | 2 +- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c38f8d84b..c0962089ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jul 20 10:04:51 2005 Yukihiro Matsumoto + + * variable.c (rb_class_path): need to adjust snprintf() len for + teminating NUL. [ruby-dev:26581] + Wed Jul 20 03:58:52 2005 Hirokazu Yamamoto * ext/socket/socket.c: sorry, BeOS also uses HAVE_CLOSESOCKET, @@ -12,6 +17,11 @@ Wed Jul 20 03:12:21 2005 Hirokazu Yamamoto it's defined to rb_w32_close(), otherwise handle leaks. [ruby-Bugs-2131] +Wed Jul 20 00:48:16 2005 Yukihiro Matsumoto + + * error.c (syserr_initialize): don't use str before StringValue() + check. [ruby-dev:26579] + Tue Jul 19 22:47:29 2005 Yukihiro Matsumoto * error.c (syserr_initialize): add 1 byte for snprintf() size for diff --git a/error.c b/error.c index d21f990ae9..f35dc2ba3e 100644 --- a/error.c +++ b/error.c @@ -956,12 +956,14 @@ syserr_initialize(argc, argv, self) else err = "unknown error"; if (!NIL_P(mesg)) { VALUE str = mesg; - size_t len = strlen(err)+RSTRING(str)->len+3; + size_t len; + StringValue(str); + len = strlen(err)+RSTRING(str)->len+3; mesg = rb_str_new(0, len); snprintf(RSTRING(mesg)->ptr, len+1, "%s - %.*s", err, (int)RSTRING(str)->len, RSTRING(str)->ptr); - rb_str_resize(mesg, strlen(RSTRING(mesg)->ptr)); + RSTRING(mesg)->len = strlen(RSTRING(mesg)->ptr); } else { mesg = rb_str_new2(err); diff --git a/object.c b/object.c index 332b22fc61..af8f289f46 100644 --- a/object.c +++ b/object.c @@ -301,9 +301,9 @@ rb_any_to_s(obj) size_t len; VALUE str; - len = strlen(cname)+6+16+1; - str = rb_str_new(0, len); /* 6:tags 16:addr 1:nul */ - snprintf(RSTRING(str)->ptr, len, "#<%s:0x%lx>", cname, obj); + len = strlen(cname)+6+16; + str = rb_str_new(0, len); /* 6:tags 16:addr */ + snprintf(RSTRING(str)->ptr, len+1, "#<%s:0x%lx>", cname, obj); RSTRING(str)->len = strlen(RSTRING(str)->ptr); if (OBJ_TAINTED(obj)) OBJ_TAINT(str); @@ -389,9 +389,9 @@ rb_obj_inspect(obj) char *c; c = rb_obj_classname(obj); - len = strlen(c)+10+16+1; - str = rb_str_new(0, len); /* 10:tags 16:addr 1:nul */ - snprintf(RSTRING(str)->ptr, len, "-<%s:0x%lx", c, obj); + len = strlen(c)+10+16; + str = rb_str_new(0, len); /* 10:tags 16:addr */ + snprintf(RSTRING(str)->ptr, len+1, "-<%s:0x%lx", c, obj); RSTRING(str)->len = strlen(RSTRING(str)->ptr); return rb_exec_recursive(inspect_obj, obj, str); } diff --git a/struct.c b/struct.c index a8429a405e..4468cbe0f3 100644 --- a/struct.c +++ b/struct.c @@ -477,10 +477,10 @@ inspect_struct(s, dummy, recur) if (recur) { char *cname = rb_class2name(rb_obj_class(s)); - size_t len = strlen(cname) + 15; + size_t len = strlen(cname) + 14; VALUE str = rb_str_new(0, len); - snprintf(RSTRING(str)->ptr, len, "#", cname); + snprintf(RSTRING(str)->ptr, len+1, "#", cname); RSTRING(str)->len = strlen(RSTRING(str)->ptr); return str; } diff --git a/variable.c b/variable.c index 02483fe8af..1139b016ca 100644 --- a/variable.c +++ b/variable.c @@ -208,7 +208,7 @@ rb_class_path(klass) } len = 2 + strlen(s) + 3 + 2 * SIZEOF_LONG + 1; path = rb_str_new(0, len); - snprintf(RSTRING(path)->ptr, len, "#<%s:0x%lx>", s, klass); + snprintf(RSTRING(path)->ptr, len+1, "#<%s:0x%lx>", s, klass); RSTRING(path)->len = strlen(RSTRING(path)->ptr); rb_ivar_set(klass, tmp_classpath, path);