diff --git a/SystemTools.cxx b/SystemTools.cxx
index 04bcb86bf91fd25d9fcb7927b4022f29927a7cc3..d5616d919b2059c59598fc03255cf675858da3ca 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -3589,13 +3589,13 @@ bool SystemTools::GetLineFromStream(kwsys_ios::istream& is,
         }
       else
         {
-        leftToRead -= length;
+        leftToRead -= static_cast<long>(length);
         }
       }
 
     // Append the data read to the line.
     line.append(buffer);
-    sizeLimit -= length;
+    sizeLimit = sizeLimit - static_cast<long>(length);
     }
 
   // Return the results.