diff --git a/ChangeLog b/ChangeLog index 763a5716a531859566558de61bc96a91ff75550e..8dcf232538d90451be6d4b9024559a18657fa987 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2016-01-04 Benno Schulenberg <bensberg@justemail.net> * src/global.c (shortcut_init): Nowadays the functions are defined only once, so there is no longer any need to free existing ones. + * src/global.c (sctofunc): Rewrite the loop, and constify the input. 2016-01-04 Mike Frysinger <vapier@gentoo.org> * src/global.c (strtosc, strtomenu): Constify the input parameter. diff --git a/src/global.c b/src/global.c index 4a41659abb799f601e898f0abd7c0cc08d2a2f90..e4a13280c0fb13d1ff5311e13143d90963d8369c 100644 --- a/src/global.c +++ b/src/global.c @@ -1260,12 +1260,12 @@ void set_spell_shortcuts(void) } #endif -const subnfunc *sctofunc(sc *s) +const subnfunc *sctofunc(const sc *s) { - subnfunc *f; + subnfunc *f = allfuncs; - for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next) - ; + while (f != NULL && f->scfunc != s->scfunc) + f = f->next; return f; } diff --git a/src/nano.c b/src/nano.c index 3007f6c75b2efaf6e02ab338d920f80f4d950f2f..d4366b93112604fc79f51b8c262e0eae3669a6ea 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1702,7 +1702,7 @@ int do_input(bool allow_funcs) } if (have_shortcut) { - const subnfunc *f = sctofunc((sc *)s); + const subnfunc *f = sctofunc(s); /* If the function associated with this shortcut is * cutting or copying text, remember this. */ if (s->scfunc == do_cut_text_void diff --git a/src/prompt.c b/src/prompt.c index 448ff7f6ba7e8680628aff1a4b68c9341f6a70e4..dbe84546ee3251cdf76d7a3c6b6549109d5f7c0f 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -210,7 +210,7 @@ int do_statusbar_input(bool *ran_func, bool *finished, * functions and setting finished to TRUE to indicate * that we're done after running or trying to run their * associated functions. */ - f = sctofunc((sc *) s); + f = sctofunc(s); if (s->scfunc != NULL) { *ran_func = TRUE; if (f && (!ISSET(VIEW_MODE) || f->viewok) && diff --git a/src/proto.h b/src/proto.h index 07e5eefef2541ab48db3154ee9268babfb19811c..74280edd09ab74258199921290819df876c426e4 100644 --- a/src/proto.h +++ b/src/proto.h @@ -370,7 +370,7 @@ void shortcut_init(void); void set_lint_or_format_shortcuts(void); void set_spell_shortcuts(void); #endif -const subnfunc *sctofunc(sc *s); +const subnfunc *sctofunc(const sc *s); const char *flagtostr(int flag); sc *strtosc(const char *input); int strtomenu(const char *input);