View Issue Details

IDProjectCategoryView StatusLast Update
0023042Open CASCADEOCCT:Foundation Classespublic2013-12-19 13:56
Reporterkgv Assigned Toomy 
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version6.5.2 
Target Version6.7.0Fixed in Version6.7.0 
Summary0023042: Potential mistakes in (s)printf usage
DescriptionThere are some warning related to (s)printf usage.
This is a known problem caused by fact that (s)printf functions has different format options on different platforms
and appear mostly for integer types other than 'int' (long, size_t, int64_t etc.).

src/OSD/OSD_MAllocHook.cxx: In static member function 'static Standard_Boolean OSD_MAllocHook::LogFileHandler::MakeReport(const char*, const char*, Standard_Boolean)':
src/OSD/OSD_MAllocHook.cxx:362: warning: format '%10d' expects type 'int', but argument 3 has type 'long unsigned int'
src/OSD/OSD_MAllocHook.cxx:362: warning: unknown conversion type character 'I' in format
src/OSD/OSD_MAllocHook.cxx:362: warning: too many arguments for format
src/OSD/OSD_MAllocHook.cxx:376: warning: unknown conversion type character 'I' in format
src/OSD/OSD_MAllocHook.cxx:376: warning: too many arguments for format

src/OSD/OSD_MAllocHook.cxx: In member function 'virtual void OSD_MAllocHook::LogFileHandler::AllocEvent(size_t, long int)':
src/OSD/OSD_MAllocHook.cxx:393: warning: format '%10u' expects type 'unsigned int', but argument 4 has type 'size_t'

src/OSD/OSD_MAllocHook.cxx: In member function 'virtual void OSD_MAllocHook::LogFileHandler::FreeEvent(void*, size_t, long int)':
src/OSD/OSD_MAllocHook.cxx:415: warning: format '%10u' expects type 'unsigned int', but argument 4 has type 'size_t'

src/OSD/OSD_MAllocHook.cxx: In member function 'Standard_Boolean OSD_MAllocHook::CollectBySize::MakeReport(const char*)':
src/OSD/OSD_MAllocHook.cxx:497: warning: unknown conversion type character 'I' in format
src/OSD/OSD_MAllocHook.cxx:497: warning: too many arguments for format
src/OSD/OSD_MAllocHook.cxx:506: warning: unknown conversion type character 'I' in format
src/OSD/OSD_MAllocHook.cxx:506: warning: too many arguments for format

src/NCollection/NCollection_BaseAllocator.cxx: In static member function 'static void NCollection_BaseAllocator::PrintMemUsageStatistics()':
src/NCollection/NCollection_BaseAllocator.cxx:276: warning: format '%12d' expects type 'int', but argument 3 has type 'long unsigned int'
src/NCollection/NCollection_BaseAllocator.cxx:276: warning: format '%12d' expects type 'int', but argument 6 has type 'Standard_Size'
src/NCollection/NCollection_BaseAllocator.cxx:276: warning: format '%12d' expects type 'int', but argument 7 has type 'Standard_Size'
src/NCollection/NCollection_BaseAllocator.cxx:281: warning: format '%12d' expects type 'int', but argument 6 has type 'Standard_Size'
src/NCollection/NCollection_BaseAllocator.cxx:281: warning: format '%12d' expects type 'int', but argument 7 has type 'Standard_Size'
src/NCollection/NCollection_BaseAllocator.cxx:285: warning: format '%d' expects type 'int', but argument 3 has type 'long unsigned int'
src/NCollection/NCollection_BaseAllocator.cxx:288: warning: format '%d' expects type 'int', but argument 3 has type 'long unsigned int'

src/NCollection/NCollection_IncAllocator.cxx: In function 'void IncAllocator_PrintAlive()':
src/NCollection/NCollection_IncAllocator.cxx:165: warning: format '%-8d' expects type 'int', but argument 3 has type 'Standard_Size'

src/NCollection/NCollection_HeapAllocator.cxx: In member function 'virtual void* NCollection_HeapAllocator::Allocate(Standard_Size)':
src/NCollection/NCollection_HeapAllocator.cxx:41: warning: format '%d' expects type 'int', but argument 3 has type 'long unsigned int'

