Mercurial > vim
comparison src/vim9class.c @ 31408:c82cb53474ee v9.0.1037
patch 9.0.1037: lalloc(0) error for a class without members
Commit: https://github.com/vim/vim/commit/98aeb2100c2759111f93f0f0857e93d98afdc88a
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 8 22:09:14 2022 +0000
patch 9.0.1037: lalloc(0) error for a class without members
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 08 Dec 2022 23:15:03 +0100 |
parents | 60b1d266548d |
children | f088f1d97eee |
comparison
equal
deleted
inserted
replaced
31407:9b7fe85ab47f | 31408:c82cb53474ee |
---|---|
119 { | 119 { |
120 if (STRNCMP(line, "endclass", 8) != 0) | 120 if (STRNCMP(line, "endclass", 8) != 0) |
121 semsg(_(e_command_cannot_be_shortened_str), line); | 121 semsg(_(e_command_cannot_be_shortened_str), line); |
122 else if (*p == '|' || !ends_excmd2(line, p)) | 122 else if (*p == '|' || !ends_excmd2(line, p)) |
123 semsg(_(e_trailing_characters_str), p); | 123 semsg(_(e_trailing_characters_str), p); |
124 | 124 else |
125 success = TRUE; | 125 success = TRUE; |
126 break; | 126 break; |
127 } | 127 } |
128 | 128 |
129 // "this.varname" | 129 // "this.varname" |
130 // "this._varname" | 130 // "this._varname" |
188 cl->class_refcount = 1; | 188 cl->class_refcount = 1; |
189 cl->class_name = vim_strnsave(arg, name_end - arg); | 189 cl->class_name = vim_strnsave(arg, name_end - arg); |
190 | 190 |
191 // Members are used by the new() function, add them here. | 191 // Members are used by the new() function, add them here. |
192 cl->class_obj_member_count = objmembers.ga_len; | 192 cl->class_obj_member_count = objmembers.ga_len; |
193 cl->class_obj_members = ALLOC_MULT(objmember_T, objmembers.ga_len); | 193 cl->class_obj_members = objmembers.ga_len == 0 ? NULL |
194 : ALLOC_MULT(objmember_T, objmembers.ga_len); | |
194 if (cl->class_name == NULL | 195 if (cl->class_name == NULL |
195 || cl->class_obj_members == NULL) | 196 || (objmembers.ga_len > 0 && cl->class_obj_members == NULL)) |
196 { | 197 { |
197 vim_free(cl->class_name); | 198 vim_free(cl->class_name); |
198 vim_free(cl->class_obj_members); | 199 vim_free(cl->class_obj_members); |
199 vim_free(cl); | 200 vim_free(cl); |
200 goto cleanup; | 201 goto cleanup; |