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

Rename some variables in the process, and remove two cluttering asserts.
master
Benno Schulenberg 2017-03-30 20:57:28 +02:00
parent 7e18100197
commit 53cea142e0
3 changed files with 12 additions and 21 deletions

View File

@ -1812,7 +1812,7 @@ int do_mouse(void)
* TRUE. */
void do_output(char *output, size_t output_len, bool allow_cntrls)
{
char *char_buf = charalloc(mb_cur_max());
char onechar[mb_cur_max()];
int char_len;
size_t current_len = strlen(openfile->current->data);
size_t i = 0;
@ -1832,7 +1832,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
output[i] = '\n';
/* Get the next multibyte character. */
char_len = parse_mbchar(output + i, char_buf, NULL);
char_len = parse_mbchar(output + i, onechar, NULL);
i += char_len;
@ -1853,7 +1853,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
charmove(openfile->current->data + openfile->current_x + char_len,
openfile->current->data + openfile->current_x,
current_len - openfile->current_x + 1);
strncpy(openfile->current->data + openfile->current_x, char_buf,
strncpy(openfile->current->data + openfile->current_x, onechar,
char_len);
current_len += char_len;
openfile->totsize++;
@ -1893,8 +1893,6 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
refresh_needed = TRUE;
#endif
free(char_buf);
openfile->placewewant = xplustabs();
#ifndef DISABLE_COLOR

View File

@ -197,7 +197,7 @@ void do_statusbar_output(int *the_input, size_t input_len,
bool filtering)
{
char *output = charalloc(input_len + 1);
char *char_buf = charalloc(mb_cur_max());
char onechar[mb_cur_max()];
int i, char_len;
/* Copy the typed stuff so it can be treated. */
@ -213,7 +213,7 @@ void do_statusbar_output(int *the_input, size_t input_len,
output[i] = '\n';
/* Interpret the next multibyte character. */
char_len = parse_mbchar(output + i, char_buf, NULL);
char_len = parse_mbchar(output + i, onechar, NULL);
i += char_len;
@ -225,12 +225,11 @@ void do_statusbar_output(int *the_input, size_t input_len,
answer = charealloc(answer, strlen(answer) + char_len + 1);
charmove(answer + statusbar_x + char_len, answer + statusbar_x,
strlen(answer) - statusbar_x + 1);
strncpy(answer + statusbar_x, char_buf, char_len);
strncpy(answer + statusbar_x, onechar, char_len);
statusbar_x += char_len;
}
free(char_buf);
free(output);
update_the_statusbar();

View File

@ -1682,25 +1682,19 @@ ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl)
size_t indent_length(const char *line)
{
size_t len = 0;
char *blank_mb;
int blank_mb_len;
assert(line != NULL);
blank_mb = charalloc(mb_cur_max());
char onechar[mb_cur_max()];
int charlen;
while (*line != '\0') {
blank_mb_len = parse_mbchar(line, blank_mb, NULL);
charlen = parse_mbchar(line, onechar, NULL);
if (!is_blank_mbchar(blank_mb))
if (!is_blank_mbchar(onechar))
break;
line += blank_mb_len;
len += blank_mb_len;
line += charlen;
len += charlen;
}
free(blank_mb);
return len;
}
#endif /* !NANO_TINY || !DISABLE_JUSTIFY */