diff --git a/src/histo_utils.cxx b/src/histo_utils.cxx
index 2b0f433777841a924d93df490711dca946c368e6..9944d359b02af4db0ff7fa1b6c5fab6c39b2cfb4 100644
--- a/src/histo_utils.cxx
+++ b/src/histo_utils.cxx
@@ -299,6 +299,12 @@ short get_elev_snowline_from_bin(const itk::Statistics::ImageToHistogramFilter<i
   idx4[1] = 1;
   idx4[2] = 1;
 
+  // Ensure that the current elevation is in the validity range. (nodata and/or inconsistent elevation)
+  if ( ( histogram->GetMeasurementVector(idx1)[0] < -413 ) && (histogram->GetMeasurementVector(idx1)[0] < 8850) )
+    {
+      return -1
+    }
+
   // Compute the total number of pixels on the altitude bin
   const HistogramType::AbsoluteFrequencyType tot_z=histogram->GetFrequency(idx1) + histogram->GetFrequency(idx2) + histogram->GetFrequency(idx3) + histogram->GetFrequency(idx4);