Skip to content

Commit

Permalink
Various cleanups based on static analysis (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaloney authored Dec 8, 2021
1 parent 2a5e0fa commit b811b72
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
.vscode
2 changes: 1 addition & 1 deletion src/CompressedVectorReaderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace e57
class CompressedVectorReaderImpl
{
public:
CompressedVectorReaderImpl( std::shared_ptr<CompressedVectorNodeImpl> ni, std::vector<SourceDestBuffer> &dbufs );
CompressedVectorReaderImpl( std::shared_ptr<CompressedVectorNodeImpl> cvi, std::vector<SourceDestBuffer> &dbufs );
~CompressedVectorReaderImpl();
unsigned read();
unsigned read( std::vector<SourceDestBuffer> &dbufs );
Expand Down
4 changes: 4 additions & 0 deletions src/E57Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,18 @@ namespace e57
os << " context: " << context_ << std::endl;
os << " sourceFunctionName: " << sourceFunctionName_ << std::endl;
if ( reportingFunctionName != nullptr )
{
os << " reportingFunctionName: " << reportingFunctionName << std::endl;
}

/*** Add a line in error message that a smart editor (gnu emacs) can
* interpret as a link to the source code: */
os << sourceFileName_ << "(" << sourceLineNumber_ << ") : error C" << errorCode_ << ": <--- occurred on"
<< std::endl;
if ( reportingFileName != nullptr )
{
os << reportingFileName << "(" << reportingLineNumber << ") : error C0: <--- reported on" << std::endl;
}
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions src/ImageFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ namespace e57
#ifdef E57_MAX_VERBOSE
std::cout << "pathNameParse returning: isRelative=" << isRelative << " fields.size()=" << fields.size()
<< " fields=";
for ( size_t i = 0; i < fields.size(); i++ )
for ( auto &field : fields )
{
std::cout << fields[i] << ",";
std::cout << field << ",";
}
std::cout << std::endl;
#endif
Expand Down
111 changes: 47 additions & 64 deletions src/ReaderImpl.cpp

Large diffs are not rendered by default.

50 changes: 23 additions & 27 deletions src/StructureNodeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,40 +161,36 @@ NodeImplSharedPtr StructureNodeImpl::lookup( const ustring &pathName )
{
return NodeImplSharedPtr(); /// empty pointer
}
else
{
NodeImplSharedPtr root( getRoot() );
return ( root );
}

NodeImplSharedPtr root( getRoot() );
return ( root );
}
else

/// Find child with elementName that matches first field in path
unsigned i;
for ( i = 0; i < children_.size(); i++ )
{
/// Find child with elementName that matches first field in path
unsigned i;
for ( i = 0; i < children_.size(); i++ )
{
if ( fields.at( 0 ) == children_.at( i )->elementName() )
{
break;
}
}
if ( i == children_.size() )
if ( fields.at( 0 ) == children_.at( i )->elementName() )
{
return NodeImplSharedPtr(); /// empty pointer
break;
}
}
if ( i == children_.size() )
{
return NodeImplSharedPtr(); /// empty pointer
}

if ( fields.size() == 1 )
{
return ( children_.at( i ) );
}
if ( fields.size() == 1 )
{
return ( children_.at( i ) );
}

//??? use level here rather than unparse
/// Remove first field in path
fields.erase( fields.begin() );
//??? use level here rather than unparse
/// Remove first field in path
fields.erase( fields.begin() );

/// Call lookup on child object with remaining fields in path name
return children_.at( i )->lookup( imf->pathNameUnparse( true, fields ) );
}
/// Call lookup on child object with remaining fields in path name
return children_.at( i )->lookup( imf->pathNameUnparse( true, fields ) );
}
else
{ /// Absolute pathname and we aren't at the root
Expand Down
30 changes: 13 additions & 17 deletions src/WriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ namespace e57
// TODO currently no support for handling UTC <-> GPS time conversions
// note that "creationDateTime" is optional in the standard
#if 0
StructureNode creationDateTime = StructureNode(imf_);
creationDateTime.set("dateTimeValue", FloatNode(imf_, GetGPSTime()));
creationDateTime.set("isAtomicClockReferenced", IntegerNode(imf_,0));
root_.set("creationDateTime", creationDateTime);
StructureNode creationDateTime = StructureNode(imf_);
creationDateTime.set("dateTimeValue", FloatNode(imf_, GetGPSTime()));
creationDateTime.set("isAtomicClockReferenced", IntegerNode(imf_,0));
root_.set("creationDateTime", creationDateTime);
#endif

root_.set( "data3D", data3D_ );
Expand Down Expand Up @@ -321,7 +321,7 @@ namespace e57
return pos;
}

// This function reads one of the image blobs
// This function writes one of the image blobs
int64_t WriterImpl::WriteImage2DNode( StructureNode image, Image2DType imageType, void *pBuffer, int64_t start,
int64_t count )
{
Expand Down Expand Up @@ -438,7 +438,7 @@ namespace e57
scan.set( "description", StringNode( imf_, data3DHeader.description ) );
}

if ( data3DHeader.originalGuids.size() > 0 )
if ( !data3DHeader.originalGuids.empty() )
{
scan.set( "originalGuids", VectorNode( imf_ ) );
VectorNode originalGuids( scan.get( "originalGuids" ) );
Expand Down Expand Up @@ -646,7 +646,7 @@ namespace e57

// data3DHeader.pointGroupingSchemes.groupingByLine.idElementName));
bool byColumn = true; // default should be "columnIndex"
if ( data3DHeader.pointGroupingSchemes.groupingByLine.idElementName.compare( "rowIndex" ) == 0 )
if ( data3DHeader.pointGroupingSchemes.groupingByLine.idElementName == "rowIndex" )
{
byColumn = false;
}
Expand Down Expand Up @@ -739,11 +739,9 @@ namespace e57
return ScaledIntegerNode( imf_, 0, pointRangeMinimum, pointRangeMaximum, pointRangeScale,
pointRangeOffset );
}
else
{
return FloatNode( imf_, 0., ( pointRangeScale < E57_NOT_SCALED_USE_FLOAT ) ? E57_DOUBLE : E57_SINGLE,
data3DHeader.pointFields.pointRangeMinimum, data3DHeader.pointFields.pointRangeMaximum );
}

return FloatNode( imf_, 0., ( pointRangeScale < E57_NOT_SCALED_USE_FLOAT ) ? E57_DOUBLE : E57_SINGLE,
data3DHeader.pointFields.pointRangeMinimum, data3DHeader.pointFields.pointRangeMaximum );
};

if ( data3DHeader.pointFields.cartesianXField )
Expand Down Expand Up @@ -777,11 +775,9 @@ namespace e57
{
return ScaledIntegerNode( imf_, 0, angleMinimum, angleMaximum, angleScale, angleOffset );
}
else
{
return FloatNode( imf_, 0., ( angleScale < E57_NOT_SCALED_USE_FLOAT ) ? E57_DOUBLE : E57_SINGLE,
data3DHeader.pointFields.angleMinimum, data3DHeader.pointFields.angleMaximum );
}

return FloatNode( imf_, 0., ( angleScale < E57_NOT_SCALED_USE_FLOAT ) ? E57_DOUBLE : E57_SINGLE,
data3DHeader.pointFields.angleMinimum, data3DHeader.pointFields.angleMaximum );
};

if ( data3DHeader.pointFields.sphericalAzimuthField )
Expand Down

0 comments on commit b811b72

Please sign in to comment.