diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-16 05:55:22 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-16 05:55:22 +0000 |
commit | 2402ecabb064525651667374a0f758321bbc7f65 (patch) | |
tree | 5c858bef621fa3e0276b617d9c3d8b1071298a9c /file.c | |
parent | ce2652c9d46acd102d80fe645000ad31dc45ebbb (diff) | |
download | ruby-2402ecabb064525651667374a0f758321bbc7f65.tar.gz |
* 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.c | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -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); } |