From 9a5eac3c5935954c9b8d6a8fbe6f1172a3c2d482 Mon Sep 17 00:00:00 2001
From: Scott Giese <scttgs0@gmail.com>
Date: Tue, 29 Jan 2019 23:07:35 -0600
Subject: [PATCH] Reduce technical debt

---
 src/Airports/GenAirports850/airport.cxx       | 95 ++++---------------
 src/Airports/GenAirports850/airport.hxx       |  5 +-
 src/Airports/GenAirports850/beznode.hxx       | 44 +++------
 src/Airports/GenAirports850/closedpoly.cxx    |  4 +-
 src/Airports/GenAirports850/lights.cxx        | 11 +--
 src/Airports/GenAirports850/linearfeature.cxx |  6 +-
 src/Airports/GenAirports850/linearfeature.hxx |  4 +-
 src/Lib/DEM/dem.cxx                           | 35 ++++---
 src/Lib/DEM/dem.hxx                           |  2 +-
 src/Lib/HGT/dted.cxx                          |  6 +-
 src/Lib/HGT/dted.hxx                          |  2 +-
 src/Lib/HGT/hgt.cxx                           |  3 +-
 src/Lib/HGT/hgt.hxx                           |  2 +-
 src/Lib/HGT/srtmbase.cxx                      |  4 -
 src/Lib/HGT/srtmbase.hxx                      | 15 ++-
 src/Lib/landcover/landcover.hxx               |  2 +-
 src/Lib/landcover/test-landcover.cxx          |  2 +-
 src/Lib/terragear/clipper.cpp                 | 14 ++-
 src/Lib/terragear/clipper.hpp                 |  6 +-
 src/Lib/terragear/tg_surface.hxx              | 14 +--
 src/Lib/terragear/tg_unique_geod.hxx          |  2 +-
 src/Prep/Terra/Vec2.h                         |  2 +-
 src/Prep/Terra/Vec3.h                         |  2 +-
 src/Prep/Terra/xterra.cc                      |  7 +-
 24 files changed, 111 insertions(+), 178 deletions(-)

diff --git a/src/Airports/GenAirports850/airport.cxx b/src/Airports/GenAirports850/airport.cxx
index 6582a7d7..c809f085 100644
--- a/src/Airports/GenAirports850/airport.cxx
+++ b/src/Airports/GenAirports850/airport.cxx
@@ -93,60 +93,17 @@ Airport::Airport( int c, char* def)
 
 Airport::~Airport()
 {
-    for (auto feature : features)
-    {
-        feature = nullptr;
-    }
-
-    for (auto helipad : helipads)
-    {
-        helipad = nullptr;
-    }
-
-    for (auto runway : runways)
-    {
-        runway = nullptr;
-    }
-
-    for (auto waterrunway : waterrunways)
-    {
-        waterrunway = nullptr;
-    }
-
-    for (auto pavement : pavements)
-    {
-        pavement = nullptr;
-    }
-
-    for (auto taxiway : taxiways)
-    {
-        taxiway = nullptr;
-    }
-
-    for (auto lightobject : lightobjects)
-    {
-        lightobject = nullptr;
-    }
-
-    for (auto windsock : windsocks)
-    {
-        windsock = nullptr;
-    }
-
-    for (auto beacon : beacons)
-    {
-        beacon = nullptr;
-    }
-
-    for (auto sign : signs)
-    {
-        sign = nullptr;
-    }
-
-    for (auto boundaryItem : boundary)
-    {
-        boundaryItem = nullptr;
-    }
+    std::fill(features.begin(), features.end(), nullptr);
+    std::fill(helipads.begin(), helipads.end(), nullptr);
+    std::fill(runways.begin(), runways.end(), nullptr);
+    std::fill(waterrunways.begin(), waterrunways.end(), nullptr);
+    std::fill(pavements.begin(), pavements.end(), nullptr);
+    std::fill(taxiways.begin(), taxiways.end(), nullptr);
+    std::fill(lightobjects.begin(), lightobjects.end(), nullptr);
+    std::fill(windsocks.begin(), windsocks.end(), nullptr);
+    std::fill(beacons.begin(), beacons.end(), nullptr);
+    std::fill(signs.begin(), signs.end(), nullptr);
+    std::fill(boundary.begin(), boundary.end(), nullptr);
 }
 
 bool Airport::isDebugRunway( int rwy )
