From a1d8147e4419d81cd93c664b85f7062c89101c87 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 31 Mar 1998 04:52:10 +0000 Subject: eval(..,file,line);String#center git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 59e4024bbf..43c8aaac37 100644 --- a/string.c +++ b/string.c @@ -2530,7 +2530,7 @@ str_ljust(str, w) VALUE res; UCHAR *p, *pend; - if (RSTRING(str)->len >= width) return str; + if (width < 0 || RSTRING(str)->len >= width) return str; res = str_new(0, width); memcpy(RSTRING(res)->ptr, RSTRING(str)->ptr, RSTRING(str)->len); p = RSTRING(res)->ptr + RSTRING(str)->len; pend = RSTRING(res)->ptr + width; @@ -2549,7 +2549,7 @@ str_rjust(str, w) VALUE res; UCHAR *p, *pend; - if (RSTRING(str)->len >= width) return str; + if (width < 0 || RSTRING(str)->len >= width) return str; res = str_new(0, width); p = RSTRING(res)->ptr; pend = p + width - RSTRING(str)->len; while (p < pend) { @@ -2569,7 +2569,7 @@ str_center(str, w) UCHAR *p, *pend; int n; - if (RSTRING(str)->len >= width) return str; + if (width < 0 || RSTRING(str)->len >= width) return str; res = str_new(0, width); n = (width - RSTRING(str)->len)/2; p = RSTRING(res)->ptr; pend = p + n; -- cgit v1.2.3