3535
3636long read_array (FILE * fp , char * PVname , char * value_string , short field_type , long element_count , char * read_buffer ,
3737 int debug );
38+ int do_asVerify_fp (FILE * fp , int verbose , int debug , int write_restore_file , char * restoreFileName );
3839
3940/* verbose==-1 means don't say anything unless there's a problem. */
4041int do_asVerify (char * fileName , int verbose , int debug , int write_restore_file , char * restoreFileName )
42+ {
43+ FILE * fp = NULL ;
44+ fp = fopen (fileName , "r" );
45+ if (fp == NULL ) {
46+ printf ("asVerify: Can't open '%s'.\n" , fileName );
47+ return (-1 );
48+ }
49+ return do_asVerify_fp (fp , verbose , debug , write_restore_file , restoreFileName );
50+ }
51+
52+ int do_asVerify_fp (FILE * fp , int verbose , int debug , int write_restore_file , char * restoreFileName )
4153{
4254 float * pfvalue , * pf_read ;
4355 double * pdvalue , * pd_read , diff , max_diff = 0. ;
4456 short * penum_value , * penum_value_read ;
4557 char * svalue , * svalue_read ;
4658 chid chid ;
47- FILE * fp = NULL , * fr = NULL , * fr1 = NULL ;
59+ FILE * fr = NULL , * fr1 = NULL ;
4860 char c , s [BUF_SIZE ], * bp , PVname [PV_NAME_LEN + 1 ], value_string [BUF_SIZE ];
4961 char trial_restoreFileName [PATH_SIZE ];
5062 char * CA_buffer = NULL , * read_buffer = NULL , * pc = NULL ;
@@ -54,12 +66,6 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
5466 int different , wrote_head = 0 , status , file_ok = 0 ;
5567 long element_count = 0 , storageBytes = 0 , alloc_CA_buffer = 0 ;
5668
57- fp = fopen (fileName , "r" );
58- if (fp == NULL ) {
59- printf ("asVerify: Can't open '%s'.\n" , fileName );
60- return (-1 );
61- }
62-
6369 if (write_restore_file ) {
6470 strcpy (trial_restoreFileName , restoreFileName );
6571 strcat (trial_restoreFileName , "B" );
@@ -74,11 +80,11 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
7480 }
7581 /* check that (copy of) .sav file is good */
7682 status = fseek (fp , -6 , SEEK_END );
77- fgets (s , 6 , fp );
83+ if ( fgets (s , 6 , fp ) == NULL ) file_ok = 0 ;
7884 if (strncmp (s , "<END>" , 5 ) == 0 ) file_ok = 1 ;
7985 if (!file_ok ) {
8086 status = fseek (fp , -7 , SEEK_END );
81- fgets (s , 7 , fp );
87+ if ( fgets (s , 7 , fp ) == NULL ) file_ok = 0 ;
8288 if (strncmp (s , "<END>" , 5 ) == 0 ) file_ok = 1 ;
8389 }
8490 if (status || !file_ok ) {
@@ -328,13 +334,13 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
328334 /* No, we didn't. One more read will certainly accumulate a value string of length BUF_SIZE */
329335 if (debug > 3 ) printf ("did not reach end of line for long-string PV\n" );
330336 bp = fgets (s , BUF_SIZE , fp );
331- n = BUF_SIZE - strlen (value_string ) - 1 ;
337+ n = BUF_SIZE - ( int ) strlen (value_string ) - 1 ;
332338 strncat (value_string , bp , n );
333339 if (value_string [strlen (value_string ) - 1 ] == '\n' )
334340 value_string [strlen (value_string ) - 1 ] = '\0' ;
335341 }
336342 /* Discard additional characters until end of line */
337- while (bp [strlen (bp ) - 1 ] != '\n' ) fgets (s , BUF_SIZE , fp );
343+ while (bp [strlen (bp ) - 1 ] != '\n' && fgets (s , BUF_SIZE , fp ) != NULL );
338344
339345 status = ca_array_get (DBR_CHAR , element_count , chid , (void * )svalue );
340346 } else {
@@ -370,7 +376,7 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
370376 if (different || (verbose > 0 )) {
371377 WRITE_HEADER ;
372378 if (is_scalar || is_long_string ) {
373- nspace = 24 - strlen (value_string );
379+ nspace = 24 - ( int ) strlen (value_string );
374380 if (nspace < 1 ) nspace = 1 ;
375381 printf ("%s%-24s '%s'%*s'%s'\n" , different ? "*** " : " " , PVname , value_string ,
376382 nspace , "" , svalue );
@@ -455,7 +461,7 @@ static float safeDoubleToFloat(double d)
455461 if (d > 0.0 ) f = FLT_MIN ;
456462 else f = - FLT_MIN ;
457463 } else {
458- f = d ;
464+ f = ( float ) d ;
459465 }
460466 return (f );
461467}
@@ -536,7 +542,7 @@ long read_array(FILE *fp, char *PVname, char *value_string, short field_type, lo
536542 * If there are more characters than we can handle, just pretend we read them.
537543 */
538544 /* *bp == ELEMENT_END ,*/
539- if (debug > 1 ) printf ("array_read: looking for element-end: '%s'\n" , bp );
545+ if (debug > 1 ) printf ("array_read: looking for element-end: '%s'\n" , bp ? bp : "(null)" );
540546 for (found = 0 ; (found == 0 ) && !end_of_file ;) {
541547 while (* bp && (* bp != ELEMENT_END ) && (* bp != ESCAPE )) bp ++ ;
542548 switch (* bp ) {
@@ -613,7 +619,7 @@ long read_array(FILE *fp, char *PVname, char *value_string, short field_type, lo
613619 if ((bp = fgets (buffer , BUF_SIZE , fp )) == NULL ) end_of_file = 1 ;
614620 }
615621 }
616- if (debug > 1 ) printf ("array_read: positioned for next PV '%s'\n" , bp );
622+ if (debug > 1 ) printf ("array_read: positioned for next PV '%s'\n" , bp ? bp : "(null)" );
617623 if (!status && end_of_file ) status = end_of_file ;
618624
619625 return (status );
0 commit comments