src/IFSelect/IFSelect_SessionPilot.cxx: In member function 'IFSelect_ReturnStatus IFSelect_SessionPilot::ReadScript(const char*)':
src/IFSelect/IFSelect_SessionPilot.cxx:242: warning: format not a string literal and no format arguments

src/VrmlData/VrmlData_Scene.cxx: In function 'void dumpNode(Standard_OStream&, const Handle_VrmlData_Node&, const TCollection_AsciiString&)':
src/VrmlData/VrmlData_Scene.cxx:1136: warning: format '%d' expects type 'int', but argument 3 has type 'long unsigned int'
src/VrmlData/VrmlData_Scene.cxx:1136: warning: format '%d' expects type 'int', but argument 4 has type 'long unsigned int'
src/VrmlData/VrmlData_Scene.cxx:1145: warning: format '%d' expects type 'int', but argument 3 has type 'long unsigned int'
src/VrmlData/VrmlData_Scene.cxx:1145: warning: format '%d' expects type 'int', but argument 4 has type 'long unsigned int'


src/BOPTest/BOPTest_LowCommands.cxx: In function 'void PrintState(Draw_Interpretor&, const TopAbs_State&)':
src/BOPTest/BOPTest_LowCommands.cxx:735: warning: format not a string literal and no format arguments
src/BOPTest/BOPTest_LowCommands.cxx:738: warning: format not a string literal and no format arguments
src/BOPTest/BOPTest_LowCommands.cxx:741: warning: format not a string literal and no format arguments
src/BOPTest/BOPTest_LowCommands.cxx:744: warning: format not a string literal and no format arguments
src/BOPTest/BOPTest_LowCommands.cxx:747: warning: format not a string literal and no format arguments

src/QABugs/QABugs_3.cxx: In function 'Standard_Integer coordload(Draw_Interpretor&, Standard_Integer, const char**)':
src/QABugs/QABugs_3.cxx:1440: warning: format '%20c' expects type 'char*', but argument 3 has type 'char (*)[30]'
src/QABugs/QABugs_3.cxx:1440: warning: format '%20c' expects type 'char*', but argument 4 has type 'char (*)[30]'
src/QABugs/QABugs_3.cxx:1448: warning: format '%20c' expects type 'char*', but argument 3 has type 'char (*)[30]'
src/QABugs/QABugs_3.cxx:1448: warning: format '%20c' expects type 'char*', but argument 4 has type 'char (*)[30]'

src/QABugs/QABugs_11.cxx: In function 'Standard_Integer OCC299bug(Draw_Interpretor&, Standard_Integer, const char**)':
src/QABugs/QABugs_11.cxx:934: warning: format not a string literal and no format arguments
src/QABugs/QABugs_11.cxx:937: warning: format not a string literal and no format arguments
src/QABugs/QABugs_11.cxx:940: warning: format not a string literal and no format arguments
src/QABugs/QABugs_11.cxx:943: warning: format not a string literal and no format arguments
src/QABugs/QABugs_11.cxx:946: warning: format not a string literal and no format arguments
TagsNo tags attached.
Test case numberNot needed

Activities

omy

2013-03-06 11:22

developer   ~0023601

Dear kgv,
Fix is implemented into branch CR23042.
Please, review.

omy

2013-03-11 17:16

developer   ~0023646

Dear kgv,
I've made some fixes in current branch.
Please, review.

kgv

2013-07-07 20:01

developer   ~0024980

Patch is ready for testing in CR23042_1 branch.

abv

2013-07-08 08:31

manager   ~0024981

Kirill, as a side note, I did not get completely your point in replacing fprintfs by streams, to me the previous code was simpler and nicer. Note that as far as I can see, your changes affected width of the fields in output -- would not it be a problem for someone? Nevertheless, I agree that C++ streams are better in that they are exception safe, so let it be.

Another note: please avoid changing formatting and names of existing variables even when they do not meet 'default' OCCT style, e.g. in BOPTest_LowCommands.cxx / bclassify(): usage of simple names for command line arguments (n / a, argc / argv) was de-facto standard for decades, it is better not to break this.

