diff src/if_ruby.c @ 2990:ad404f2a4bfa v7.3.267

updated for version 7.3.267 Problem: Ruby on Mac OS X 10.7 may crash. Solution: Avoid alloc(0). (Bjorn Winckler)
author Bram Moolenaar <bram@vim.org>
date Thu, 04 Aug 2011 19:34:59 +0200
parents 0c7d6d01e058
children d7b335626ddc
line wrap: on
line diff
--- a/src/if_ruby.c
+++ b/src/if_ruby.c
@@ -761,11 +761,19 @@ static VALUE vim_message(VALUE self UNUS
     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)
+    {
+	/* Only do this when the string isn't empty, alloc(0) causes trouble. */
+	buff = ALLOCA_N(char, RSTRING_LEN(str));
+	strcpy(buff, RSTRING_PTR(str));
+	p = strchr(buff, '\n');
+	if (p) *p = '\0';
+	MSG(buff);
+    }
+    else
+    {
+	MSG("");
+    }
     return Qnil;
 }