From 6bd19ecf62718706171d8c064485dafbee7a3cf1 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Thu, 21 Jul 2011 21:57:33 +0200 Subject: [PATCH] Emergency fix for Ruby problems With optimizations enabled "alloca(len)" generates code which depends on "len > 0". If "len == 0" then the stack pointer becomes botched. This fix simply avoids a call to "alloca(len)" in the latter case. The root of this problem may be deeper than this, hence I am calling this an "emergency fix" for now but at least it fixes the crashes in the Ruby interface that appear when compiling on Mac OS X 10.7. --- src/if_ruby.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/if_ruby.c b/src/if_ruby.c index d5b39cc6c9..6524077714 100644 --- a/src/if_ruby.c +++ b/src/if_ruby.c @@ -765,11 +765,14 @@ static VALUE vim_message(VALUE self UNUSED, VALUE str) char *buff, *p; str = rb_obj_as_string(str); - buff = ALLOCA_N(char, RSTRING_LEN(str)); - strcpy(buff, RSTRING_PTR(str)); - p = strchr(buff, '\n'); - if (p) *p = '\0'; - MSG(buff); + if (RSTRING_LEN(str) > 0) + { + buff = ALLOCA_N(char, RSTRING_LEN(str)); + strcpy(buff, RSTRING_PTR(str)); + p = strchr(buff, '\n'); + if (p) *p = '\0'; + MSG(buff); + } return Qnil; }