Make Unicode strings safe for ncurses 6 ABI.

Closes #241.
This commit is contained in:
Hisham Muhammad 2015-08-20 00:31:48 -03:00
parent 78be8201dc
commit 8bd603cb68
3 changed files with 10 additions and 7 deletions

View File

@ -32,8 +32,8 @@ in the source distribution for its full text.
#define RichString_size(this) ((this)->chlen) #define RichString_size(this) ((this)->chlen)
#define RichString_sizeVal(this) ((this).chlen) #define RichString_sizeVal(this) ((this).chlen)
#define RichString_begin(this) RichString (this); (this).chlen = 0; (this).chptr = (this).chstr; #define RichString_begin(this) RichString (this); memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr;
#define RichString_beginAllocated(this) (this).chlen = 0; (this).chptr = (this).chstr; #define RichString_beginAllocated(this) memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr;
#define RichString_end(this) RichString_prune(&(this)); #define RichString_end(this) RichString_prune(&(this));
#ifdef HAVE_LIBNCURSESW #ifdef HAVE_LIBNCURSESW
@ -79,6 +79,7 @@ static void RichString_extendLen(RichString* this, int len) {
this->chptr = realloc(this->chptr, charBytes(len+1)); this->chptr = realloc(this->chptr, charBytes(len+1));
} }
} }
RichString_setChar(this, len, 0); RichString_setChar(this, len, 0);
this->chlen = len; this->chlen = len;
} }
@ -155,9 +156,8 @@ int RichString_findChar(RichString* this, char c, int start) {
void RichString_prune(RichString* this) { void RichString_prune(RichString* this) {
if (this->chlen > RICHSTRING_MAXLEN) if (this->chlen > RICHSTRING_MAXLEN)
free(this->chptr); free(this->chptr);
memset(this, 0, sizeof(RichString));
this->chptr = this->chstr; this->chptr = this->chstr;
this->chlen = 0;
RichString_setChar(this, 0, 0);
} }
void RichString_setAttr(RichString* this, int attrs) { void RichString_setAttr(RichString* this, int attrs) {

View File

@ -30,8 +30,8 @@ in the source distribution for its full text.
#define RichString_size(this) ((this)->chlen) #define RichString_size(this) ((this)->chlen)
#define RichString_sizeVal(this) ((this).chlen) #define RichString_sizeVal(this) ((this).chlen)
#define RichString_begin(this) RichString (this); (this).chlen = 0; (this).chptr = (this).chstr; #define RichString_begin(this) RichString (this); memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr;
#define RichString_beginAllocated(this) (this).chlen = 0; (this).chptr = (this).chstr; #define RichString_beginAllocated(this) memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr;
#define RichString_end(this) RichString_prune(&(this)); #define RichString_end(this) RichString_prune(&(this));
#ifdef HAVE_LIBNCURSESW #ifdef HAVE_LIBNCURSESW

View File

@ -143,7 +143,10 @@ fi
AC_ARG_ENABLE(unicode, [AC_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes") AC_ARG_ENABLE(unicode, [AC_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes")
if test "x$enable_unicode" = xyes; then if test "x$enable_unicode" = xyes; then
AC_CHECK_LIB([ncursesw6], [refresh], [], [ AC_CHECK_LIB([ncursesw6], [refresh], [
AC_DEFINE(HAVE_LIBNCURSESW, 1, [])
LIBS="-lncursesw6 $LIBS "
], [
AC_CHECK_LIB([ncursesw], [refresh], [], [ AC_CHECK_LIB([ncursesw], [refresh], [], [
missing_libraries="$missing_libraries libncursesw" missing_libraries="$missing_libraries libncursesw"
AC_MSG_ERROR([You may want to use --disable-unicode or install libncursesw.]) AC_MSG_ERROR([You may want to use --disable-unicode or install libncursesw.])