Fix compile errors using latest gcc (fread etc must have return value checked)

This commit is contained in:
ehouse 2009-01-03 18:12:34 +00:00
parent 552f6350f9
commit 863f79bfb9
4 changed files with 106 additions and 65 deletions

View file

@ -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
post-event on a more familiar system. It works, so no complaints! */
CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure;
(void)write( globals->timepipe[1], "!", 1 );
if ( 1 != write( globals->timepipe[1], "!", 1 ) ) {
XP_ASSERT(0);
}
} /* curses_util_requestTime */
static void
@ -947,7 +949,9 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch )
if ( (globals->fdArray[FD_TIMEEVT].revents & POLLIN) != 0 ) {
char ch;
/* 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;

View file

@ -97,9 +97,9 @@ skipBitmap( LinuxDictionaryCtxt* ctxt, FILE* dictF )
XP_U8 nCols, nRows, nBytes;
LinuxBMStruct* lbs = NULL;
(void)fread( &nCols, sizeof(nCols), 1, dictF );
if ( nCols > 0 ) {
(void)fread( &nRows, sizeof(nRows), 1, dictF );
if ( 1 == fread( &nCols, sizeof(nCols), 1, dictF )
&& nCols > 0
&& 1 == fread( &nRows, sizeof(nRows), 1, dictF ) ) {
nBytes = ((nRows * nCols) + 7) / 8;
@ -108,7 +108,10 @@ skipBitmap( LinuxDictionaryCtxt* ctxt, FILE* dictF )
lbs->nCols = nCols;
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;
@ -138,16 +141,18 @@ skipBitmaps( LinuxDictionaryCtxt* ctxt, FILE* dictF )
XP_ASSERT( face < nSpecials );
/* get the string */
(void)fread( &txtlen, sizeof(txtlen), 1, dictF );
text = (XP_UCHAR*)XP_MALLOC(ctxt->super.mpool, txtlen+1);
(void)fread( text, txtlen, 1, dictF );
text[txtlen] = '\0';
texts[face] = text;
if ( 1 == fread( &txtlen, sizeof(txtlen), 1, dictF ) ) {
text = (XP_UCHAR*)XP_MALLOC(ctxt->super.mpool, txtlen+1);
if ( 1 == fread( text, txtlen, 1, dictF ) ) {
text[txtlen] = '\0';
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].smallBM = skipBitmap( ctxt, dictF );
bitmaps[face].largeBM = skipBitmap( ctxt, dictF );
bitmaps[face].smallBM = skipBitmap( ctxt, dictF );
}
}
}
}
@ -158,7 +163,7 @@ skipBitmaps( LinuxDictionaryCtxt* ctxt, FILE* dictF )
static XP_Bool
initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
{
XP_Bool formatOk = XP_TRUE;
XP_Bool formatOk = XP_FALSE;
XP_U8 numFaces;
long curPos, dictLength;
XP_U32 topOffset;
@ -169,25 +174,30 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
XP_U16 charSize;
XP_ASSERT( dictF );
(void)fread( &flags, sizeof(flags), 1, dictF );
flags = ntohs(flags);
XP_DEBUGF( "flags=0x%x", flags );
if ( 1 == fread( &flags, sizeof(flags), 1, dictF ) ) {
flags = ntohs(flags);
XP_DEBUGF( "flags=0x%x", flags );
#ifdef NODE_CAN_4
if ( flags == 0x0001 ) {
dctx->super.nodeSize = 3;
charSize = 1;
dctx->super.is_4_byte = XP_FALSE;
} else if ( flags == 0x0002 ) {
dctx->super.nodeSize = 3;
charSize = 2;
dctx->super.is_4_byte = XP_FALSE;
} else if ( flags == 0x0003 ) {
dctx->super.nodeSize = 4;
charSize = 2;
dctx->super.is_4_byte = XP_TRUE;
if ( flags == 0x0001 ) {
dctx->super.nodeSize = 3;
charSize = 1;
dctx->super.is_4_byte = XP_FALSE;
formatOk = XP_TRUE;
} else if ( flags == 0x0002 ) {
dctx->super.nodeSize = 3;
charSize = 2;
dctx->super.is_4_byte = XP_FALSE;
formatOk = XP_TRUE;
} else if ( flags == 0x0003 ) {
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 {
/* case I don't know how to deal with */
formatOk = XP_FALSE;
XP_ASSERT(0);
}
#else
@ -195,7 +205,9 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
#endif
if ( formatOk ) {
(void)fread( &numFaces, sizeof(numFaces), 1, dictF );
if ( 1 != fread( &numFaces, sizeof(numFaces), 1, dictF ) ) {
goto closeAndExit;
}
dctx->super.nFaces = numFaces;
@ -205,8 +217,11 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
dctx->super.faces16 = XP_MALLOC( dctx->super.mpool, facesSize );
XP_MEMSET( dctx->super.faces16, 0, facesSize );
fread( dctx->super.faces16, numFaces * charSize,
1, dictF );
if ( 1 != fread( dctx->super.faces16, numFaces * charSize, 1,
dictF ) ) {
goto closeAndExit;
}
if ( charSize == sizeof(dctx->super.faces16[0]) ) {
/* fix endianness */
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
now */
fread( dctx->super.countsAndValues, numFaces*2, 1, dictF );
if ( (1 != fread( &xloc, 2, 1, dictF ) )/* read in (dump) the xloc
header for now */
|| (1 != fread( dctx->super.countsAndValues, numFaces*2, 1,
dictF ) ) ) {
goto closeAndExit;
}
}
if ( formatOk ) {
skipBitmaps( dctx, dictF );
curPos = ftell( dictF );
@ -234,7 +254,9 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
fseek( dictF, curPos, SEEK_SET );
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 */
topOffset = ntohl(topOffset);
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,
dictLength );
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;
} else {
@ -262,9 +286,13 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
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 );
return formatOk;
} /* initFromDictFile */

View file

@ -85,7 +85,9 @@ streamFromFile( CommonGlobals* cGlobals, char* name, void* closure )
(void)stat( name, &statBuf );
buf = malloc( statBuf.st_size );
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 );
stream = mem_stream_make( MPPARM(cGlobals->params->util->mpool)
@ -110,7 +112,9 @@ writeToFile( XWStreamCtxt* stream, void* closure )
stream_getBytes( stream, buf, len );
file = fopen( cGlobals->params->fileName, "w" );
fwrite( buf, 1, len, file );
if ( 1 != fwrite( buf, 1, len, file ) ) {
XP_ASSERT( 0 );
}
fclose( file );
free( buf );
@ -592,7 +596,9 @@ defaultRandomSeed()
without getting the same results. */
unsigned int rs;
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 );
return rs;
} /* defaultRandomSeed */

View file

@ -177,7 +177,10 @@ decodeAndDelete( LinSMSData* data, const gchar* name,
gchar* contents;
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 );
unlink( path );
@ -216,29 +219,29 @@ linux_sms_receive( CommonGlobals* globals, int sock,
/* read required or we'll just get the event again */
XP_U8 buffer[sizeof(struct inotify_event) + 16];
(void)read( sock, buffer, sizeof(buffer) );
char shortest[256] = { '\0' };
GDir* dir = g_dir_open( data->myQueue, 0, NULL );
for ( ; ; ) {
const gchar* name = g_dir_read_name( dir );
if ( NULL == name ) {
break;
} else if ( 0 == strcmp( name, LOCK_FILE ) ) {
continue;
nRead = read( sock, buffer, sizeof(buffer) );
if ( nRead > 0 ) {
char shortest[256] = { '\0' };
GDir* dir = g_dir_open( data->myQueue, 0, NULL );
for ( ; ; ) {
const gchar* name = g_dir_read_name( dir );
if ( NULL == name ) {
break;
} else if ( 0 == strcmp( name, LOCK_FILE ) ) {
continue;
}
if ( !shortest[0] || 0 < strcmp( shortest, name ) ) {
snprintf( shortest, sizeof(shortest), "%s", name );
}
}
if ( !shortest[0] || 0 < strcmp( shortest, name ) ) {
snprintf( shortest, sizeof(shortest), "%s", name );
g_dir_close( dir );
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;
} /* linux_sms_receive */