]> granicus.if.org Git - vim/commitdiff
patch 9.0.1037: lalloc(0) error for a class without members v9.0.1037
authorBram Moolenaar <Bram@vim.org>
Thu, 8 Dec 2022 22:09:14 +0000 (22:09 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 8 Dec 2022 22:09:14 +0000 (22:09 +0000)
Problem:    lalloc(0) error for a class without members.
Solution:   Don't allocate room for members if there aren't any.
            Don't create the class if there was an error.

src/version.c
src/vim9class.c

index 9c162fbbbdebdad49d5e5b5cfc43d13b045c9d44..a39bdba2ec5c5eedfee47c88b4c3bcbf2361779f 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1037,
 /**/
     1036,
 /**/
index 864a2e00b937f7f7612f67cfd9484c641c0a36c3..c2a17e12796e3b10c1a1d8ed83f36a4124697529 100644 (file)
@@ -121,8 +121,8 @@ ex_class(exarg_T *eap)
                semsg(_(e_command_cannot_be_shortened_str), line);
            else if (*p == '|' || !ends_excmd2(line, p))
                semsg(_(e_trailing_characters_str), p);
-
-           success = TRUE;
+           else
+               success = TRUE;
            break;
        }
 
@@ -190,9 +190,10 @@ ex_class(exarg_T *eap)
 
        // Members are used by the new() function, add them here.
        cl->class_obj_member_count = objmembers.ga_len;
-       cl->class_obj_members = ALLOC_MULT(objmember_T, objmembers.ga_len);
+       cl->class_obj_members = objmembers.ga_len == 0 ? NULL
+                                 : ALLOC_MULT(objmember_T, objmembers.ga_len);
        if (cl->class_name == NULL
-               || cl->class_obj_members == NULL)
+               || (objmembers.ga_len > 0 && cl->class_obj_members == NULL))
        {
            vim_free(cl->class_name);
            vim_free(cl->class_obj_members);