@@ -813,7 +770,6 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
     group_list strips_tc; strips_tc.clear();
     string_list strip_materials; strip_materials.clear();
 
-    int index;
     int_list pt_v, tri_v, strip_v;
     int_list pt_n, tri_n, strip_n;
     int_list tri_tc, strip_tc;
@@ -837,9 +793,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
             sgboTri.material = material;
      
             for (int l = 0; l < 3; ++l) {
-                int index;
-                        
-                index = nodes.add( poly.GetTriNode( i, l ) );
+                int index = nodes.add( poly.GetTriNode( i, l ) );
                 sgboTri.v_list.push_back( index );
                         
                 // use 'the' normal
@@ -868,9 +822,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
             sgboTri.material = material;
      
             for (int l = 0; l < 3; ++l) {
-                int index;
-        
-                index = nodes.add( poly.GetTriNode( i, l ) );                
+                int index = nodes.add( poly.GetTriNode( i, l ) );                
                 sgboTri.v_list.push_back( index );
                         
                 // use 'the' normal
@@ -899,9 +851,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
             sgboTri.material = material;
      
             for (int l = 0; l < 3; ++l) {
-                int index;
-                        
-                index = nodes.add( poly.GetTriNode( i, l ) );                
+                int index = nodes.add( poly.GetTriNode( i, l ) );                
                 sgboTri.v_list.push_back( index );
                         
                 // use 'the' normal
@@ -924,9 +874,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
         sgboTri.material = material;
                     
         for (int l = 0; l < 3; ++l) {
-            int index;
-                        
-            index = nodes.add( base_poly.GetTriNode( k, l ) );            
+            int index = nodes.add( base_poly.GetTriNode( k, l ) );            
             sgboTri.v_list.push_back( index );
                         
             // use 'the' normal
@@ -947,7 +895,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
     {
         for ( unsigned int j = 0; j < divided_base.ContourSize( i ); ++j )
         {
-            index = nodes.add( divided_base.GetNode(i, j) );
+            int index = nodes.add( divided_base.GetNode(i, j) );
             TG_LOG(SG_GENERAL, SG_DEBUG, "added base point " << divided_base.GetNode(i, j) << " at " << index );
         }
     }
@@ -1080,9 +1028,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
                    
             for ( unsigned int j = 0; j < rwy_lights[i].ContourSize(); ++j )
             {
-                int index;
-                       
-                index = nodes.add( rwy_lights[i].GetPosition(j) );
+                int index = nodes.add( rwy_lights[i].GetPosition(j) );
                 sgboPt.v_list.push_back( index );
                         
                 index = normals.add( rwy_lights[i].GetNormal(j) );
@@ -1157,7 +1103,6 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
     }
 #endif
 
-    SGGeod ref_geod;
     // calc elevations and write out windsock references
     TG_LOG(SG_GENERAL, SG_DEBUG, "Computing windsock node elevations");
 
@@ -1181,7 +1126,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
     // write out beacon references
     for ( unsigned int i = 0; i < beacons.size(); ++i )
     {
-        ref_geod = beacons[i]->GetLoc();
+        SGGeod ref_geod = beacons[i]->GetLoc();
         ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) );
 
         write_index_object_shared( objpath, b, ref_geod,
@@ -1192,7 +1137,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
     // write out taxiway signs references
     for ( unsigned int i = 0; i < signs.size(); ++i )
     {
-        ref_geod = signs[i]->GetLoc();
+        SGGeod ref_geod = signs[i]->GetLoc();
         ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) );
         write_index_object_sign( objpath, b, ref_geod,
                                 signs[i]->GetDefinition(),
@@ -1207,7 +1152,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
 
         for ( unsigned int j = 0; j < buoys.GetSize(); ++j )
         {
-            ref_geod = buoys.GetNode(j);
+            SGGeod ref_geod = buoys.GetNode(j);
             ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) );
             write_index_object_shared( objpath, b, ref_geod,
                                       "Models/Airport/water_rw_buoy.xml",
diff --git a/src/Airports/GenAirports850/airport.hxx b/src/Airports/GenAirports850/airport.hxx
index 11064043..da40b561 100644
--- a/src/Airports/GenAirports850/airport.hxx
+++ b/src/Airports/GenAirports850/airport.hxx
@@ -59,10 +59,7 @@ public:
 
     void AddFeatures( FeatureList feature_list )
     {
-        for (auto feature : feature_list)
-        {
-            features.push_back( feature );
-        }
+        std::copy( feature_list.begin(), feature_list.end(), features.begin() );
     }
 
     int NumFeatures( void )
diff --git a/src/Airports/GenAirports850/beznode.hxx b/src/Airports/GenAirports850/beznode.hxx
index 26f6d2e7..92d08608 100644
--- a/src/Airports/GenAirports850/beznode.hxx
+++ b/src/Airports/GenAirports850/beznode.hxx
@@ -120,10 +120,9 @@ inline double CalculateTheta( const SGVec3d& dirCur, const SGVec3d& dirNext, con
 class BezNode 
 {
 public:
-    explicit BezNode( SGGeod l )
+    explicit BezNode( SGGeod l ) :
+        loc(l)
     {
-        loc   = l;
-
         has_prev_cp = false;
         has_next_cp = false;
 
@@ -133,28 +132,18 @@ public:
         close = false;
     }
 
-    BezNode( double lat, double lon )
+    BezNode( double lat, double lon ) :
+        BezNode(SGGeod::fromDeg(lon, lat))
     {
-        loc   = SGGeod::fromDeg( lon, lat );
-
-        has_prev_cp = false;
-        has_next_cp = false;
-
-        mark  = 0;
-        light = 0;
-        term  = false;
-        close = false;
     }
 
-    BezNode( SGGeod l, SGGeod cp )
+    BezNode( SGGeod l, SGGeod cp ) :
+        loc(l),
+        prev_cp(Mirror(cp)),
+        next_cp(cp)
     {
-        loc     = l;
-
-        next_cp = cp;
-        has_next_cp = true;
-
-        prev_cp = Mirror(cp);
         has_prev_cp = true;
+        has_next_cp = true;
 
         mark    = 0;
         light   = 0;
@@ -162,20 +151,9 @@ public:
         close   = false;
     }
 
-    BezNode( double lat, double lon, double cp_lat, double cp_lon )
+    BezNode( double lat, double lon, double cp_lat, double cp_lon ) :
+        BezNode(SGGeod::fromDeg(lon, lat), SGGeod::fromDeg(cp_lon, cp_lat))
     {
-        loc     = SGGeod::fromDeg( lon, lat );
-
-        next_cp = SGGeod::fromDeg( cp_lon, cp_lat );
-        has_next_cp = true;
-
-        prev_cp = Mirror( next_cp );
-        has_prev_cp = true;
-
-        mark    = 0;
-        light   = 0;
-        term    = false;
-        close   = false;
     }
 
     SGGeod Mirror( const SGGeod& pt )
diff --git a/src/Airports/GenAirports850/closedpoly.cxx b/src/Airports/GenAirports850/closedpoly.cxx
index c3df2504..bb538ff6 100644
--- a/src/Airports/GenAirports850/closedpoly.cxx
+++ b/src/Airports/GenAirports850/closedpoly.cxx
@@ -136,7 +136,7 @@ void ClosedPoly::ConvertContour( const BezContour& src, tgContour& dst )
     dst.Erase();
 
     // iterate through each bezier node in the contour
-    for (unsigned int i = 0; i <= src.size()-1; i++)
+    for (unsigned int i = 0; i < src.size(); ++i)
     {
         TG_LOG(SG_GENERAL, SG_DEBUG, "\nHandling Node " << i << "\n\n");
 
@@ -147,7 +147,7 @@ void ClosedPoly::ConvertContour( const BezContour& src, tgContour& dst )
         }
         else
         {
-            // for the last node, next is the first. as all contours are closed
+            // for the last node, next is the first node, as all contours are closed
             nextNode = src.at(0);
         }
 
diff --git a/src/Airports/GenAirports850/lights.cxx b/src/Airports/GenAirports850/lights.cxx
index fc9edbf2..d08b9951 100644
--- a/src/Airports/GenAirports850/lights.cxx
+++ b/src/Airports/GenAirports850/lights.cxx
@@ -402,7 +402,6 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip )
 {
     tgLightContour w_lights;
     tgLightContour r_lights;
-    int i, j;
     string flag;
 
     SGVec3f normal = gen_runway_light_vector( 3.0, recip );
@@ -438,9 +437,7 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip )
 
     // first set of single lights
     pt = ref;
-    for ( i = 0; i < count; ++i ) {
-
-
+    for ( int i = 0; i < count; ++i ) {
         // centre lights
         pt = SGGeodesy::direct(pt, length_hdg, -vert_space);
 
@@ -529,7 +526,7 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip )
     int num_lights = 0;
 
     // draw nice crossbars
-    for ( i = 0; i < 5; i++ ) {
+    for ( int i = 0; i < 5; ++i ) {
         switch ( i ) {
             case 0:
                 num_lights = 4;
@@ -549,14 +546,14 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip )
         }
 
         pt = crossbar[i];
-        for ( j = 0 ; j < num_lights; j++ ) {
+        for ( int j = 0 ; j < num_lights; ++j ) {
             // left side lights
             pt = SGGeodesy::direct(pt, left_hdg, horiz_space);
             w_lights.AddLight(pt, normal);
         }
 
         pt = crossbar[i];
-        for ( j = 0; j < num_lights; j++ ) {
+        for ( int j = 0; j < num_lights; ++j ) {
             // right side lights
             pt = SGGeodesy::direct(pt, left_hdg, -horiz_space);
             w_lights.AddLight(pt, normal);
diff --git a/src/Airports/GenAirports850/linearfeature.cxx b/src/Airports/GenAirports850/linearfeature.cxx
index 72232d55..622eec97 100644
--- a/src/Airports/GenAirports850/linearfeature.cxx
+++ b/src/Airports/GenAirports850/linearfeature.cxx
@@ -28,17 +28,17 @@ void LinearFeature::ConvertContour( const BezContour& src, bool closed )
     points.Erase();
 
     // iterate through each bezier node in the contour
-    for (unsigned int i = 0; i <= src.size() - 1; ++i)
+    for (unsigned int i = 0; i < src.size(); ++i)
     {
         curNode = src.at(i);
 
         if (i < src.size() - 1)
         {
-            nextNode = src.at(i+1);
+            nextNode = src.at(i + 1);
         }
         else
         {
-            // for the last node, next is the first. as all contours are closed
+            // for the last node, next is the first node, as all contours are closed
             nextNode = src.at(0);
         }
 
diff --git a/src/Airports/GenAirports850/linearfeature.hxx b/src/Airports/GenAirports850/linearfeature.hxx
index 74054be8..4ccc34a0 100644
--- a/src/Airports/GenAirports850/linearfeature.hxx
+++ b/src/Airports/GenAirports850/linearfeature.hxx
@@ -78,12 +78,12 @@ public:
     }
 
     LinearFeature( const std::string& desc, double o ) :
-        offset(o),
-        width(0),
         cur_mark(nullptr),
         cur_light(nullptr),
         description(desc)
     {
+        offset = o;
+        width = 0;
     }
 
     ~LinearFeature();
diff --git a/src/Lib/DEM/dem.cxx b/src/Lib/DEM/dem.cxx
index 42f7589b..b55ffa23 100644
--- a/src/Lib/DEM/dem.cxx
+++ b/src/Lib/DEM/dem.cxx
@@ -38,19 +38,33 @@ using std::string;
 
 
 TGDem::TGDem() :
-    z_units(2)                  // meters
+    in(nullptr),
+    dem_data(new float[DEM_SIZE_1][DEM_SIZE_1]),
+    output_data(new float[DEM_SIZE_1][DEM_SIZE_1]),
+    dem_description(""),
+    dem_quadrangle(""),
+    option_name("")
 {
-    // cout << "class TGDem CONstructor called." << endl;
-    dem_data = new float[DEM_SIZE_1][DEM_SIZE_1];
-    output_data = new float[DEM_SIZE_1][DEM_SIZE_1];
+    originx = originy = 0.0;
+    cols =rows = 0;
+    col_step = row_step = 0.0;
+    dem_x1 = dem_x2 = dem_x3 = dem_x4 = 0.0;
+    dem_y1 = dem_y2 = dem_y3 = dem_y4 = 0.0;
+    dem_z1 = dem_z2 = 0.0;
+    dem_resolution = dem_num_profiles = 0;
+    prof_col = prof_row = 0;
+    prof_num_cols = prof_num_rows = 0;
+    prof_x1 = prof_y1 = 0.0;
+    prof_data = 0.0;
+    do_data = 0;
+    cur_col = cur_row = 0;
+    z_units = 2;    // meters
 }
 
 
-TGDem::TGDem( const string &file ) {
-    // cout << "class TGDem CONstructor called." << endl;
-    dem_data = new float[DEM_SIZE_1][DEM_SIZE_1];
-    output_data = new float[DEM_SIZE_1][DEM_SIZE_1];
-
+TGDem::TGDem( const string &file ) :
+    TGDem::TGDem()
+{
     TGDem::open(file);
 }
 
@@ -150,7 +164,6 @@ TGDem::next_exp() {
 bool
 TGDem::read_a_record() {
     int i, inum;
-    double dnum;
     string name, token, buf;
     char c;
 
@@ -187,7 +200,7 @@ TGDem::read_a_record() {
 
     // Map projection parameters (ignored)
     for ( i = 0; i < 15; i++ ) {
-        dnum = next_exp();
+        double dnum = next_exp();
         SG_LOG(SG_GENERAL, SG_DEBUG, i << ": "  << dnum);
     }
 
diff --git a/src/Lib/DEM/dem.hxx b/src/Lib/DEM/dem.hxx
index c0ee2578..ff02b3bc 100644
--- a/src/Lib/DEM/dem.hxx
+++ b/src/Lib/DEM/dem.hxx
@@ -95,7 +95,7 @@ public:
 
     // Constructor
     TGDem();
-    TGDem( const std::string& file );
+    explicit TGDem( const std::string& file );
 
     // Destructor
     ~TGDem();
diff --git a/src/Lib/HGT/dted.cxx b/src/Lib/HGT/dted.cxx
index 56700c08..5f71887f 100644
--- a/src/Lib/HGT/dted.cxx
+++ b/src/Lib/HGT/dted.cxx
@@ -47,7 +47,6 @@
 #include <simgear/misc/sg_dir.hxx>
 #include <simgear/debug/logstream.hxx>
 
-
 #include "dted.hxx"
 
 using std::cout;
@@ -64,9 +63,9 @@ TGDted::TGDted( int _res )
 }
 
 
-TGDted::TGDted( int _res, const SGPath &file ):TGDted(_res)
+TGDted::TGDted( int _res, const SGPath &file ) :
+    TGDted(_res)
 {
-
     TGDted::open( file );
 }
 
@@ -224,7 +223,6 @@ TGDted::load( ) {
 }
 
 
-
 TGDted::~TGDted() {
     // printf("class TGSrtmBase DEstructor called.\n");
     delete [] data;
diff --git a/src/Lib/HGT/dted.hxx b/src/Lib/HGT/dted.hxx
index fbd2d426..582f46ba 100644
--- a/src/Lib/HGT/dted.hxx
+++ b/src/Lib/HGT/dted.hxx
@@ -60,7 +60,7 @@ public:
 
     // Constructor, _res must be either "1" for the 1arcsec data or
     // "3" for the 3arcsec data.
-    TGDted( int _res );
+    explicit TGDted( int _res );
     TGDted( int _res, const SGPath &file );
 
     // Destructor
diff --git a/src/Lib/HGT/hgt.cxx b/src/Lib/HGT/hgt.cxx
index f768b031..d45615e0 100644
--- a/src/Lib/HGT/hgt.cxx
+++ b/src/Lib/HGT/hgt.cxx
@@ -62,7 +62,8 @@ TGHgt::TGHgt( int _res )
 }
 
 
-TGHgt::TGHgt( int _res, const SGPath &file ) : TGHgt( _res )
+TGHgt::TGHgt( int _res, const SGPath &file ) :
+    TGHgt( _res )
 {
     TGHgt::open( file );
 }
diff --git a/src/Lib/HGT/hgt.hxx b/src/Lib/HGT/hgt.hxx
index afd7026f..4784820a 100644
--- a/src/Lib/HGT/hgt.hxx
+++ b/src/Lib/HGT/hgt.hxx
@@ -59,7 +59,7 @@ public:
 
     // Constructor, _res must be either "1" for the 1arcsec data or
     // "3" for the 3arcsec data.
-    TGHgt( int _res );
+    explicit TGHgt( int _res );
     TGHgt( int _res, const SGPath &file );
 
     // Destructor
diff --git a/src/Lib/HGT/srtmbase.cxx b/src/Lib/HGT/srtmbase.cxx
index 947a5a45..e2b76eb4 100644
--- a/src/Lib/HGT/srtmbase.cxx
+++ b/src/Lib/HGT/srtmbase.cxx
@@ -21,10 +21,6 @@
 // $Id: hgt.cxx,v 1.7 2005-12-19 16:06:45 curt Exp $
 
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
 #include <iostream>
 #include <stdlib.h>
 #include <zlib.h>
diff --git a/src/Lib/HGT/srtmbase.hxx b/src/Lib/HGT/srtmbase.hxx
index 88849a8f..3f895675 100644
--- a/src/Lib/HGT/srtmbase.hxx
+++ b/src/Lib/HGT/srtmbase.hxx
@@ -24,10 +24,6 @@
 #ifndef _SRTMBASE_HXX
 #define _SRTMBASE_HXX
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
 #include <simgear/compiler.h>
 
 #include <simgear/bucket/newbucket.hxx>
@@ -36,8 +32,13 @@
 class TGSrtmBase {
 
 protected:
-    TGSrtmBase() : remove_tmp_file(false)
-    {}
+    TGSrtmBase() :
+        remove_tmp_file(false)
+    {
+        originx = originy = 0.0;
+        cols = rows = 0;
+        col_step = row_step = 0.0;
+    }
 
     ~TGSrtmBase();
 
@@ -83,5 +84,3 @@ public:
 
 
 #endif // _SRTMBASE_HXX
-
-
diff --git a/src/Lib/landcover/landcover.hxx b/src/Lib/landcover/landcover.hxx
index a6f72fcc..e32acf39 100644
--- a/src/Lib/landcover/landcover.hxx
+++ b/src/Lib/landcover/landcover.hxx
@@ -61,7 +61,7 @@ class LandCover {
 
 public:
 
-  LandCover( const std::string &filename );
+  explicit LandCover( const std::string &filename );
   virtual ~LandCover ();
 
   virtual int getValue (long x, long y) const;
diff --git a/src/Lib/landcover/test-landcover.cxx b/src/Lib/landcover/test-landcover.cxx
index ae54f3c1..19424312 100644
--- a/src/Lib/landcover/test-landcover.cxx
+++ b/src/Lib/landcover/test-landcover.cxx
@@ -40,7 +40,7 @@ main (int ac, const char * av[])
     int value = lu.getValue(lon, lat);
     cout << "Value is " << value 
 	 << " \"" << lu.getDescUSGS(value) << '"' << endl;
-  } catch (string e) {
+  } catch (const string& e) {
     cerr << "Died with exception: " << e << endl;
     return 1;
   }
diff --git a/src/Lib/terragear/clipper.cpp b/src/Lib/terragear/clipper.cpp
index ab91cc67..a6b8cf03 100644
--- a/src/Lib/terragear/clipper.cpp
+++ b/src/Lib/terragear/clipper.cpp
@@ -181,6 +181,8 @@ int PolyTree::Total() const
 
 PolyNode::PolyNode(): Parent(0), Index(0), m_IsOpen(false)
 {
+  m_jointype = JoinType::Square;
+  m_endtype = EndType::ClosedPolygon;
 }
 //------------------------------------------------------------------------------
 
@@ -718,7 +720,10 @@ void DisposeOutPts(OutPt*& pp)
 
 inline void InitEdge(TEdge* e, TEdge* eNext, TEdge* ePrev, const IntPoint& Pt)
 {
+  // Dx is explicitly being set due to memset not being portable for floating-point values
   std::memset(e, 0, sizeof(TEdge));
+  e->Dx = 0.0;
+
   e->Next = eNext;
   e->Prev = ePrev;
   e->Curr = Pt;
@@ -880,10 +885,13 @@ bool HorzSegmentsOverlap(cInt seg1a, cInt seg1b, cInt seg2a, cInt seg2b)
 // ClipperBase class methods ...
 //------------------------------------------------------------------------------
 
-ClipperBase::ClipperBase() //constructor
+ClipperBase::ClipperBase() :
+  m_ActiveEdges(nullptr)
 {
   m_CurrentLM = m_MinimaList.begin(); //begin() == end() here
   m_UseFullRange = false;
+  m_PreserveCollinear = false;
+  m_HasOpenPaths = false; 
 }
 //------------------------------------------------------------------------------
 
@@ -4199,13 +4207,13 @@ void ClipperOffset::DoRound(int j, int k)
   m_normals[k].X * m_normals[j].X + m_normals[k].Y * m_normals[j].Y);
   int steps = std::max((int)Round(m_StepsPerRad * std::fabs(a)), 1);
 
-  double X = m_normals[k].X, Y = m_normals[k].Y, X2;
+  double X = m_normals[k].X, Y = m_normals[k].Y;
   for (int i = 0; i < steps; ++i)
   {
     m_destPoly.push_back(IntPoint(
         Round(m_srcPoly[j].X + X * m_delta),
         Round(m_srcPoly[j].Y + Y * m_delta)));
-    X2 = X;
+    double X2 = X;
     X = X * m_cos - m_sin * Y;
     Y = X2 * m_sin + Y * m_cos;
   }
diff --git a/src/Lib/terragear/clipper.hpp b/src/Lib/terragear/clipper.hpp
index e0253e0d..ff34c225 100644
--- a/src/Lib/terragear/clipper.hpp
+++ b/src/Lib/terragear/clipper.hpp
@@ -118,7 +118,7 @@ struct DoublePoint
   double X;
   double Y;
   DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {}
-  DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {}
+  explicit DoublePoint(const IntPoint& ip) : X(ip.X), Y(ip.Y) {}
 };
 //------------------------------------------------------------------------------
 
@@ -263,7 +263,7 @@ protected:
 class Clipper : public virtual ClipperBase
 {
 public:
-  Clipper(int initOptions = 0);
+  explicit Clipper(int initOptions = 0);
   bool Execute(ClipType clipType,
       Paths &solution,
       PolyFillType fillType = PolyFillType::EvenOdd);
@@ -391,7 +391,7 @@ private:
 class clipperException : public std::exception
 {
   public:
-    clipperException(const char* description): m_descr(description) {}
+    explicit clipperException(const char* description): m_descr(description) {}
     virtual ~clipperException() throw() {}
     virtual const char* what() const throw() {return m_descr.c_str();}
   private:
diff --git a/src/Lib/terragear/tg_surface.hxx b/src/Lib/terragear/tg_surface.hxx
index 9e12a70e..608dfb66 100644
--- a/src/Lib/terragear/tg_surface.hxx
+++ b/src/Lib/terragear/tg_surface.hxx
@@ -53,10 +53,11 @@ public:
         //int index = ( row * _cols ) + col;
         if ( col < 0 || col >= _cols ) {
             SG_LOG(SG_GENERAL, SG_WARN, "column out of bounds on read (" << col << " >= " << _cols << ")");
-            int *p = 0; *p = 1; // force crash
-        } else if ( row < 0 || row >= _rows ) {
+            col = col < 0 ? 0 : _cols - 1;
+        }
+        else if ( row < 0 || row >= _rows ) {
             SG_LOG(SG_GENERAL, SG_WARN, "row out of bounds on read (" << row << " >= " << _rows << ")");
-            int *p = 0; *p = 1; // force crash
+            row = row < 0 ? 0 : _rows - 1;
         }
 
         return m[row][col];
@@ -66,10 +67,11 @@ public:
         //int index = ( row * _cols ) + col;
         if ( col < 0 || col >= _cols ) {
             SG_LOG(SG_GENERAL, SG_WARN,"column out of bounds on set (" << col << " >= " << _cols << ")");
-            int *p = 0; *p = 1; // force crash
-        } else if ( row < 0 || row >= _rows ) {
+            col = col < 0 ? 0 : _cols - 1;
+        }
+        else if ( row < 0 || row >= _rows ) {
             SG_LOG(SG_GENERAL, SG_WARN,"row out of bounds on set (" << row << " >= " << _rows << ")");
-            int *p = 0; *p = 1; // force crash
+            row = row < 0 ? 0 : _rows - 1;
         }
         m[row][col] = p;
     }
diff --git a/src/Lib/terragear/tg_unique_geod.hxx b/src/Lib/terragear/tg_unique_geod.hxx
index 323d872f..97bc9db4 100644
--- a/src/Lib/terragear/tg_unique_geod.hxx
+++ b/src/Lib/terragear/tg_unique_geod.hxx
@@ -27,7 +27,7 @@
 
 class SGGeodIndex {
 public:
-    SGGeodIndex( SGGeod g ) {
+    explicit SGGeodIndex( SGGeod g ) {
         geod = g;
 
         std::size_t FNV_prime;
diff --git a/src/Prep/Terra/Vec2.h b/src/Prep/Terra/Vec2.h
index 5c708a28..67fe9dc9 100644
--- a/src/Prep/Terra/Vec2.h
+++ b/src/Prep/Terra/Vec2.h
@@ -163,7 +163,7 @@ inline std::ostream& operator<<(std::ostream& out, const Vec2& v)
 
 inline std::istream& operator>>(std::istream& in, Vec2& v)
 {
-    char c;
+    char c = '\0';
     return in >> c >> v[0] >> v[1] >> c;
 }
 
diff --git a/src/Prep/Terra/Vec3.h b/src/Prep/Terra/Vec3.h
index 31b6741e..763c7040 100644
--- a/src/Prep/Terra/Vec3.h
+++ b/src/Prep/Terra/Vec3.h
@@ -174,7 +174,7 @@ inline std::ostream& operator<<(std::ostream& out, const Vec3& v)
 
 inline std::istream& operator>>(std::istream& in, Vec3& v)
 {
-    char c;
+    char c = '\0';
     return in >> c >> v[0] >> v[1] >> v[2] >> c;
 }
 
diff --git a/src/Prep/Terra/xterra.cc b/src/Prep/Terra/xterra.cc
index f0471012..470fa18e 100644
--- a/src/Prep/Terra/xterra.cc
+++ b/src/Prep/Terra/xterra.cc
@@ -4,15 +4,14 @@
 #include "gui.h"
 
 
-
-main(int argc, char **argv)
+int main(int argc, char **argv)
 {
     glutInit(&argc, argv);
     Terra::process_cmdline(argc, argv);
 
-
     Terra::gui_init();
 
-
     Terra::gui_interact();
+
+    return 0;
 }