summaryrefslogtreecommitdiff
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
commit2402ecabb064525651667374a0f758321bbc7f65 (patch)
tree5c858bef621fa3e0276b617d9c3d8b1071298a9c /file.c
parentce2652c9d46acd102d80fe645000ad31dc45ebbb (diff)
* file.c (sys_fail2): get rid of unlimited alloca.
* io.c (mode_enc, pipe_open, rb_io_s_popen): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/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 452f7ff18f..18caf6b8a8 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);
}