[Liblas-commits] hg: more error checking and appropriate casting of shorts

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Oct 26 11:29:56 EDT 2010


changeset 83a42a40ae96 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=83a42a40ae96
summary: more error checking and appropriate casting of shorts

diffstat:

 apps/laskernel.cpp |  30 ++++++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 4 deletions(-)

diffs (61 lines):

diff -r 6c885263069c -r 83a42a40ae96 apps/laskernel.cpp
--- a/apps/laskernel.cpp	Tue Oct 26 10:22:26 2010 -0500
+++ b/apps/laskernel.cpp	Tue Oct 26 10:29:51 2010 -0500
@@ -974,7 +974,7 @@
         
         if (vlrs.size() % 2 != 0) {
             ostringstream err;
-            err << "VLR descriptions must be in pairs of 2";
+            err << "VLR descriptions must be in pairs of 2 -- A name and an ID";
             throw std::runtime_error(err.str());
         }
         ostringstream oss;
@@ -993,7 +993,17 @@
         
         for (std::vector<std::string>::size_type i = 0; i < vlrs.size(); i=i+2)
         {
-            header.DeleteVLRs(vlrs[i], atoi(vlrs[i+1].c_str()));
+            boost::int32_t id = atoi(vlrs[i+1].c_str());
+            if (id < 0)
+            {
+                throw std::runtime_error("VLR ID must be > 0");
+            }
+            if (id > std::numeric_limits<boost::uint16_t>::max()) {
+                ostringstream oss;
+                oss << "ID must be less than "<< std::numeric_limits<boost::uint16_t>::max() <<", not " << id;
+                throw std::runtime_error(oss.str());
+            }
+            header.DeleteVLRs(vlrs[i], static_cast<boost::uint16_t>(id));
         }
     }
 
@@ -1022,7 +1032,19 @@
         
         liblas::VariableRecord v;
         v.SetUserId(vlrs[0]);
-        v.SetRecordId(atoi(vlrs[1].c_str()));
+
+        boost::int32_t id = atoi(vlrs[1].c_str());
+        if (id < 0)
+        {
+            throw std::runtime_error("VLR ID must be > 0");
+        }
+        if (id > std::numeric_limits<boost::uint16_t>::max()) {
+            ostringstream oss;
+            oss << "ID must be less than "<< std::numeric_limits<boost::uint16_t>::max() <<", not " << id;
+            throw std::runtime_error(oss.str());
+        }
+
+        v.SetRecordId(id);
         
         std::vector<boost::uint8_t> data;
         
@@ -1067,7 +1089,7 @@
 
 
         v.SetData(data);
-        v.SetRecordLength(data.size());
+        v.SetRecordLength(static_cast<boost::uint16_t>(data.size()));
         header.AddVLR(v);
     }
 


More information about the Liblas-commits mailing list