Bug #764
closedsscanf() does not support integer variables of a specific size
100%
Description
At various places in the DCMTK, sscanf() is used to convert character string into an integer value. The current approach...
Uint32 value = 0; #if SIZEOF_LONG == 8 if (sscanf(ptr, "%u", &value) == 1) #else if (sscanf(ptr, "%lu", &value) == 1) #endif
... is not 100% portable when the integer variable has a specific size (number of bits), e.g. Uint32 or Sint32. This first showed up on a 32-bit Linux (Debian) system. Not sure whether this only happens when C++11 support is enabled.
Maybe, there should be something like OFStandard::sscanUint32() and OFStandard::sscanSint32(), i.e. global functions that provide this functionality.
Updated by Marco Eichelberg over 7 years ago
- Target version changed from 3.6.3 to 3.6.6
Updated by Marco Eichelberg over 7 years ago
This is the list of sscanf related warnings in the (very long) log file:
dcmdata/libsrc/dcpath.cc:131:44: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'Uint32 {aka unsigned int}' [-Wformat=]
dcmdata/libsrc/dcpath.cc:294:41: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'Uint32 {aka unsigned int}' [-Wformat=]
dcmdata/libsrc/dcvris.cc:112:48: warning: format '%ld' expects argument of type 'long int*', but argument 3 has type 'Sint32* {aka int*}' [-Wformat=]
dcmdata/libsrc/dcvrsl.cc:191:53: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'Sint32 {aka int}' [-Wformat=]
dcmdata/libsrc/dcvrsl.cc:193:55: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'Sint32 {aka int}' [-Wformat=]
dcmdata/libsrc/dcvrsl.cc:336:56: warning: format '%ld' expects argument of type 'long int*', but argument 3 has type 'Sint32* {aka int*}' [-Wformat=]
dcmdata/libsrc/dcvrul.cc:190:53: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'Uint32 {aka unsigned int}' [-Wformat=]
dcmdata/libsrc/dcvrul.cc:192:55: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'Uint32 {aka unsigned int}' [-Wformat=]
dcmdata/libsrc/dcvrul.cc:335:56: warning: format '%lu' expects argument of type 'long unsigned int*', but argument 3 has type 'Uint32* {aka unsigned int*}' [-Wformat=]
dcmimage/libsrc/dicoimg.cc:580:54: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'Uint32 {aka unsigned int}' [-Wformat=]
dcmimgle/libsrc/dimoimg.cc:2025:50: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'Uint32 {aka unsigned int}' [-Wformat=]
dcmsr/libsrc/dsrimgfr.cc:134:41: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'int' [-Wformat=]
dcmsr/libsrc/dsrimgfr.cc:165:42: warning: format '%ld' expects argument of type 'long int*', but argument 3 has type 'Sint32* {aka int*}' [-Wformat=]
dcmsr/libsrc/dsrtcosp.cc:154:42: warning: format '%lu' expects argument of type 'long unsigned int*', but argument 3 has type 'Uint32* {aka unsigned int*}' [-Wformat=]
The essential compiler options used were:
c++ -DDCMTK_BUILD_IN_PROGRESS -DUSE_NULL_SAFE_OFSTRING -D_REENTRANT -Ddcmdata_EXPORTS
-g -O2 -fdebug-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time
-D_FORTIFY_SOURCE=2 -fvisibility=hidden -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_DEFAULT_SOURCE
-D_BSD_COMPAT -D_OSF_SOURCE -D_POSIX_C_SOURCE=199506L -std=c++11 -fPIC
Updated by Jörg Riesmeier about 7 years ago
Since C99, format constants are defined in "inttypes.h" that could be used for sscanf():
https://en.cppreference.com/w/c/types/integer#Format_constants_for_the_fscanf_family_of_functions
Updated by Jörg Riesmeier almost 7 years ago
- Status changed from New to Closed
- Assignee set to Jörg Riesmeier
- % Done changed from 0 to 100
Fixed with commit 386b588.