]> granicus.if.org Git - libevent/commitdiff
Cleanup on 7c11e51e1ab: fix strtol usage
authorNick Mathewson <nickm@torproject.org>
Sun, 28 Aug 2011 18:03:10 +0000 (14:03 -0400)
committerNick Mathewson <nickm@torproject.org>
Sun, 28 Aug 2011 18:03:10 +0000 (14:03 -0400)
test/bench_http.c

index 9fdd5aab23803fd10163650d187766fd70c04a0e..8180b267f2d07b81965307b51fc3ff76d265e0f6 100644 (file)
@@ -91,6 +91,7 @@ main(int argc, char **argv)
        int c;
        int use_iocp = 0;
        unsigned short port = 8080;
+       char *endptr = NULL;
 
 #ifdef WIN32
        WSADATA WSAData;
@@ -112,21 +113,24 @@ main(int argc, char **argv)
                }
 
                switch (c) {
-               char ** eptr;
                case 'p':
-                       port = (int)strtol(argv[i+1], eptr, 10);
-                       if (!(argv[i+1] && (**eptr == '\0'))) {
+                       if (i+1 >= argc || !argv[i+1]) {
+                               fprintf(stderr, "Missing port\n");
+                               exit(1);
+                       }
+                       port = (int)strtol(argv[i+1], &endptr, 10);
+                       if (*endptr != '\0') {
                                fprintf(stderr, "Bad port\n");
                                exit(1);
                        }
                        break;
                case 'l':
-                       content_len = (int)strtol(argv[i+1], eptr, 10);
-                       if (!(argv[i+1] && (**eptr == '\0'))) {
-                               fprintf(stderr, "Bad content length\n");
+                       if (i+1 >= argc || !argv[i+1]) {
+                               fprintf(stderr, "Missing content length\n");
                                exit(1);
                        }
-                       if (content_len == 0) {
+                       content_len = (size_t)strtol(argv[i+1], &endptr, 10);
+                       if (*endptr != '\0' || content_len == 0) {
                                fprintf(stderr, "Bad content length\n");
                                exit(1);
                        }