Fix for lp:1123153 (poor use of strtol).
[awesomized/libmemcached] / clients / memping.cc
index 983447f1c097765a5b15f82373cff473ebc8a3a8..39546d4f660be95d4bf994a8c6bf731e332c802f 100644 (file)
  */
 #include "mem_config.h"
 
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
 #include <getopt.h>
+#include <unistd.h>
+
 #include <libmemcached-1.0/memcached.h>
 #include <libmemcachedutil-1.0/util.h>
 #include "client_options.h"
@@ -139,11 +141,18 @@ void options_parse(int argc, char *argv[])
       break;
 
     case OPT_EXPIRE: /* --expire */
-      opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);
+      errno= 0;
+      opt_expire= time_t(strtoll(optarg, (char **)NULL, 10));
+      if (errno != 0)
+      {
+        std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::cerr;
+        exit(EXIT_FAILURE);
+      }
       break;
 
     case OPT_USERNAME:
       opt_username= optarg;
+      opt_binary= true;
       break;
 
     case OPT_PASSWD: