fix valgrind-flagged errors

This commit is contained in:
Eric House 2018-04-14 09:13:43 -07:00
parent fecbfdddb6
commit 3bb6f842b2
2 changed files with 19 additions and 14 deletions

View file

@ -221,27 +221,28 @@ dict_splitFaces( DictionaryCtxt* dict, const XP_U8* utf8,
XP_U16 ii; XP_U16 ii;
XP_Bool isUTF8 = dict->isUTF8; XP_Bool isUTF8 = dict->isUTF8;
XP_UCHAR* next = faces; XP_UCHAR* next = faces;
const gchar* bytes = (const gchar*)utf8; const gchar* bytesIn = (const gchar*)utf8;
const gchar* bytesEnd = bytesIn + nBytes;
for ( ii = 0; ii < nFaces; ++ii ) { for ( ii = 0; ii < nFaces; ++ii ) {
ptrs[ii] = next; ptrs[ii] = next;
if ( isUTF8 ) { if ( isUTF8 ) {
for ( ; ; ) { for ( ; ; ) {
gchar* cp = g_utf8_offset_to_pointer( bytes, 1 ); gchar* cp = g_utf8_offset_to_pointer( bytesIn, 1 );
size_t len = cp - bytes; size_t len = cp - bytesIn;
XP_MEMCPY( next, bytes, len ); XP_MEMCPY( next, bytesIn, len );
next += len; next += len;
bytes += len; bytesIn += len;
if ( SYNONYM_DELIM != bytes[0] ) { if ( bytesIn >= bytesEnd || SYNONYM_DELIM != bytesIn[0] ) {
break; break;
} }
++bytes; /* skip delimiter */ ++bytesIn; /* skip delimiter */
*next++ = '\0'; *next++ = '\0';
} }
} else { } else {
XP_ASSERT( 0 == *bytes ); XP_ASSERT( 0 == *bytesIn );
++bytes; /* skip empty */ ++bytesIn; /* skip empty */
*next++ = *bytes++; *next++ = *bytesIn++;
} }
XP_ASSERT( next < faces + nFaces + nBytes ); XP_ASSERT( next < faces + nFaces + nBytes );
*next++ = '\0'; *next++ = '\0';

View file

@ -83,11 +83,15 @@ static int blocking_read( int fd, unsigned char* buf, const int len );
XP_Bool XP_Bool
file_exists( const char* fileName ) file_exists( const char* fileName )
{ {
XP_Bool exists = !!fileName;
if ( exists ) {
struct stat statBuf; struct stat statBuf;
int statResult = stat( fileName, &statBuf ); int statResult = stat( fileName, &statBuf );
// XP_LOGF( "%s(%s)=>%d", __func__, fileName, statResult == 0 ); // XP_LOGF( "%s(%s)=>%d", __func__, fileName, statResult == 0 );
return statResult == 0; exists = statResult == 0;
}
return exists;
} /* file_exists */ } /* file_exists */
XWStreamCtxt* XWStreamCtxt*