Skip to content

Commit 32d848c

Browse files
authored
Fix 32-bit build issues (asmaloney#234)
1 parent 0d3e964 commit 32d848c

10 files changed

+38
-12
lines changed

include/E57SimpleData.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,9 @@ namespace e57
611611
PointStandardizedFieldsAvailable pointFields;
612612

613613
/// The number of points in the Data3D.
614-
int64_t pointCount = 0;
614+
/// On 32-bit systems size_t will allow for 4,294,967,295 points per scan which seems
615+
/// reasonable...
616+
size_t pointCount = 0;
615617
};
616618

617619
/// @brief Stores pointers to user-provided buffers

include/E57SimpleReader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace e57
164164
/// "points" data vector for the groups
165165
/// @param [out] pointCount pointer to the buffer holding size of the groups given
166166
/// @return Return true if successful, false otherwise
167-
bool ReadData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue,
167+
bool ReadData3DGroupsData( int64_t dataIndex, size_t groupCount, int64_t *idElementValue,
168168
int64_t *startPointIndex, int64_t *pointCount ) const;
169169

170170
/// @brief Use this to read the actual 3D data

include/E57SimpleWriter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ namespace e57
177177
/// for the groups
178178
/// @param [in] pointCount buffer with sizes of the groups given
179179
/// @return Return true if successful, false otherwise
180-
bool WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue,
180+
bool WriteData3DGroupsData( int64_t dataIndex, size_t groupCount, int64_t *idElementValue,
181181
int64_t *startPointIndex, int64_t *pointCount );
182182

183183
///@}

src/Common.h

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
#define VALIDATE_BASIC ( E57_VALIDATION_LEVEL > VALIDATION_OFF )
5454
#define VALIDATE_DEEP ( E57_VALIDATION_LEVEL > VALIDATION_BASIC )
5555

56+
// Determine if we are building 32 or 64 bit
57+
#if SIZE_MAX == UINT32_MAX
58+
#define E57_32_BIT
59+
#elif SIZE_MAX == UINT64_MAX
60+
#define E57_64_BIT
61+
#endif
62+
5663
namespace e57
5764
{
5865
#define E57_EXCEPTION1( ecode ) \

src/E57SimpleReader.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ namespace e57
126126
bColumnIndex );
127127
}
128128

129-
bool Reader::ReadData3DGroupsData( int64_t dataIndex, int64_t groupCount,
130-
int64_t *idElementValue, int64_t *startPointIndex,
131-
int64_t *pointCount ) const
129+
bool Reader::ReadData3DGroupsData( int64_t dataIndex, size_t groupCount, int64_t *idElementValue,
130+
int64_t *startPointIndex, int64_t *pointCount ) const
132131
{
133132
return impl_->ReadData3DGroupsData( dataIndex, groupCount, idElementValue, startPointIndex,
134133
pointCount );

src/E57SimpleWriter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace
9090
( pointFields.timeMinimum == cMin ) && ( pointFields.timeMaximum == cMax );
9191

9292
// Now run through the points and set the things we need to
93-
for ( int64_t i = 0; i < ioData3DHeader.pointCount; ++i )
93+
for ( size_t i = 0; i < ioData3DHeader.pointCount; ++i )
9494
{
9595
if ( writePointRange && pointFields.cartesianXField )
9696
{
@@ -267,7 +267,7 @@ namespace e57
267267
return impl_->SetUpData3DPointsData( dataIndex, pointCount, buffers );
268268
}
269269

270-
bool Writer::WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount,
270+
bool Writer::WriteData3DGroupsData( int64_t dataIndex, size_t groupCount,
271271
int64_t *idElementValue, int64_t *startPointIndex,
272272
int64_t *pointCount )
273273
{

src/ReaderImpl.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,25 @@ namespace e57
627627
const StructureNode proto( points.prototype() );
628628

629629
data3DHeader.guid = StringNode( scan.get( "guid" ) ).value();
630+
631+
#ifdef E57_32_BIT
632+
// If we exceed the size_t max, only process the max (4,294,967,295 points).
633+
if ( points.childCount() > static_cast<int64_t>( std::numeric_limits<size_t>::max() ) )
634+
{
635+
data3DHeader.pointCount = std::numeric_limits<size_t>::max();
636+
637+
std::cout << "Warning (32-bit): Point count (" << points.childCount()
638+
<< ") exceeds storage capacity (" << std::numeric_limits<size_t>::max()
639+
<< "). Dropping " << points.childCount() - std::numeric_limits<size_t>::max()
640+
<< " points from scan." << std::endl;
641+
}
642+
else
643+
{
644+
data3DHeader.pointCount = static_cast<size_t>( points.childCount() );
645+
}
646+
#else
630647
data3DHeader.pointCount = points.childCount();
648+
#endif
631649

632650
if ( scan.isDefined( "name" ) )
633651
{
@@ -1478,7 +1496,7 @@ namespace e57
14781496
}
14791497

14801498
// Reads the group data
1481-
bool ReaderImpl::ReadData3DGroupsData( int64_t dataIndex, int64_t groupCount,
1499+
bool ReaderImpl::ReadData3DGroupsData( int64_t dataIndex, size_t groupCount,
14821500
int64_t *idElementValue, int64_t *startPointIndex,
14831501
int64_t *pointCount ) const
14841502
{

src/ReaderImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace e57
7272
int64_t &pointsSize, int64_t &groupsSize, int64_t &countSize,
7373
bool &bColumnIndex ) const;
7474

75-
bool ReadData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue,
75+
bool ReadData3DGroupsData( int64_t dataIndex, size_t groupCount, int64_t *idElementValue,
7676
int64_t *startPointIndex, int64_t *pointCount ) const;
7777

7878
template <typename COORDTYPE>

src/WriterImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ namespace e57
13081308
int64_t dataIndex, size_t pointCount, const Data3DPointsData_t<double> &buffers );
13091309

13101310
// This function writes out the group data
1311-
bool WriterImpl::WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount,
1311+
bool WriterImpl::WriteData3DGroupsData( int64_t dataIndex, size_t groupCount,
13121312
int64_t *idElementValue, int64_t *startPointIndex,
13131313
int64_t *pointCount )
13141314
{

src/WriterImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace e57
6161
CompressedVectorWriter SetUpData3DPointsData( int64_t dataIndex, size_t pointCount,
6262
const Data3DPointsData_t<COORDTYPE> &buffers );
6363

64-
bool WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue,
64+
bool WriteData3DGroupsData( int64_t dataIndex, size_t groupCount, int64_t *idElementValue,
6565
int64_t *startPointIndex, int64_t *pointCount );
6666

6767
StructureNode GetRawE57Root();

0 commit comments

Comments
 (0)