tweaks: declare a function as const and let its allocated string leak

Avoiding this leak is more trouble than it's worth: invocation_error()
will be called seldomly, and when it is called, the user will probably
quickly exit from nano to fix things.

Also declare the speller functions as const again, so they don't give
the impression that their result can be freed.

Suggested-by: Brand Huntsman <alpha@qzx.com>
master
Benno Schulenberg 2019-04-23 11:48:10 +02:00
parent 34d22d3f00
commit fcad442d80
1 changed files with 7 additions and 10 deletions

View File

@ -60,8 +60,9 @@ void do_mark(void)
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
#if defined(ENABLE_COLOR) || defined(ENABLE_SPELLER) #if defined(ENABLE_COLOR) || defined(ENABLE_SPELLER)
/* Return an error message about invoking the given name. */ /* Return an error message about invoking the given name. The message
char *invocation_error(const char *name) * should not be freed; this leak is not worth the trouble avoiding. */
const char *invocation_error(const char *name)
{ {
char *message, *invoke_error = _("Error invoking \"%s\""); char *message, *invoke_error = _("Error invoking \"%s\"");
@ -2356,7 +2357,7 @@ bool fix_spello(const char *word)
/* Internal (integrated) spell checking using the spell program, /* Internal (integrated) spell checking using the spell program,
* filtered through the sort and uniq programs. Return NULL for normal * filtered through the sort and uniq programs. Return NULL for normal
* termination, and the error string otherwise. */ * termination, and the error string otherwise. */
char *do_int_speller(const char *tempfile_name) const char *do_int_speller(const char *tempfile_name)
{ {
char *misspellings, *pointer, *oneword; char *misspellings, *pointer, *oneword;
long pipesize; long pipesize;
@ -2548,7 +2549,7 @@ char *do_int_speller(const char *tempfile_name)
/* External (alternate) spell checking. Return NULL for normal /* External (alternate) spell checking. Return NULL for normal
* termination, and the error string otherwise. */ * termination, and the error string otherwise. */
char *do_alt_speller(char *tempfile_name) const char *do_alt_speller(char *tempfile_name)
{ {
int alt_spell_status; int alt_spell_status;
size_t current_x_save = openfile->current_x; size_t current_x_save = openfile->current_x;
@ -2651,7 +2652,7 @@ void do_spell(void)
char *temp; char *temp;
unsigned stash[sizeof(flags) / sizeof(flags[0])]; unsigned stash[sizeof(flags) / sizeof(flags[0])];
/* A storage place for the current flag settings. */ /* A storage place for the current flag settings. */
char *result_msg; const char *result_msg;
if (ISSET(RESTRICTED)) { if (ISSET(RESTRICTED)) {
show_restricted_warning(); show_restricted_warning();
@ -2705,7 +2706,6 @@ void do_spell(void)
else else
statusline(ALERT, _("Spell checking failed: %s: %s"), result_msg, statusline(ALERT, _("Spell checking failed: %s: %s"), result_msg,
strerror(errno)); strerror(errno));
/* Don't try to free the result message; see bug #56188. */
} else } else
statusbar(_("Finished checking spelling")); statusbar(_("Finished checking spelling"));
} }
@ -2891,10 +2891,7 @@ void do_linter(void)
waitpid(pid_lint, &lint_status, 0); waitpid(pid_lint, &lint_status, 0);
if (!WIFEXITED(lint_status) || WEXITSTATUS(lint_status) > 2) { if (!WIFEXITED(lint_status) || WEXITSTATUS(lint_status) > 2) {
char *result_msg= invocation_error(openfile->syntax->linter); statusbar(invocation_error(openfile->syntax->linter));
statusbar(result_msg);
free(result_msg);
return; return;
} }