apn

2013-07-08 17:52

administrator   ~0024989

Dear BugMaster,

Branch CR23042_1 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
SHA-1: 6839f33720ba6c9f8af5d2b05f36bc1cebe9efbe

Number of compiler warnings:

occt component :
Linux: 2 (2 on master)
Windows: 7 (7 on master)

products component :
Linux: 0 (0 on master)
Windows: 63 (63 on master)

Regressions:
No regressions

Improvements:
No improvements

Testing cases:
Not needed

Testing on Linux:
Total MEMORY difference: 364951520 / 365009856
Total CPU difference: 45274.36000000066 / 44730.12000000092

Testing on Windows:
Total MEMORY difference: 425488680 / 425517236
Total CPU difference: 40953.1875 / 41691.875

There are not differences in images found by testdiff.

Related Changesets

occt: master 64531d9c

2013-07-12 08:25:44

omy

Details Diff
0023042: Potential mistakes in (s)printf usage

Use PRIuPTR macros for Standard_Size values in printf.
Use STL streams instead of printf when reasonable.
Affected Issues
0023042
mod - src/BOPTest/BOPTest_LowCommands.cxx Diff File
mod - src/IFSelect/IFSelect_SessionPilot.cxx Diff File
mod - src/NCollection/NCollection_BaseAllocator.cxx Diff File
mod - src/NCollection/NCollection_HeapAllocator.cxx Diff File
mod - src/NCollection/NCollection_IncAllocator.cxx Diff File
mod - src/NCollection/NCollection_IncAllocator.hxx Diff File
mod - src/OSD/OSD_MAllocHook.cxx Diff File
mod - src/OSD/OSD_MAllocHook.hxx Diff File
mod - src/QABugs/QABugs_11.cxx Diff File
mod - src/QABugs/QABugs_3.cxx Diff File
mod - src/Standard/Standard_TypeDef.hxx Diff File
mod - src/VrmlData/VrmlData_Scene.cxx Diff File

Issue History

Date Modified Username Field Change
2012-03-28 12:19 kgv New Issue
2012-03-28 12:19 kgv Assigned To => abv
2012-05-04 12:48 abv Assigned To abv => dbv
2012-05-04 12:48 abv Status new => assigned
2012-10-26 17:58 abv Assigned To dbv => ilv
2012-10-26 19:10 abv Assigned To ilv => dbv
2012-10-26 19:10 abv Target Version => 6.6.0
2013-03-02 09:54 abv Assigned To dbv => oan
2013-03-02 09:54 abv Assigned To oan => omy
2013-03-06 11:22 omy Note Added: 0023601
2013-03-06 11:22 omy Assigned To omy => kgv
2013-03-06 11:22 omy Status assigned => resolved
2013-03-06 17:10 kgv Assigned To kgv => omy
2013-03-06 17:10 kgv Status resolved => assigned
2013-03-11 17:16 omy Note Added: 0023646
2013-03-11 17:16 omy Assigned To omy => kgv
2013-03-11 17:16 omy Status assigned => resolved
2013-04-12 10:31 abv Target Version 6.6.0 => 6.7.0
2013-07-07 20:01 kgv Note Added: 0024980
2013-07-07 20:01 kgv Assigned To kgv => bugmaster
2013-07-07 20:01 kgv Status resolved => reviewed
2013-07-08 08:31 abv Note Added: 0024981
2013-07-08 12:14 apn Assigned To bugmaster => apn
2013-07-08 17:52 apn Note Added: 0024989
2013-07-08 17:53 apn Test case number => Not needed
2013-07-08 17:53 apn Assigned To apn => bugmaster
2013-07-08 17:53 apn Status reviewed => tested
2013-07-12 18:08 omy Changeset attached => occt master 64531d9c
2013-07-12 18:09 omy Assigned To bugmaster => omy
2013-07-12 18:09 omy Status tested => verified
2013-07-12 18:09 omy Resolution open => fixed
2013-12-19 13:53 bugmaster Status verified => closed
2013-12-19 13:56 bugmaster Fixed in Version => 6.7.0