nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 8db21b68d55806bc302370058903222c2bab7600
parent cb31e45f6c1e411f93c29af5776b8e7f1ac45568
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Mon, 26 Dec 2016 10:27:42 +0100

tweaks: use memory on the stack instead of calling malloc() and free()

Diffstat:
Msrc/files.c | 6+-----
Msrc/utils.c | 12+++---------
2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -2713,8 +2713,7 @@ char *input_tab(char *buf, bool allow_files, size_t *place, char *mzero, *glued; const char *lastslash = revstrstr(buf, "/", buf + *place); size_t lastslash_len = (lastslash == NULL) ? 0 : lastslash - buf + 1; - char *match1 = charalloc(mb_cur_max()); - char *match2 = charalloc(mb_cur_max()); + char match1[mb_cur_max()], match2[mb_cur_max()]; int match1_len, match2_len; /* Get the number of characters that all matches have in common. */ @@ -2735,9 +2734,6 @@ char *input_tab(char *buf, bool allow_files, size_t *place, common_len += match1_len; } - free(match1); - free(match2); - mzero = charalloc(lastslash_len + common_len + 1); strncpy(mzero, buf, lastslash_len); diff --git a/src/utils.c b/src/utils.c @@ -303,9 +303,8 @@ const char *fixbounds(const char *r) * a separate word? That is: is it not part of a longer word?*/ bool is_separate_word(size_t position, size_t length, const char *buf) { - char *before = charalloc(mb_cur_max()), *after = charalloc(mb_cur_max()); + char before[mb_cur_max()], after[mb_cur_max()]; size_t word_end = position + length; - bool retval; /* Get the characters before and after the word, if any. */ parse_mbchar(buf + move_mbleft(buf, position), before, NULL); @@ -314,13 +313,8 @@ bool is_separate_word(size_t position, size_t length, const char *buf) /* If the word starts at the beginning of the line OR the character before * the word isn't a letter, and if the word ends at the end of the line OR * the character after the word isn't a letter, we have a whole word. */ - retval = (position == 0 || !is_alpha_mbchar(before)) && - (word_end == strlen(buf) || !is_alpha_mbchar(after)); - - free(before); - free(after); - - return retval; + return ((position == 0 || !is_alpha_mbchar(before)) && + (buf[word_end] == '\0' || !is_alpha_mbchar(after))); } #endif /* !DISABLE_SPELLER */