diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 3127a36bde..90f48333b2 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -195,38 +195,41 @@ char *estack_sfile(estack_arg_T which) for (int idx = 0; idx < exestack.ga_len; idx++) { entry = ((estack_T *)exestack.ga_data) + idx; if (entry->es_name != NULL) { - char *type_name = ""; + String type_name = STATIC_CSTR_AS_STRING(""); + String es_name = cstr_as_string(entry->es_name); if (entry->es_type != last_type) { switch (entry->es_type) { case ETYPE_SCRIPT: - type_name = "script "; break; + type_name = STATIC_CSTR_AS_STRING("script "); break; case ETYPE_UFUNC: - type_name = "function "; break; + type_name = STATIC_CSTR_AS_STRING("function "); break; default: - type_name = ""; break; + break; } last_type = entry->es_type; } linenr_T lnum = idx == exestack.ga_len - 1 ? which == ESTACK_STACK ? SOURCING_LNUM : 0 : entry->es_lnum; - size_t len = strlen(entry->es_name) + strlen(type_name) + 26; + + size_t len = es_name.size + type_name.size + 26; ga_grow(&ga, (int)len); - ga_concat(&ga, type_name); - ga_concat(&ga, entry->es_name); + ga_concat_len(&ga, type_name.data, type_name.size); + ga_concat_len(&ga, es_name.data, es_name.size); // For the bottom entry of : do not add the line number, it is used in // . Also leave it out when the number is not set. if (lnum != 0) { - ga.ga_len += vim_snprintf((char *)ga.ga_data + ga.ga_len, 23, - "[%" PRIdLINENR "]", lnum); + ga.ga_len += (int)vim_snprintf_safelen((char *)ga.ga_data + ga.ga_len, + len - (size_t)ga.ga_len, + "[%" PRIdLINENR "]", lnum); } if (idx != exestack.ga_len - 1) { - ga_concat(&ga, ".."); + ga_concat_len(&ga, S_LEN("..")); } } } - ga_append(&ga, '\0'); + ga_append(&ga, NUL); return (char *)ga.ga_data; }