tweaks: use memory on the stack instead of calling malloc() and free()
parent
cb31e45f6c
commit
8db21b68d5
|
@ -2713,8 +2713,7 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
|
||||||
char *mzero, *glued;
|
char *mzero, *glued;
|
||||||
const char *lastslash = revstrstr(buf, "/", buf + *place);
|
const char *lastslash = revstrstr(buf, "/", buf + *place);
|
||||||
size_t lastslash_len = (lastslash == NULL) ? 0 : lastslash - buf + 1;
|
size_t lastslash_len = (lastslash == NULL) ? 0 : lastslash - buf + 1;
|
||||||
char *match1 = charalloc(mb_cur_max());
|
char match1[mb_cur_max()], match2[mb_cur_max()];
|
||||||
char *match2 = charalloc(mb_cur_max());
|
|
||||||
int match1_len, match2_len;
|
int match1_len, match2_len;
|
||||||
|
|
||||||
/* Get the number of characters that all matches have in common. */
|
/* 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;
|
common_len += match1_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(match1);
|
|
||||||
free(match2);
|
|
||||||
|
|
||||||
mzero = charalloc(lastslash_len + common_len + 1);
|
mzero = charalloc(lastslash_len + common_len + 1);
|
||||||
|
|
||||||
strncpy(mzero, buf, lastslash_len);
|
strncpy(mzero, buf, lastslash_len);
|
||||||
|
|
12
src/utils.c
12
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?*/
|
* 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)
|
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;
|
size_t word_end = position + length;
|
||||||
bool retval;
|
|
||||||
|
|
||||||
/* Get the characters before and after the word, if any. */
|
/* Get the characters before and after the word, if any. */
|
||||||
parse_mbchar(buf + move_mbleft(buf, position), before, NULL);
|
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
|
/* 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 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. */
|
* the character after the word isn't a letter, we have a whole word. */
|
||||||
retval = (position == 0 || !is_alpha_mbchar(before)) &&
|
return ((position == 0 || !is_alpha_mbchar(before)) &&
|
||||||
(word_end == strlen(buf) || !is_alpha_mbchar(after));
|
(buf[word_end] == '\0' || !is_alpha_mbchar(after)));
|
||||||
|
|
||||||
free(before);
|
|
||||||
free(after);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
#endif /* !DISABLE_SPELLER */
|
#endif /* !DISABLE_SPELLER */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue