Fix for lp:1123153 (poor use of strtol).
[awesomized/libmemcached] / clients / memping.cc
index bcc07cd3921397661ad44941a4cf9d2ec4c32a42..39546d4f660be95d4bf994a8c6bf731e332c802f 100644 (file)
@@ -1,4 +1,5 @@
 /* LibMemcached
+ * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
  * Copyright (C) 2006-2009 Brian Aker
  * All rights reserved.
  *
@@ -8,14 +9,16 @@
  * Summary:
  *
  */
-#include "config.h"
+#include "mem_config.h"
 
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
 #include <getopt.h>
-#include <libmemcached/memcached.h>
-#include <libmemcached/util.h>
+#include <unistd.h>
+
+#include <libmemcached-1.0/memcached.h>
+#include <libmemcachedutil-1.0/util.h>
 #include "client_options.h"
 #include "utilities.h"
 
@@ -138,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: