mirror of git://git.sv.gnu.org/nano.git
fix potential memory corruption in display_string() when adding UTF-8
characters, found by valgrind (and caused by a bad merge of part of DB's code) git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2234 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
28e19f8bbc
commit
bbd63e136d
12
src/winio.c
12
src/winio.c
|
@ -2287,7 +2287,15 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
|
|||
assert(column <= start_col);
|
||||
|
||||
alloc_len = display_string_len(buf + start_index, start_col,
|
||||
start_col + len) + 2;
|
||||
start_col + len);
|
||||
alloc_len +=
|
||||
#ifdef NANO_WIDE
|
||||
MB_CUR_MAX
|
||||
#else
|
||||
1
|
||||
#endif
|
||||
* 2;
|
||||
|
||||
converted = charalloc(alloc_len + 1);
|
||||
index = 0;
|
||||
|
||||
|
@ -2464,8 +2472,6 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
|
|||
}
|
||||
|
||||
/* Make sure that converted is at most len columns wide. */
|
||||
converted[index] = '\0';
|
||||
index = actual_x(converted, len);
|
||||
null_at(&converted, index);
|
||||
|
||||
return converted;
|
||||
|
|
Loading…
Reference in New Issue