aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Ledford <dledford@redhat.com>2015-06-08 09:36:00 -0400
committerDoug Ledford <dledford@redhat.com>2015-06-08 09:36:00 -0400
commit252749ced9cacc991f116ebc99d4f5e4e15e55cc (patch)
tree03783887b43e0524db3b4ee2ad0dc35637079009
parent990ca025d0ad967b6f266bae700bf82a4ceaff1a (diff)
downloadlibibverbs-252749ced9cacc991f116ebc99d4f5e4e15e55cc.tar.gz
example: fix argiment processing
Various arguments that should be unsigned were signed, giving rise to the possiblity of people passing negative numbers when they intended to pass large positive numbers (this was mainly seen in real world usage with the size argument). Switch the args that are never legitimately negative to unsigned. Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r--examples/rc_pingpong.c20
-rw-r--r--examples/srq_pingpong.c28
-rw-r--r--examples/uc_pingpong.c20
-rw-r--r--examples/ud_pingpong.c18
4 files changed, 45 insertions, 41 deletions
diff --git a/examples/rc_pingpong.c b/examples/rc_pingpong.c
index a8637a5..ddfe8d0 100644
--- a/examples/rc_pingpong.c
+++ b/examples/rc_pingpong.c
@@ -552,12 +552,12 @@ int main(int argc, char *argv[])
struct timeval start, end;
char *ib_devname = NULL;
char *servername = NULL;
- int port = 18515;
+ unsigned int port = 18515;
int ib_port = 1;
- int size = 4096;
+ unsigned int size = 4096;
enum ibv_mtu mtu = IBV_MTU_1024;
- int rx_depth = 500;
- int iters = 1000;
+ unsigned int rx_depth = 500;
+ unsigned int iters = 1000;
int use_event = 0;
int routs;
int rcnt, scnt;
@@ -592,8 +592,8 @@ int main(int argc, char *argv[])
switch (c) {
case 'p':
- port = strtol(optarg, NULL, 0);
- if (port < 0 || port > 65535) {
+ port = strtoul(optarg, NULL, 0);
+ if (port > 65535) {
usage(argv[0]);
return 1;
}
@@ -605,14 +605,14 @@ int main(int argc, char *argv[])
case 'i':
ib_port = strtol(optarg, NULL, 0);
- if (ib_port < 0) {
+ if (ib_port < 1) {
usage(argv[0]);
return 1;
}
break;
case 's':
- size = strtol(optarg, NULL, 0);
+ size = strtoul(optarg, NULL, 0);
break;
case 'm':
@@ -624,11 +624,11 @@ int main(int argc, char *argv[])
break;
case 'r':
- rx_depth = strtol(optarg, NULL, 0);
+ rx_depth = strtoul(optarg, NULL, 0);
break;
case 'n':
- iters = strtol(optarg, NULL, 0);
+ iters = strtoul(optarg, NULL, 0);
break;
case 'l':
diff --git a/examples/srq_pingpong.c b/examples/srq_pingpong.c
index 552a144..f61acb0 100644
--- a/examples/srq_pingpong.c
+++ b/examples/srq_pingpong.c
@@ -624,13 +624,13 @@ int main(int argc, char *argv[])
struct timeval start, end;
char *ib_devname = NULL;
char *servername = NULL;
- int port = 18515;
+ unsigned int port = 18515;
int ib_port = 1;
- int size = 4096;
+ unsigned int size = 4096;
enum ibv_mtu mtu = IBV_MTU_1024;
- int num_qp = 16;
- int rx_depth = 500;
- int iters = 1000;
+ unsigned int num_qp = 16;
+ unsigned int rx_depth = 500;
+ unsigned int iters = 1000;
int use_event = 0;
int routs;
int rcnt, scnt;
@@ -668,8 +668,8 @@ int main(int argc, char *argv[])
switch (c) {
case 'p':
- port = strtol(optarg, NULL, 0);
- if (port < 0 || port > 65535) {
+ port = strtoul(optarg, NULL, 0);
+ if (port > 65535) {
usage(argv[0]);
return 1;
}
@@ -681,14 +681,18 @@ int main(int argc, char *argv[])
case 'i':
ib_port = strtol(optarg, NULL, 0);
- if (ib_port < 0) {
+ if (ib_port < 1) {
usage(argv[0]);
return 1;
}
break;
case 's':
- size = strtol(optarg, NULL, 0);
+ size = strtoul(optarg, NULL, 0);
+ if (size < 1) {
+ usage(argv[0]);
+ return 1;
+ }
break;
case 'm':
@@ -700,15 +704,15 @@ int main(int argc, char *argv[])
break;
case 'q':
- num_qp = strtol(optarg, NULL, 0);
+ num_qp = strtoul(optarg, NULL, 0);
break;
case 'r':
- rx_depth = strtol(optarg, NULL, 0);
+ rx_depth = strtoul(optarg, NULL, 0);
break;
case 'n':
- iters = strtol(optarg, NULL, 0);
+ iters = strtoul(optarg, NULL, 0);
break;
case 'l':
diff --git a/examples/uc_pingpong.c b/examples/uc_pingpong.c
index 58cc3cc..272dc26 100644
--- a/examples/uc_pingpong.c
+++ b/examples/uc_pingpong.c
@@ -539,12 +539,12 @@ int main(int argc, char *argv[])
struct timeval start, end;
char *ib_devname = NULL;
char *servername = NULL;
- int port = 18515;
+ unsigned int port = 18515;
int ib_port = 1;
- int size = 4096;
+ unsigned int size = 4096;
enum ibv_mtu mtu = IBV_MTU_1024;
- int rx_depth = 500;
- int iters = 1000;
+ unsigned int rx_depth = 500;
+ unsigned int iters = 1000;
int use_event = 0;
int routs;
int rcnt, scnt;
@@ -579,8 +579,8 @@ int main(int argc, char *argv[])
switch (c) {
case 'p':
- port = strtol(optarg, NULL, 0);
- if (port < 0 || port > 65535) {
+ port = strtoul(optarg, NULL, 0);
+ if (port > 65535) {
usage(argv[0]);
return 1;
}
@@ -592,14 +592,14 @@ int main(int argc, char *argv[])
case 'i':
ib_port = strtol(optarg, NULL, 0);
- if (ib_port < 0) {
+ if (ib_port < 1) {
usage(argv[0]);
return 1;
}
break;
case 's':
- size = strtol(optarg, NULL, 0);
+ size = strtoul(optarg, NULL, 0);
break;
case 'm':
@@ -611,11 +611,11 @@ int main(int argc, char *argv[])
break;
case 'r':
- rx_depth = strtol(optarg, NULL, 0);
+ rx_depth = strtoul(optarg, NULL, 0);
break;
case 'n':
- iters = strtol(optarg, NULL, 0);
+ iters = strtoul(optarg, NULL, 0);
break;
case 'l':
diff --git a/examples/ud_pingpong.c b/examples/ud_pingpong.c
index 9102241..6d32ced 100644
--- a/examples/ud_pingpong.c
+++ b/examples/ud_pingpong.c
@@ -563,11 +563,11 @@ int main(int argc, char *argv[])
struct timeval start, end;
char *ib_devname = NULL;
char *servername = NULL;
- int port = 18515;
+ unsigned int port = 18515;
int ib_port = 1;
- int size = 2048;
- int rx_depth = 500;
- int iters = 1000;
+ unsigned int size = 2048;
+ unsigned int rx_depth = 500;
+ unsigned int iters = 1000;
int use_event = 0;
int routs;
int rcnt, scnt;
@@ -602,7 +602,7 @@ int main(int argc, char *argv[])
switch (c) {
case 'p':
port = strtol(optarg, NULL, 0);
- if (port < 0 || port > 65535) {
+ if (port > 65535) {
usage(argv[0]);
return 1;
}
@@ -614,22 +614,22 @@ int main(int argc, char *argv[])
case 'i':
ib_port = strtol(optarg, NULL, 0);
- if (ib_port < 0) {
+ if (ib_port < 1) {
usage(argv[0]);
return 1;
}
break;
case 's':
- size = strtol(optarg, NULL, 0);
+ size = strtoul(optarg, NULL, 0);
break;
case 'r':
- rx_depth = strtol(optarg, NULL, 0);
+ rx_depth = strtoul(optarg, NULL, 0);
break;
case 'n':
- iters = strtol(optarg, NULL, 0);
+ iters = strtoul(optarg, NULL, 0);
break;
case 'l':