Check fgets for return value to avoid warnings.
git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@695 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
parent
e6727385dd
commit
3929b150ac
@ -1168,3 +1168,11 @@ generated by autogen.sh.
|
||||
|
||||
(303) Moved GLUT_INIT_STATE to <GL/freeglut_ext.h>, it is not part of the
|
||||
original GLUT.
|
||||
|
||||
**************************************************************************
|
||||
* Changes on August 05, 2006.
|
||||
**************************************************************************
|
||||
|
||||
(304) Updated build requirements for SuSE 10.1.
|
||||
|
||||
(305) Check fgets for return value to avoid warnings.
|
||||
|
@ -208,6 +208,16 @@ Special(int key, int x, int y)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
checkedFGets ( char *s, int size, FILE *stream )
|
||||
{
|
||||
if ( fgets ( s, size, stream ) == NULL ) {
|
||||
fprintf ( stderr, "fgets failed\n");
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void readConfigFile ( char *fnme )
|
||||
{
|
||||
FILE *fptr = fopen ( fnme, "rt" ) ;
|
||||
@ -217,13 +227,13 @@ void readConfigFile ( char *fnme )
|
||||
if ( fptr )
|
||||
{
|
||||
/* Read a header line */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
|
||||
/* Read a comment line */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
|
||||
/* Read the window title */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
/* We assume here that this line will not exceed 79 characters plus a
|
||||
newline (window_title is 80 characters long). That'll cause a buffer
|
||||
overflow. For a simple program like this, though, we're letting it
|
||||
@ -232,21 +242,21 @@ void readConfigFile ( char *fnme )
|
||||
sscanf ( inputline, "%[a-zA-Z0-9!@#$%^&*()+=/\\_-\" ]", window_title ) ;
|
||||
|
||||
/* Read a comment line */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
|
||||
/* Read the number of affine transformations */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
sscanf ( inputline, "%d", &num_trans ) ;
|
||||
|
||||
affine = (AffineTrans *)malloc ( num_trans * sizeof(AffineTrans) ) ;
|
||||
|
||||
/* Read a comment line */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
|
||||
for ( i = 0; i < num_trans; i++ )
|
||||
{
|
||||
/* Read an affine transformation definition */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
sscanf ( inputline, "%lf %lf %lf %lf %lf %lf", &affine[i].a00, &affine[i].a01,
|
||||
&affine[i].a10, &affine[i].a11, &affine[i].b0, &affine[i].b1 ) ;
|
||||
}
|
||||
|
@ -255,6 +255,16 @@ MouseWheel ( int wheel_number, int direction, int x, int y )
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
checkedFGets ( char *s, int size, FILE *stream )
|
||||
{
|
||||
if ( fgets ( s, size, stream ) == NULL ) {
|
||||
fprintf ( stderr, "fgets failed\n");
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void readConfigFile ( char *fnme )
|
||||
{
|
||||
FILE *fptr = fopen ( fnme, "rt" ) ;
|
||||
@ -264,13 +274,13 @@ void readConfigFile ( char *fnme )
|
||||
if ( fptr )
|
||||
{
|
||||
/* Read a header line */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
|
||||
/* Read a comment line */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
|
||||
/* Read the window title */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
/* We assume here that this line will not exceed 79 characters plus a
|
||||
newline (window_title is 80 characters long). That'll cause a buffer
|
||||
overflow. For a simple program like this, though, we're letting it
|
||||
@ -279,21 +289,21 @@ void readConfigFile ( char *fnme )
|
||||
sscanf ( inputline, "%[a-zA-Z0-9!@#$%^&*()+=/\\_-\" ]", window_title ) ;
|
||||
|
||||
/* Read a comment line */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
|
||||
/* Read the number of affine transformations */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
sscanf ( inputline, "%d", &num_trans ) ;
|
||||
|
||||
affine = (AffineTrans *)malloc ( num_trans * sizeof(AffineTrans) ) ;
|
||||
|
||||
/* Read a comment line */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
|
||||
for ( i = 0; i < num_trans; i++ )
|
||||
{
|
||||
/* Read an affine transformation definition */
|
||||
fgets ( inputline, 256, fptr ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
|
||||
sscanf ( inputline, "%lf %lf %lf %lf %lf %lf", &affine[i].a00, &affine[i].a01,
|
||||
&affine[i].a10, &affine[i].a11, &affine[i].b0, &affine[i].b1 ) ;
|
||||
}
|
||||
|
@ -107,6 +107,16 @@ void advance_in_time ( double time_step, double position[3], double new_position
|
||||
( deriv0[i] + 2.0 * ( deriv1[i] + deriv2[i] ) + deriv3[i] ) ;
|
||||
}
|
||||
|
||||
static void
|
||||
checkedFGets ( char *s, int size, FILE *stream )
|
||||
{
|
||||
if ( fgets ( s, size, stream ) == NULL ) {
|
||||
fprintf ( stderr, "fgets failed\n");
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* GLUT callbacks */
|
||||
|
||||
#define INPUT_LINE_LENGTH 80
|
||||
@ -142,15 +152,15 @@ void key_cb ( unsigned char key, int x, int y )
|
||||
|
||||
case 'm' : case 'M' : /* Modify the Lorenz parameters */
|
||||
printf ( "Please enter new value for <sigma> (default %f, currently %f): ", s0, sigma ) ;
|
||||
fgets ( inputline, INPUT_LINE_LENGTH-1, stdin ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), stdin ) ;
|
||||
sscanf ( inputline, "%lf", &sigma ) ;
|
||||
|
||||
printf ( "Please enter new value for <b> (default %f, currently %f): ", b0, b ) ;
|
||||
fgets ( inputline, INPUT_LINE_LENGTH-1, stdin ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), stdin ) ;
|
||||
sscanf ( inputline, "%lf", &b ) ;
|
||||
|
||||
printf ( "Please enter new value for <r> (default %f, currently %f): ", r0, r ) ;
|
||||
fgets ( inputline, INPUT_LINE_LENGTH-1, stdin ) ;
|
||||
checkedFGets ( inputline, sizeof ( inputline ), stdin ) ;
|
||||
sscanf ( inputline, "%lf", &r ) ;
|
||||
|
||||
break ;
|
||||
|
Reference in New Issue
Block a user