fix potential memory corruption problem in make_mbstring(), and also fix
compilation with -pedantic git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2372 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
38156d4491
commit
0099a8f45c
18
src/chars.c
18
src/chars.c
|
@ -213,7 +213,7 @@ char *control_mbrep(const char *c, char *crep, int *crep_len)
|
|||
} else {
|
||||
#endif
|
||||
*crep_len = 1;
|
||||
crep[0] = control_rep((unsigned char)*c);
|
||||
*crep = control_rep((unsigned char)*c);
|
||||
|
||||
return crep;
|
||||
#ifdef NANO_WIDE
|
||||
|
@ -276,10 +276,10 @@ int mb_cur_max(void)
|
|||
* multibyte character and its length. */
|
||||
char *make_mbchar(int chr, int *chr_mb_len)
|
||||
{
|
||||
assert(chr_mb != NULL && chr_mb_len != NULL);
|
||||
|
||||
char *chr_mb;
|
||||
|
||||
assert(chr_mb != NULL && chr_mb_len != NULL);
|
||||
|
||||
#ifdef NANO_WIDE
|
||||
if (!ISSET(NO_UTF8)) {
|
||||
chr_mb = charalloc(MB_CUR_MAX);
|
||||
|
@ -293,7 +293,7 @@ char *make_mbchar(int chr, int *chr_mb_len)
|
|||
#endif
|
||||
*chr_mb_len = 1;
|
||||
chr_mb = charalloc(1);
|
||||
chr_mb[0] = (char)chr;
|
||||
*chr_mb = (char)chr;
|
||||
#ifdef NANO_WIDE
|
||||
}
|
||||
#endif
|
||||
|
@ -305,17 +305,15 @@ char *make_mbchar(int chr, int *chr_mb_len)
|
|||
/* Convert the string str to a valid multibyte string with the same wide
|
||||
* character values as str. Return the (dynamically allocated)
|
||||
* multibyte string. */
|
||||
char *make_mbstring(char *str)
|
||||
char *make_mbstring(const char *str)
|
||||
{
|
||||
assert(str != NULL);
|
||||
|
||||
char *str_mb;
|
||||
|
||||
#ifdef NANO_WIDE
|
||||
if (!ISSET(NO_UTF8)) {
|
||||
char *chr_mb = charalloc(MB_CUR_MAX);
|
||||
int chr_mb_len;
|
||||
str_mb = charalloc((MB_CUR_MAX * strlen(str)) + 1);
|
||||
char *str_mb = charalloc((MB_CUR_MAX * strlen(str)) + 1);
|
||||
size_t str_mb_len = 0;
|
||||
|
||||
while (*str != '\0') {
|
||||
|
@ -328,7 +326,7 @@ char *make_mbstring(char *str)
|
|||
char *bad_chr_mb;
|
||||
int bad_chr_mb_len;
|
||||
|
||||
bad_chr_mb = make_mbchar((unsigned char)chr_mb[0],
|
||||
bad_chr_mb = make_mbchar((unsigned char)*chr_mb,
|
||||
&bad_chr_mb_len);
|
||||
|
||||
for (i = 0; i < bad_chr_mb_len; i++)
|
||||
|
@ -351,7 +349,7 @@ char *make_mbstring(char *str)
|
|||
return str_mb;
|
||||
} else
|
||||
#endif
|
||||
return mallocstrcpy(str_mb, str);
|
||||
return mallocstrcpy(NULL, str);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ int mbwidth(const char *c);
|
|||
int mb_cur_max(void);
|
||||
char *make_mbchar(int chr, int *chr_mb_len);
|
||||
#ifdef ENABLE_NANORC
|
||||
char *make_mbstring(char *str);
|
||||
char *make_mbstring(const char *str);
|
||||
#endif
|
||||
int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t
|
||||
*col);
|
||||
|
|
|
@ -4051,10 +4051,7 @@ void do_credits(void)
|
|||
"David Benbennick",
|
||||
"Ken Tyler",
|
||||
"Sven Guckes",
|
||||
#ifdef NANO_WIDE
|
||||
!ISSET(NO_UTF8) ? "Florian König" :
|
||||
#endif
|
||||
"Florian König",
|
||||
"Florian König",
|
||||
"Pauli Virtanen",
|
||||
"Daniele Medri",
|
||||
"Clement Laforet",
|
||||
|
@ -4121,6 +4118,7 @@ void do_credits(void)
|
|||
for (crpos = 0; crpos < CREDIT_LEN + editwinrows / 2; crpos++) {
|
||||
if (wgetch(edit) != ERR)
|
||||
break;
|
||||
|
||||
if (crpos < CREDIT_LEN) {
|
||||
const char *what = credits[crpos];
|
||||
size_t start_x;
|
||||
|
@ -4134,6 +4132,7 @@ void do_credits(void)
|
|||
mvwaddstr(edit, editwinrows - 1 - editwinrows % 2, start_x,
|
||||
what);
|
||||
}
|
||||
|
||||
napms(700);
|
||||
scroll(edit);
|
||||
wrefresh(edit);
|
||||
|
|
Loading…
Reference in New Issue