SimpleShell: use strtol to check for valid line limit instead of int(atof(...))
authorMichael Moon <triffid.hunter@gmail.com>
Sun, 10 Feb 2013 03:01:20 +0000 (14:01 +1100)
committerMichael Moon <triffid.hunter@gmail.com>
Mon, 11 Feb 2013 03:25:32 +0000 (14:25 +1100)
src/modules/utils/simpleshell/SimpleShell.cpp

index d80cfd2..b948cbb 100644 (file)
@@ -95,7 +95,13 @@ void SimpleShell::cat_command( string parameters, StreamOutput* stream ){
     string filename          = this->absolute_from_relative(shift_parameter( parameters ));
     string limit_paramater   = shift_parameter( parameters );
     int limit = -1;
-    if( limit_paramater != "" ){ limit = int(atof(limit_paramater.c_str())); }
+    if( limit_paramater != "" )
+    {
+        char* e = NULL;
+        limit = strtol(limit_paramater.c_str(), &e, 10);
+        if (e <= limit_paramater.c_str())
+            limit = -1;
+    }
 
     // Open file
     FILE *lp = fopen(filename.c_str(), "r");