Archived issue #0029252

Coding rules - eliminate GCC compiler warnings -Wformat-overflow

Open CASCADEOCCT:Codingclosed6 public notes

Search issues

Description

The following GCC 7.2.0 compiler warnings should be eliminated.
/occt.git/src/OSD/OSD_DirectoryIterator.cxx: In member function ‘void OSD_DirectoryIterator::Next()’:
/occt.git/src/OSD/OSD_DirectoryIterator.cxx:100:6: warning: ‘%s’ directive writing up to 255 bytes into a region of size 254 [-Wformat-overflow=]
 void OSD_DirectoryIterator::Next(){
      ^~~~~~~~~~~~~~~~~~~~~
/occt.git/src/OSD/OSD_DirectoryIterator.cxx:123:13: note: ‘sprintf’ output 2 or more bytes (assuming 257) into a destination of size 255
      sprintf(full_name,"%s/%s",myPlace.ToCString(),
      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       ((struct dirent *)myEntry)->d_name);   // LD debug
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/occt.git/src/OSD/OSD_FileIterator.cxx: In member function ‘void OSD_FileIterator::Next()’:
/occt.git/src/OSD/OSD_FileIterator.cxx:176:6: warning: ‘%s’ directive writing up to 255 bytes into a region of size 254 [-Wformat-overflow=]
 void OSD_FileIterator::Next(){
      ^~~~~~~~~~~~~~~~
/occt.git/src/OSD/OSD_FileIterator.cxx:199:13: note: ‘sprintf’ output 2 or more bytes (assuming 257) into a destination of size 255
      sprintf(full_name,"%s/%s",myPlace.ToCString(),
      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       ((struct dirent *)myEntry)->d_name);   // LD debug
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

||=== Build finished: 0 error(s), 2 warning(s) (17 minute(s), 37 second(s)) ===|

Public activity

6 archived notes

Participants are labeled by their role within this record.

01Commenter 2
Branch [archived branch] has been created by Author.

[revision removed]


Detailed log of new commits:

Author: Author
Date: Sat Oct 21 21:17:14 2017 +0300

    0029252: Coding rules - eliminate GCC compiler warnings -Wformat-overflow
    
    OSD_DirectoryIterator and OSD_FileIterator now uses TCollection_AsciiString instead of unsafe sprintf.
02Author
Patch is ready for review.
03Commenter 3
Reviewed, please test.

A side note is: function readdir used in the affected code is not reentrant; thread-safe version exist, called readdir_r.
04Author
> A side note is: function readdir used in the affected code is not reentrant;
> thread-safe version exist, called readdir_r.
readdir_r has bad design and is deprecated within glibc:
http://man7.org/linux/man-pages/man3/readdir_r.3.html
05Commenter 1
Combination -
OCCT branch : [archived branch] [revision removed]
Products branch : [archived branch]
was compiled on Linux, MacOS and Windows platforms and tested on optimize mode on jenkins-test-10 and jenkins-tets-08.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
No differences that require special attention

Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention
06Commenter 2
Branch [archived branch] has been deleted by Author.

[revision removed]

Related records