From e1a3fedd4e1e174d4df6e50b47ae624b1a7a87f0 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sat, 8 Apr 2017 10:42:39 -0400 Subject: [PATCH] Added overflow check in normalsDirectionCount --- modules/odm_25dmeshing/src/PlyInterpreter.cpp | 6 +++++- modules/odm_25dmeshing/src/PlyInterpreter.hpp | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/odm_25dmeshing/src/PlyInterpreter.cpp b/modules/odm_25dmeshing/src/PlyInterpreter.cpp index 888360f7..c8e7fc55 100644 --- a/modules/odm_25dmeshing/src/PlyInterpreter.cpp +++ b/modules/odm_25dmeshing/src/PlyInterpreter.cpp @@ -25,7 +25,11 @@ void PlyInterpreter::process_line(CGAL::Ply_reader& reader) { Point3 p(x, y, z); Vector3 n(nx, ny, nz); - zNormalsDirectionCount += nz >= 0 ? 1 : -1; + if (nz >= 0 && zNormalsDirectionCount < std::numeric_limits::max()){ + zNormalsDirectionCount++; + }else if (nz < 0 && zNormalsDirectionCount > std::numeric_limits::min()){ + zNormalsDirectionCount--; + } points.push_back(std::make_pair(p, n)); } diff --git a/modules/odm_25dmeshing/src/PlyInterpreter.hpp b/modules/odm_25dmeshing/src/PlyInterpreter.hpp index 79716fcc..f7b78478 100644 --- a/modules/odm_25dmeshing/src/PlyInterpreter.hpp +++ b/modules/odm_25dmeshing/src/PlyInterpreter.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -19,7 +20,7 @@ typedef std::pair Pwn; class PlyInterpreter { std::vector& points; - int zNormalsDirectionCount; + long zNormalsDirectionCount; public: PlyInterpreter (std::vector& points)