Skip to content

Commit

Permalink
zero-terminate empty-conversion (closes comotion#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
comotion committed Apr 26, 2012
1 parent daf9672 commit 778be1c
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions interface_utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ char* convert(int direction, char* instring)

if (!instring)
return NULL;
if (!encodingHandler || !encodingHandler->output)
return instring; // NULL handler, return instring

if (convertbuffer)
{
Expand All @@ -71,8 +73,10 @@ char* convert(int direction, char* instring)
outsize = insize * 2 - 1;
convertbuffer = memAlloc(__FILE__, __LINE__, outsize);
// (xml)encodingHandler doesn't handle empty strings
if(insize == 1)
if(insize == 1){
convertbuffer[0] = '\0';
return convertbuffer;
}

tmp = insize - 1;
if (direction)
Expand Down Expand Up @@ -108,9 +112,7 @@ char* convert(int direction, char* instring)

/* #############################################################################
*
* Description convert the given string to the terminal display type (latin1)
* Author Harry Brueckner
* Date 2005-07-01
* Description convert the given string to the terminal display type
* Arguments char* instring - string to convert
* Return converted string
*/
Expand Down Expand Up @@ -183,13 +185,22 @@ int initUTF8Encoding(char* encoding)
/* we first try to find the encode by it's name */
encoder = xmlParseCharEncoding(encoding);
if (encoder <= 0)
{ return 0; }
{fprintf(stderr,"parse char\n"); return 0; }

/* and then load it by using it's id */
encodingHandler = xmlGetCharEncodingHandler(encoder);

if (!encodingHandler)
{ return 0; }
if (!encodingHandler) {
switch(encoder) {
case XML_CHAR_ENCODING_NONE:
case XML_CHAR_ENCODING_UTF8:
// null handler, no encoder.
return 1;
default:
fprintf(stderr,"Failed to init character handler.\n");
return 0;
}
}

tmp = convert(0, TSTRING);
if (tmp)
Expand Down

0 comments on commit 778be1c

Please sign in to comment.