mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
Fix compile errors using latest gcc (fread etc must have return value checked)
This commit is contained in:
parent
552f6350f9
commit
863f79bfb9
4 changed files with 106 additions and 65 deletions
|
@ -376,7 +376,9 @@ curses_util_requestTime( XW_UtilCtxt* uc )
|
||||||
fds that my event loop polls so that I can write to it to simulate
|
fds that my event loop polls so that I can write to it to simulate
|
||||||
post-event on a more familiar system. It works, so no complaints! */
|
post-event on a more familiar system. It works, so no complaints! */
|
||||||
CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure;
|
CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure;
|
||||||
(void)write( globals->timepipe[1], "!", 1 );
|
if ( 1 != write( globals->timepipe[1], "!", 1 ) ) {
|
||||||
|
XP_ASSERT(0);
|
||||||
|
}
|
||||||
} /* curses_util_requestTime */
|
} /* curses_util_requestTime */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -947,7 +949,9 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch )
|
||||||
if ( (globals->fdArray[FD_TIMEEVT].revents & POLLIN) != 0 ) {
|
if ( (globals->fdArray[FD_TIMEEVT].revents & POLLIN) != 0 ) {
|
||||||
char ch;
|
char ch;
|
||||||
/* XP_DEBUGF( "curses got a USER EVENT\n" ); */
|
/* XP_DEBUGF( "curses got a USER EVENT\n" ); */
|
||||||
(void)read(globals->fdArray[FD_TIMEEVT].fd, &ch, 1 );
|
if ( 1 != read(globals->fdArray[FD_TIMEEVT].fd, &ch, 1 ) ) {
|
||||||
|
XP_ASSERT(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fdIndex = FD_FIRSTSOCKET;
|
fdIndex = FD_FIRSTSOCKET;
|
||||||
|
|
|
@ -97,9 +97,9 @@ skipBitmap( LinuxDictionaryCtxt* ctxt, FILE* dictF )
|
||||||
XP_U8 nCols, nRows, nBytes;
|
XP_U8 nCols, nRows, nBytes;
|
||||||
LinuxBMStruct* lbs = NULL;
|
LinuxBMStruct* lbs = NULL;
|
||||||
|
|
||||||
(void)fread( &nCols, sizeof(nCols), 1, dictF );
|
if ( 1 == fread( &nCols, sizeof(nCols), 1, dictF )
|
||||||
if ( nCols > 0 ) {
|
&& nCols > 0
|
||||||
(void)fread( &nRows, sizeof(nRows), 1, dictF );
|
&& 1 == fread( &nRows, sizeof(nRows), 1, dictF ) ) {
|
||||||
|
|
||||||
nBytes = ((nRows * nCols) + 7) / 8;
|
nBytes = ((nRows * nCols) + 7) / 8;
|
||||||
|
|
||||||
|
@ -108,7 +108,10 @@ skipBitmap( LinuxDictionaryCtxt* ctxt, FILE* dictF )
|
||||||
lbs->nCols = nCols;
|
lbs->nCols = nCols;
|
||||||
lbs->nBytes = nBytes;
|
lbs->nBytes = nBytes;
|
||||||
|
|
||||||
(void)fread( lbs + 1, nBytes, 1, dictF );
|
if ( 1 != fread( lbs + 1, nBytes, 1, dictF ) ) {
|
||||||
|
XP_FREE( ctxt->super.mpool, lbs );
|
||||||
|
lbs = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lbs;
|
return lbs;
|
||||||
|
@ -138,16 +141,18 @@ skipBitmaps( LinuxDictionaryCtxt* ctxt, FILE* dictF )
|
||||||
XP_ASSERT( face < nSpecials );
|
XP_ASSERT( face < nSpecials );
|
||||||
|
|
||||||
/* get the string */
|
/* get the string */
|
||||||
(void)fread( &txtlen, sizeof(txtlen), 1, dictF );
|
if ( 1 == fread( &txtlen, sizeof(txtlen), 1, dictF ) ) {
|
||||||
text = (XP_UCHAR*)XP_MALLOC(ctxt->super.mpool, txtlen+1);
|
text = (XP_UCHAR*)XP_MALLOC(ctxt->super.mpool, txtlen+1);
|
||||||
(void)fread( text, txtlen, 1, dictF );
|
if ( 1 == fread( text, txtlen, 1, dictF ) ) {
|
||||||
text[txtlen] = '\0';
|
text[txtlen] = '\0';
|
||||||
texts[face] = text;
|
texts[face] = text;
|
||||||
|
|
||||||
XP_DEBUGF( "skipping bitmaps for %s", texts[face] );
|
XP_DEBUGF( "skipping bitmaps for %s", texts[face] );
|
||||||
|
|
||||||
bitmaps[face].largeBM = skipBitmap( ctxt, dictF );
|
bitmaps[face].largeBM = skipBitmap( ctxt, dictF );
|
||||||
bitmaps[face].smallBM = skipBitmap( ctxt, dictF );
|
bitmaps[face].smallBM = skipBitmap( ctxt, dictF );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +163,7 @@ skipBitmaps( LinuxDictionaryCtxt* ctxt, FILE* dictF )
|
||||||
static XP_Bool
|
static XP_Bool
|
||||||
initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
||||||
{
|
{
|
||||||
XP_Bool formatOk = XP_TRUE;
|
XP_Bool formatOk = XP_FALSE;
|
||||||
XP_U8 numFaces;
|
XP_U8 numFaces;
|
||||||
long curPos, dictLength;
|
long curPos, dictLength;
|
||||||
XP_U32 topOffset;
|
XP_U32 topOffset;
|
||||||
|
@ -169,25 +174,30 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
||||||
XP_U16 charSize;
|
XP_U16 charSize;
|
||||||
|
|
||||||
XP_ASSERT( dictF );
|
XP_ASSERT( dictF );
|
||||||
(void)fread( &flags, sizeof(flags), 1, dictF );
|
if ( 1 == fread( &flags, sizeof(flags), 1, dictF ) ) {
|
||||||
flags = ntohs(flags);
|
flags = ntohs(flags);
|
||||||
XP_DEBUGF( "flags=0x%x", flags );
|
XP_DEBUGF( "flags=0x%x", flags );
|
||||||
#ifdef NODE_CAN_4
|
#ifdef NODE_CAN_4
|
||||||
if ( flags == 0x0001 ) {
|
if ( flags == 0x0001 ) {
|
||||||
dctx->super.nodeSize = 3;
|
dctx->super.nodeSize = 3;
|
||||||
charSize = 1;
|
charSize = 1;
|
||||||
dctx->super.is_4_byte = XP_FALSE;
|
dctx->super.is_4_byte = XP_FALSE;
|
||||||
} else if ( flags == 0x0002 ) {
|
formatOk = XP_TRUE;
|
||||||
dctx->super.nodeSize = 3;
|
} else if ( flags == 0x0002 ) {
|
||||||
charSize = 2;
|
dctx->super.nodeSize = 3;
|
||||||
dctx->super.is_4_byte = XP_FALSE;
|
charSize = 2;
|
||||||
} else if ( flags == 0x0003 ) {
|
dctx->super.is_4_byte = XP_FALSE;
|
||||||
dctx->super.nodeSize = 4;
|
formatOk = XP_TRUE;
|
||||||
charSize = 2;
|
} else if ( flags == 0x0003 ) {
|
||||||
dctx->super.is_4_byte = XP_TRUE;
|
dctx->super.nodeSize = 4;
|
||||||
|
charSize = 2;
|
||||||
|
dctx->super.is_4_byte = XP_TRUE;
|
||||||
|
formatOk = XP_TRUE;
|
||||||
|
} else {
|
||||||
|
/* case I don't know how to deal with */
|
||||||
|
XP_ASSERT(0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* case I don't know how to deal with */
|
|
||||||
formatOk = XP_FALSE;
|
|
||||||
XP_ASSERT(0);
|
XP_ASSERT(0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -195,7 +205,9 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( formatOk ) {
|
if ( formatOk ) {
|
||||||
(void)fread( &numFaces, sizeof(numFaces), 1, dictF );
|
if ( 1 != fread( &numFaces, sizeof(numFaces), 1, dictF ) ) {
|
||||||
|
goto closeAndExit;
|
||||||
|
}
|
||||||
|
|
||||||
dctx->super.nFaces = numFaces;
|
dctx->super.nFaces = numFaces;
|
||||||
|
|
||||||
|
@ -205,8 +217,11 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
||||||
dctx->super.faces16 = XP_MALLOC( dctx->super.mpool, facesSize );
|
dctx->super.faces16 = XP_MALLOC( dctx->super.mpool, facesSize );
|
||||||
XP_MEMSET( dctx->super.faces16, 0, facesSize );
|
XP_MEMSET( dctx->super.faces16, 0, facesSize );
|
||||||
|
|
||||||
fread( dctx->super.faces16, numFaces * charSize,
|
if ( 1 != fread( dctx->super.faces16, numFaces * charSize, 1,
|
||||||
1, dictF );
|
dictF ) ) {
|
||||||
|
goto closeAndExit;
|
||||||
|
}
|
||||||
|
|
||||||
if ( charSize == sizeof(dctx->super.faces16[0]) ) {
|
if ( charSize == sizeof(dctx->super.faces16[0]) ) {
|
||||||
/* fix endianness */
|
/* fix endianness */
|
||||||
XP_U16 i;
|
XP_U16 i;
|
||||||
|
@ -222,10 +237,15 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fread( &xloc, 2, 1, dictF ); /* read in (dump) the xloc header for
|
if ( (1 != fread( &xloc, 2, 1, dictF ) )/* read in (dump) the xloc
|
||||||
now */
|
header for now */
|
||||||
fread( dctx->super.countsAndValues, numFaces*2, 1, dictF );
|
|| (1 != fread( dctx->super.countsAndValues, numFaces*2, 1,
|
||||||
|
dictF ) ) ) {
|
||||||
|
goto closeAndExit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( formatOk ) {
|
||||||
skipBitmaps( dctx, dictF );
|
skipBitmaps( dctx, dictF );
|
||||||
|
|
||||||
curPos = ftell( dictF );
|
curPos = ftell( dictF );
|
||||||
|
@ -234,7 +254,9 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
||||||
fseek( dictF, curPos, SEEK_SET );
|
fseek( dictF, curPos, SEEK_SET );
|
||||||
|
|
||||||
if ( dictLength > 0 ) {
|
if ( dictLength > 0 ) {
|
||||||
fread( &topOffset, sizeof(topOffset), 1, dictF );
|
if ( 1 != fread( &topOffset, sizeof(topOffset), 1, dictF ) ) {
|
||||||
|
goto closeAndExit;
|
||||||
|
}
|
||||||
/* it's in big-endian order */
|
/* it's in big-endian order */
|
||||||
topOffset = ntohl(topOffset);
|
topOffset = ntohl(topOffset);
|
||||||
dictLength -= sizeof(topOffset); /* first four bytes are offset */
|
dictLength -= sizeof(topOffset); /* first four bytes are offset */
|
||||||
|
@ -254,7 +276,9 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
||||||
dctx->super.base = (array_edge*)XP_MALLOC( dctx->super.mpool,
|
dctx->super.base = (array_edge*)XP_MALLOC( dctx->super.mpool,
|
||||||
dictLength );
|
dictLength );
|
||||||
XP_ASSERT( !!dctx->super.base );
|
XP_ASSERT( !!dctx->super.base );
|
||||||
fread( dctx->super.base, dictLength, 1, dictF );
|
if ( 1 != fread( dctx->super.base, dictLength, 1, dictF ) ) {
|
||||||
|
goto closeAndExit;
|
||||||
|
}
|
||||||
|
|
||||||
dctx->super.topEdge = dctx->super.base + topOffset;
|
dctx->super.topEdge = dctx->super.base + topOffset;
|
||||||
} else {
|
} else {
|
||||||
|
@ -262,9 +286,13 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
||||||
dctx->super.topEdge = NULL;
|
dctx->super.topEdge = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dctx->super.name = copyString( dctx->super.mpool, fileName);
|
dctx->super.name = copyString( dctx->super.mpool, fileName );
|
||||||
}
|
}
|
||||||
|
goto ok;
|
||||||
|
|
||||||
|
closeAndExit:
|
||||||
|
formatOk = XP_FALSE;
|
||||||
|
ok:
|
||||||
fclose( dictF );
|
fclose( dictF );
|
||||||
return formatOk;
|
return formatOk;
|
||||||
} /* initFromDictFile */
|
} /* initFromDictFile */
|
||||||
|
|
|
@ -85,7 +85,9 @@ streamFromFile( CommonGlobals* cGlobals, char* name, void* closure )
|
||||||
(void)stat( name, &statBuf );
|
(void)stat( name, &statBuf );
|
||||||
buf = malloc( statBuf.st_size );
|
buf = malloc( statBuf.st_size );
|
||||||
f = fopen( name, "r" );
|
f = fopen( name, "r" );
|
||||||
fread( buf, statBuf.st_size, 1, f );
|
if ( 1 != fread( buf, statBuf.st_size, 1, f ) ) {
|
||||||
|
XP_ASSERT( 0 );
|
||||||
|
}
|
||||||
fclose( f );
|
fclose( f );
|
||||||
|
|
||||||
stream = mem_stream_make( MPPARM(cGlobals->params->util->mpool)
|
stream = mem_stream_make( MPPARM(cGlobals->params->util->mpool)
|
||||||
|
@ -110,7 +112,9 @@ writeToFile( XWStreamCtxt* stream, void* closure )
|
||||||
stream_getBytes( stream, buf, len );
|
stream_getBytes( stream, buf, len );
|
||||||
|
|
||||||
file = fopen( cGlobals->params->fileName, "w" );
|
file = fopen( cGlobals->params->fileName, "w" );
|
||||||
fwrite( buf, 1, len, file );
|
if ( 1 != fwrite( buf, 1, len, file ) ) {
|
||||||
|
XP_ASSERT( 0 );
|
||||||
|
}
|
||||||
fclose( file );
|
fclose( file );
|
||||||
|
|
||||||
free( buf );
|
free( buf );
|
||||||
|
@ -592,7 +596,9 @@ defaultRandomSeed()
|
||||||
without getting the same results. */
|
without getting the same results. */
|
||||||
unsigned int rs;
|
unsigned int rs;
|
||||||
FILE* rfile = fopen( "/dev/urandom", "ro" );
|
FILE* rfile = fopen( "/dev/urandom", "ro" );
|
||||||
fread( &rs, sizeof(rs), 1, rfile );
|
if ( 1 != fread( &rs, sizeof(rs), 1, rfile ) ) {
|
||||||
|
XP_ASSERT( 0 );
|
||||||
|
}
|
||||||
fclose( rfile );
|
fclose( rfile );
|
||||||
return rs;
|
return rs;
|
||||||
} /* defaultRandomSeed */
|
} /* defaultRandomSeed */
|
||||||
|
|
|
@ -177,7 +177,10 @@ decodeAndDelete( LinSMSData* data, const gchar* name,
|
||||||
|
|
||||||
gchar* contents;
|
gchar* contents;
|
||||||
gsize length;
|
gsize length;
|
||||||
gboolean success = g_file_get_contents( path, &contents, &length, NULL );
|
#ifdef DEBUG
|
||||||
|
gboolean success =
|
||||||
|
#endif
|
||||||
|
g_file_get_contents( path, &contents, &length, NULL );
|
||||||
XP_ASSERT( success );
|
XP_ASSERT( success );
|
||||||
unlink( path );
|
unlink( path );
|
||||||
|
|
||||||
|
@ -216,29 +219,29 @@ linux_sms_receive( CommonGlobals* globals, int sock,
|
||||||
|
|
||||||
/* read required or we'll just get the event again */
|
/* read required or we'll just get the event again */
|
||||||
XP_U8 buffer[sizeof(struct inotify_event) + 16];
|
XP_U8 buffer[sizeof(struct inotify_event) + 16];
|
||||||
(void)read( sock, buffer, sizeof(buffer) );
|
nRead = read( sock, buffer, sizeof(buffer) );
|
||||||
|
if ( nRead > 0 ) {
|
||||||
char shortest[256] = { '\0' };
|
char shortest[256] = { '\0' };
|
||||||
GDir* dir = g_dir_open( data->myQueue, 0, NULL );
|
GDir* dir = g_dir_open( data->myQueue, 0, NULL );
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
const gchar* name = g_dir_read_name( dir );
|
const gchar* name = g_dir_read_name( dir );
|
||||||
if ( NULL == name ) {
|
if ( NULL == name ) {
|
||||||
break;
|
break;
|
||||||
} else if ( 0 == strcmp( name, LOCK_FILE ) ) {
|
} else if ( 0 == strcmp( name, LOCK_FILE ) ) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
if ( !shortest[0] || 0 < strcmp( shortest, name ) ) {
|
||||||
|
snprintf( shortest, sizeof(shortest), "%s", name );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ( !shortest[0] || 0 < strcmp( shortest, name ) ) {
|
g_dir_close( dir );
|
||||||
snprintf( shortest, sizeof(shortest), "%s", name );
|
|
||||||
|
if ( !!shortest[0] ) {
|
||||||
|
nRead = decodeAndDelete( data, shortest, buf, buflen, addr );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unlock_queue( data );
|
||||||
}
|
}
|
||||||
g_dir_close( dir );
|
|
||||||
|
|
||||||
if ( !!shortest[0] ) {
|
|
||||||
nRead = decodeAndDelete( data, shortest, buf, buflen, addr );
|
|
||||||
}
|
|
||||||
|
|
||||||
unlock_queue( data );
|
|
||||||
|
|
||||||
return nRead;
|
return nRead;
|
||||||
} /* linux_sms_receive */
|
} /* linux_sms_receive */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue