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

master
Benno Schulenberg 2016-12-26 10:27:42 +01:00
parent cb31e45f6c
commit 8db21b68d5
2 changed files with 4 additions and 14 deletions

View File

@ -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);

View File

@ -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 */