Avoid crash with empty array
@@ -3972,7 +3972,10 @@ | ||
3972 | 3972 | } |
3973 | 3973 | |
3974 | 3974 | size_t save_count = pr->pending_heredocs.length; |
3975 | - void *save_heredocs[save_count]; | |
3975 | + size_t extended_count = save_count; | |
3976 | + if (extended_count == 0) | |
3977 | + extended_count = 1; // A variable-length array must not be empty. | |
3978 | + void *save_heredocs[extended_count]; | |
3976 | 3979 | memcpy(save_heredocs, pr->pending_heredocs.contents, sizeof save_heredocs); |
3977 | 3980 | pl_truncate(&pr->pending_heredocs, 0); |
3978 | 3981 |
@@ -2123,7 +2123,10 @@ | ||
2123 | 2123 | void array_remove_elements( |
2124 | 2124 | variable_T *array, size_t count, void *const *indexwcss) |
2125 | 2125 | { |
2126 | - long indices[count]; | |
2126 | + size_t extended_count = count; | |
2127 | + if (extended_count == 0) | |
2128 | + extended_count = 1; // A variable-length array must ot be empty. | |
2129 | + long indices[extended_count]; | |
2127 | 2130 | |
2128 | 2131 | assert((array->v_type & VF_MASK) == VF_ARRAY); |
2129 | 2132 |