0029252: Coding rules - eliminate GCC compiler warnings -Wformat-overflow
authorkgv <kgv@opencascade.com>
Sat, 21 Oct 2017 18:17:14 +0000 (21:17 +0300)
committerbugmaster <bugmaster@opencascade.com>
Tue, 24 Oct 2017 15:27:00 +0000 (18:27 +0300)
OSD_DirectoryIterator and OSD_FileIterator now uses TCollection_AsciiString instead of unsafe sprintf.

src/OSD/OSD_DirectoryIterator.cxx
src/OSD/OSD_FileIterator.cxx

index 667b484..568122b 100644 (file)
@@ -100,13 +100,11 @@ static int strcmp_joker(const char *Mask,const char *Name)
 void OSD_DirectoryIterator::Next(){
 int again = 1;
 struct stat stat_buf;
-char full_name[255];
-
  myFlag = false;   // Initialize to nothing found
 
  do{
     myEntry = readdir((DIR *)myDescr);
-   
+
     if (!myEntry){   // No file found
      myEntry = NULL;              // Keep pointer clean
      myFlag = Standard_False;   // No more files/directory
@@ -119,10 +117,8 @@ char full_name[255];
 //     if (!strcmp(entry->d_name,"..")) continue;         2 directories.
 
      // Is it a directory ?
-
-     sprintf(full_name,"%s/%s",myPlace.ToCString(),
-            ((struct dirent *)myEntry)->d_name);                // LD debug
-     stat(full_name, &stat_buf);
+     const TCollection_AsciiString aFullName = myPlace + "/" + ((struct dirent* )myEntry)->d_name;
+     stat(aFullName.ToCString(), &stat_buf);
      if (S_ISDIR(stat_buf.st_mode))   // Ensure me it's not a file
       if (strcmp_joker(myMask.ToCString(), ((struct dirent *)myEntry)->d_name)){
                                                         // Does it follow mask ?
index f5b20a5..7b8f469 100644 (file)
@@ -176,13 +176,11 @@ static int strcmp_joker(char *fileMask,char *fileName)
 void OSD_FileIterator::Next(){
 int again = 1;
 struct stat stat_buf;
-char full_name[255];
-
  myFlag = false;   // Initialize to nothing found
 
  do {
     myEntry = readdir((DIR *)myDescr);
-   
+
     if (!myEntry){   // No file found
      myEntry = NULL;              // Keep pointer clean
      myFlag = Standard_False;   // No more files/directory
@@ -195,14 +193,8 @@ char full_name[255];
      if (!strcmp(((struct dirent *)myEntry)->d_name,"..")) continue;
 
      // Is it a file ?
-
-     sprintf(full_name,"%s/%s",myPlace.ToCString(),
-            ((struct dirent *)myEntry)->d_name);                // LD debug
-#ifdef OCCT_DEBUG
-     cout << "Place : " << myPlace << endl;
-     cout << "FName : " << full_name << endl;
-#endif
-     stat(full_name, &stat_buf);
+     const TCollection_AsciiString aFullName = myPlace + "/" + ((struct dirent* )myEntry)->d_name;
+     stat(aFullName.ToCString(), &stat_buf);
      if (S_ISREG(stat_buf.st_mode))   // LD : Ensure me it's a regular file
       if (strcmp_joker(myMask.ToCString(), ((struct dirent *)myEntry)->d_name)){
                                                         // Does it follow mask ?