[Liblas-commits] hg: Replaced uint8_t with uint32_t for input of
Classification i...
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Aug 25 19:53:06 EDT 2010
changeset e830e28ab4d6 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=e830e28ab4d6
summary: Replaced uint8_t with uint32_t for input of Classification index. Larger type allows more robust validation and helps to avoid potential integer overflow. uint8_t left as Classification::GetClass return type according to the spec.
diffstat:
include/liblas/lasclassification.hpp | 19 +++++--------------
src/lasclassification.cpp | 24 +++++++++++++++++++-----
2 files changed, 24 insertions(+), 19 deletions(-)
diffs (117 lines):
diff -r 30eae0160989 -r e830e28ab4d6 include/liblas/lasclassification.hpp
--- a/include/liblas/lasclassification.hpp Wed Aug 25 23:31:37 2010 +0100
+++ b/include/liblas/lasclassification.hpp Thu Aug 26 00:52:52 2010 +0100
@@ -70,7 +70,7 @@
/// @note Currently, libLAS does not support classification based on table
/// stored in variable-length record. Only Standard ASPRS classification
/// table is supported.
- static std::size_t const class_table_size;
+ static boost::uint32_t const class_table_size;
/// Values of indexes in the set of bit flags.
enum BitPosition
@@ -106,7 +106,7 @@
/// @param k [in] - If set, this point is considered to be a model keypoint and
/// thus generally should not be withheld in a thinning algorithm.
/// @param w [in] - If set, this point should not be included in processing.
- Classification(boost::uint8_t cls, bool s, bool k, bool w)
+ Classification(boost::uint32_t cls, bool s, bool k, bool w)
{
SetClass(cls);
SetSynthetic(s);
@@ -123,7 +123,7 @@
/// Assignment operator.
Classification& operator=(Classification const& rhs)
{
- if (&rhs != this )
+ if (&rhs != this)
{
m_flags = rhs.m_flags;
}
@@ -155,7 +155,7 @@
/// table is supported.
/// @exception Theoretically, may throw std::out_of_range in case index
/// value is not in range between 0 and class_table_size - 1.
- void SetClass(boost::uint8_t index);
+ void SetClass(boost::uint32_t index);
/// Sets if this point was created by a technique other than LIDAR
/// collection such as digitized from a photogrammetric stereo model.
@@ -207,16 +207,7 @@
bitset_type m_flags;
- void check_class_index(std::size_t index) const
- {
- if (index > (class_table_size - 1))
- {
- std::ostringstream msg;
- msg << "given index is " << index
- << ", but must fit between 0 and " << (class_table_size - 1);
- throw std::out_of_range(msg.str());
- }
- }
+ void check_class_index(boost::uint32_t index) const;
};
/// Equal-to operator implemented in terms of Classification::equal.
diff -r 30eae0160989 -r e830e28ab4d6 src/lasclassification.cpp
--- a/src/lasclassification.cpp Wed Aug 25 23:31:37 2010 +0100
+++ b/src/lasclassification.cpp Thu Aug 26 00:52:52 2010 +0100
@@ -45,6 +45,7 @@
#include <boost/cstdint.hpp>
// std
#include <cstddef>
+#include <limits>
#include <string>
using namespace boost;
@@ -91,11 +92,11 @@
namespace liblas {
-std::size_t const Classification::class_table_size = detail::static_array_size(g_class_names);
+uint32_t const Classification::class_table_size = detail::static_array_size(g_class_names);
std::string Classification::GetClassName() const
{
- std::size_t const index = GetClass();
+ uint32_t const index = GetClass();
check_class_index(index);
return g_class_names[index];
@@ -121,13 +122,14 @@
#endif
bits &= mask;
- uint8_t const index = static_cast<uint8_t>(bits.to_ulong());
+ uint32_t const index = static_cast<uint32_t>(bits.to_ulong());
assert(index < class_table_size);
+ assert(index <= std::numeric_limits<uint8_t>::max());
- return index;
+ return static_cast<uint8_t>(index);
}
-void Classification::SetClass(uint8_t index)
+void Classification::SetClass(uint32_t index)
{
check_class_index(index);
@@ -139,4 +141,16 @@
m_flags &= ~mask;
m_flags |= mask & binval;
}
+
+void Classification::check_class_index(boost::uint32_t index) const
+{
+ if (index > class_table_size - 1 || !(index <= std::numeric_limits<uint8_t>::max()))
+ {
+ std::ostringstream msg;
+ msg << "given index is " << index
+ << ", but must fit between 0 and " << (class_table_size - 1);
+ throw std::out_of_range(msg.str());
+ }
+}
+
} // namespace liblas
More information about the Liblas-commits
mailing list