@@ -565,31 +565,29 @@ pgstat_reset_remove_files(const char *directory)
565
565
dir = AllocateDir (directory );
566
566
while ((entry = ReadDir (dir ,directory ))!= NULL )
567
567
{
568
- int nitems ;
569
- Oid tmp_oid ;
570
- char tmp_type [8 ];
571
- char tmp_rest [2 ];
572
-
573
- if (strncmp (entry -> d_name ,"." ,2 )== 0 ||
574
- strncmp (entry -> d_name ,".." ,3 )== 0 )
575
- continue ;
568
+ int nchars ;
569
+ Oid tmp_oid ;
576
570
577
571
/*
578
572
* Skip directory entries that don't match the file names we write.
579
573
* See get_dbstat_filename for the database-specific pattern.
580
574
*/
581
- nitems = sscanf ( entry -> d_name ,"db_%u.%5s%1s" ,
582
- & tmp_oid , tmp_type , tmp_rest ) ;
583
- if ( nitems != 2 )
575
+ if ( strncmp ( entry -> d_name ,"global." , 7 ) == 0 )
576
+ nchars = 7 ;
577
+ else
584
578
{
585
- nitems = sscanf (entry -> d_name ,"global.%5s%1s" ,
586
- tmp_type ,tmp_rest );
587
- if (nitems != 1 )
579
+ nchars = 0 ;
580
+ (void )sscanf (entry -> d_name ,"db_%u.%n" ,
581
+ & tmp_oid ,& nchars );
582
+ if (nchars <=0 )
583
+ continue ;
584
+ /* %u allows leading whitespace, so reject that */
585
+ if (strchr ("0123456789" ,entry -> d_name [3 ])== NULL )
588
586
continue ;
589
587
}
590
588
591
- if (strncmp ( tmp_type ,"tmp" , 4 )!= 0 &&
592
- strncmp ( tmp_type ,"stat" , 5 )!= 0 )
589
+ if (strcmp ( entry -> d_name + nchars ,"tmp" )!= 0 &&
590
+ strcmp ( entry -> d_name + nchars ,"stat" )!= 0 )
593
591
continue ;
594
592
595
593
snprintf (fname ,MAXPGPATH ,"%s/%s" ,directory ,