Commit 0099a8f4 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

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-d3aeb78583b8
parent 38156d44
Showing with 12 additions and 15 deletions
+12 -15
...@@ -213,7 +213,7 @@ char *control_mbrep(const char *c, char *crep, int *crep_len) ...@@ -213,7 +213,7 @@ char *control_mbrep(const char *c, char *crep, int *crep_len)
} else { } else {
#endif #endif
*crep_len = 1; *crep_len = 1;
crep[0] = control_rep((unsigned char)*c); *crep = control_rep((unsigned char)*c);
return crep; return crep;
#ifdef NANO_WIDE #ifdef NANO_WIDE
...@@ -276,10 +276,10 @@ int mb_cur_max(void) ...@@ -276,10 +276,10 @@ int mb_cur_max(void)
* multibyte character and its length. */ * multibyte character and its length. */
char *make_mbchar(int chr, int *chr_mb_len) char *make_mbchar(int chr, int *chr_mb_len)
{ {
assert(chr_mb != NULL && chr_mb_len != NULL);
char *chr_mb; char *chr_mb;
assert(chr_mb != NULL && chr_mb_len != NULL);
#ifdef NANO_WIDE #ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) { if (!ISSET(NO_UTF8)) {
chr_mb = charalloc(MB_CUR_MAX); chr_mb = charalloc(MB_CUR_MAX);
...@@ -293,7 +293,7 @@ char *make_mbchar(int chr, int *chr_mb_len) ...@@ -293,7 +293,7 @@ char *make_mbchar(int chr, int *chr_mb_len)
#endif #endif
*chr_mb_len = 1; *chr_mb_len = 1;
chr_mb = charalloc(1); chr_mb = charalloc(1);
chr_mb[0] = (char)chr; *chr_mb = (char)chr;
#ifdef NANO_WIDE #ifdef NANO_WIDE
} }
#endif #endif
...@@ -305,17 +305,15 @@ char *make_mbchar(int chr, int *chr_mb_len) ...@@ -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 /* Convert the string str to a valid multibyte string with the same wide
* character values as str. Return the (dynamically allocated) * character values as str. Return the (dynamically allocated)
* multibyte string. */ * multibyte string. */
char *make_mbstring(char *str) char *make_mbstring(const char *str)
{ {
assert(str != NULL); assert(str != NULL);
char *str_mb;
#ifdef NANO_WIDE #ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) { if (!ISSET(NO_UTF8)) {
char *chr_mb = charalloc(MB_CUR_MAX); char *chr_mb = charalloc(MB_CUR_MAX);
int chr_mb_len; 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; size_t str_mb_len = 0;
while (*str != '\0') { while (*str != '\0') {
...@@ -328,7 +326,7 @@ char *make_mbstring(char *str) ...@@ -328,7 +326,7 @@ char *make_mbstring(char *str)
char *bad_chr_mb; char *bad_chr_mb;
int bad_chr_mb_len; 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); &bad_chr_mb_len);
for (i = 0; i < bad_chr_mb_len; i++) for (i = 0; i < bad_chr_mb_len; i++)
...@@ -351,7 +349,7 @@ char *make_mbstring(char *str) ...@@ -351,7 +349,7 @@ char *make_mbstring(char *str)
return str_mb; return str_mb;
} else } else
#endif #endif
return mallocstrcpy(str_mb, str); return mallocstrcpy(NULL, str);
} }
#endif #endif
......
...@@ -176,7 +176,7 @@ int mbwidth(const char *c); ...@@ -176,7 +176,7 @@ int mbwidth(const char *c);
int mb_cur_max(void); int mb_cur_max(void);
char *make_mbchar(int chr, int *chr_mb_len); char *make_mbchar(int chr, int *chr_mb_len);
#ifdef ENABLE_NANORC #ifdef ENABLE_NANORC
char *make_mbstring(char *str); char *make_mbstring(const char *str);
#endif #endif
int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t
*col); *col);
......
...@@ -4051,9 +4051,6 @@ void do_credits(void) ...@@ -4051,9 +4051,6 @@ void do_credits(void)
"David Benbennick", "David Benbennick",
"Ken Tyler", "Ken Tyler",
"Sven Guckes", "Sven Guckes",
#ifdef NANO_WIDE
!ISSET(NO_UTF8) ? "Florian König" :
#endif
"Florian König", "Florian König",
"Pauli Virtanen", "Pauli Virtanen",
"Daniele Medri", "Daniele Medri",
...@@ -4121,6 +4118,7 @@ void do_credits(void) ...@@ -4121,6 +4118,7 @@ void do_credits(void)
for (crpos = 0; crpos < CREDIT_LEN + editwinrows / 2; crpos++) { for (crpos = 0; crpos < CREDIT_LEN + editwinrows / 2; crpos++) {
if (wgetch(edit) != ERR) if (wgetch(edit) != ERR)
break; break;
if (crpos < CREDIT_LEN) { if (crpos < CREDIT_LEN) {
const char *what = credits[crpos]; const char *what = credits[crpos];
size_t start_x; size_t start_x;
...@@ -4134,6 +4132,7 @@ void do_credits(void) ...@@ -4134,6 +4132,7 @@ void do_credits(void)
mvwaddstr(edit, editwinrows - 1 - editwinrows % 2, start_x, mvwaddstr(edit, editwinrows - 1 - editwinrows % 2, start_x,
what); what);
} }
napms(700); napms(700);
scroll(edit); scroll(edit);
wrefresh(edit); wrefresh(edit);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment