summaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-16 05:55:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-16 05:55:22 +0000
commitfc4531d7fbccbdd382e329c4a73e245a25faac18 (patch)
tree5c858bef621fa3e0276b617d9c3d8b1071298a9c /file.c
parent46ec5a03ac8268bc57732369b8607c2c7c31f7cf (diff)
downloadruby-fc4531d7fbccbdd382e329c4a73e245a25faac18.tar.gz
ruby-fc4531d7fbccbdd382e329c4a73e245a25faac18.tar.xz
ruby-fc4531d7fbccbdd382e329c4a73e245a25faac18.zip
* file.c (sys_fail2): get rid of unlimited alloca.
* io.c (mode_enc, pipe_open, rb_io_s_popen): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/file.c b/file.c
index 452f7ff18..18caf6b8a 100644
--- a/file.c
+++ b/file.c
@@ -2151,11 +2151,31 @@ static void
sys_fail2(VALUE s1, VALUE s2)
{
char *buf;
- int len;
+#ifdef MAX_PATH
+ const int max_pathlen = MAX_PATH;
+#else
+ const int max_pathlen = MAXPATHLEN;
+#endif
+ const char *e1, *e2;
+ int len = 5;
+ int l1 = RSTRING_LEN(s1), l2 = RSTRING_LEN(s2);
- len = RSTRING_LEN(s1) + RSTRING_LEN(s2) + 5;
+ e1 = e2 = "";
+ if (l1 > max_pathlen) {
+ l1 = max_pathlen - 3;
+ e1 = "...";
+ len += 3;
+ }
+ if (l2 > max_pathlen) {
+ l2 = max_pathlen - 3;
+ e2 = "...";
+ len += 3;
+ }
+ len += l1 + l2;
buf = ALLOCA_N(char, len);
- snprintf(buf, len, "(%s, %s)", RSTRING_PTR(s1), RSTRING_PTR(s2));
+ snprintf(buf, len, "(%.*s%s, %.*s%s)",
+ l1, RSTRING_PTR(s1), e1,
+ l2, RSTRING_PTR(s2), e2);
rb_sys_fail(buf);
}