[Liblas-commits] hg: error checking and casting for setting DOY and Year for header

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Oct 26 11:22:32 EDT 2010


changeset 6c885263069c in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=6c885263069c
summary: error checking and casting for setting DOY and Year for header

diffstat:

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

diffs (44 lines):

diff -r 974aab1b8277 -r 6c885263069c apps/laskernel.cpp
--- a/apps/laskernel.cpp	Tue Oct 26 09:46:37 2010 -0500
+++ b/apps/laskernel.cpp	Tue Oct 26 10:22:26 2010 -0500
@@ -926,14 +926,27 @@
             }            
         }
         
-        boost::uint32_t day = 0;
-        boost::uint32_t year = 0;
+        boost::int32_t day = 0;
+        boost::int32_t year = 0;
         
         
         if (creation.size() == 2) 
         {
             day = atoi(creation[0].c_str());
             year = atoi(creation[1].c_str());
+            
+            if (day < 0 || day > 366) {
+                ostringstream oss;
+                oss << "Day must be between 1-366, not " << day;
+                throw std::runtime_error(oss.str());
+            }
+            if (year < 0)
+            {
+                ostringstream oss;
+                oss << "Year must be greater than 0, not " << year;
+                throw std::runtime_error(oss.str());
+            }
+            
         }
         
         if (now == true) 
@@ -942,8 +955,8 @@
             header.SetCreationDOY(h.GetCreationDOY());
             header.SetCreationYear(h.GetCreationYear());
         } else {
-            header.SetCreationDOY(day);
-            header.SetCreationYear(year);
+            header.SetCreationDOY(static_cast<boost::uint16_t>(day));
+            header.SetCreationYear(static_cast<boost::uint16_t>(year));
             
         }
     }


More information about the Liblas-commits mailing list