Opened 8 years ago
Closed 8 years ago
#6535 closed defect (fixed)
HDF4 type sizes not safe
Reported by: | Kurt Schwehr | Owned by: | Kurt Schwehr |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | default | Version: | svn-trunk |
Severity: | normal | Keywords: | |
Cc: |
Description (last modified by )
The sizes of char, short, int and GBigInt are not a specific bit size, so this tries to make it a little bit more predictable for oddball build envs by using GByte, GInt16/GUInt16, GInt32/GUInt32. It also adds 2 static_asserts.
Thoughts?
-
hdf4dataset.cpp
298 298 299 299 double HDF4Dataset::AnyTypeToDouble( int32 iNumType, void *pData ) 300 300 { 301 CPL_STATIC_ASSERT(sizeof(GIntBig) == 8); 301 302 switch ( iNumType ) 302 303 { 303 304 case DFNT_INT8: 304 305 return static_cast<double>(*reinterpret_cast<char *>(pData)); 305 306 case DFNT_UINT8: 306 return static_cast<double> 307 (*reinterpret_cast<unsigned char *>(pData)); 307 return static_cast<double>(*reinterpret_cast<GByte *>(pData)); 308 308 case DFNT_INT16: 309 return static_cast<double>(*reinterpret_cast< short*>(pData));309 return static_cast<double>(*reinterpret_cast<GInt16 *>(pData)); 310 310 case DFNT_UINT16: 311 return static_cast<double> 312 (*reinterpret_cast<unsigned short *>(pData)); 311 return static_cast<double>(*reinterpret_cast<GUInt16 *>(pData)); 313 312 case DFNT_INT32: 314 return static_cast<double>(*reinterpret_cast< int*>(pData));313 return static_cast<double>(*reinterpret_cast<GInt32 *>(pData)); 315 314 case DFNT_UINT32: 316 return static_cast<double> 317 (*reinterpret_cast<unsigned int *>(pData)); 315 return static_cast<double>(*reinterpret_cast<GUInt32 *>(pData)); 318 316 case DFNT_INT64: 319 317 return static_cast<double>(*reinterpret_cast<GIntBig *>(pData)); 320 318 case DFNT_UINT64: 321 319
Change History (4)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Description: | modified (diff) |
---|---|
Status: | new → assigned |
comment:4 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
"sizeof(char) == 1" is guaranteed by the C/C++ standards as far as I recall.
As far as sizeof(GIntBig) == 8, I'm pretty sure there are a lot of places where this assumption would need to be true, so I'm not sure it's worth putting it in that particular place.
OK for other changes. (But GInt16 is just typedef short GInt16)