Patchwork [Open-FCoE,5/7] fcnsq: Fixup 64bit integer handling

login
register
mail settings
Submitter Hannes Reinecke
Date Dec. 6, 2013, 11:51 a.m.
Message ID <1386330717-15616-6-git-send-email-hare@suse.de>
Download mbox | patch
Permalink /patch/134/
State Accepted
Headers show

Comments

Hannes Reinecke - Dec. 6, 2013, 11:51 a.m.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 fcnsq.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Patch

diff --git a/fcnsq.c b/fcnsq.c
index 2510f1c..1597cd5 100644
--- a/fcnsq.c
+++ b/fcnsq.c
@@ -24,6 +24,7 @@ 
 #include <stdarg.h>
 #include <stdbool.h>
 #include <unistd.h>
+#include <inttypes.h>
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -228,7 +229,7 @@  static int gpn_id(int bsg, u32 fcid)
 	rjt = gn_id(bsg, fcid, FC_NS_GPN_ID, &wwpn);
 	if (rjt)
 		goto fail;
-	print_result("Port Name", "%16.16llx\n", wwpn);
+	print_result("Port Name", "%16.16jx\n", (uintmax_t)wwpn);
 	return 0;
 fail:
 	if (rjt == (u16) ~0)
@@ -249,7 +250,7 @@  static int gnn_id(int bsg, u32 fcid)
 	rjt = gn_id(bsg, fcid, FC_NS_GNN_ID, &wwnn);
 	if (rjt)
 		goto fail;
-	print_result("Node Name", "%16.16llx\n", wwnn);
+	print_result("Node Name", "%16.16jx\n", (uintmax_t)wwnn);
 	return 0;
 fail:
 	if (rjt == (u16) ~0)
@@ -376,11 +377,12 @@  int main(int argc, char *argv[])
 {
 	char *bsg;
 	int bsg_dev;
-	u32 port_id;
-	u64 wwnn;
+	u32 port_id = 0;
+	u64 wwnn = 0;
 	int rc = 0;
 	enum commands cmd = 0;
 	char c;
+	uintmax_t wwnn_tmp = 0;
 
 	while(1) {
 		c = getopt_long_only(argc, argv, "", options, NULL);
@@ -399,13 +401,17 @@  int main(int argc, char *argv[])
 			if (cmd)
 				help(-1);
 			cmd = c;
-			sscanf(optarg, "%x", &port_id);
+			if (sscanf(optarg, "%x", &port_id) != 1)
+				help(-1);
 			break;
 		case GSNN_NN:
 			if (cmd)
 				help(-1);
 			cmd = c;
-			sscanf(optarg, "%llx", &wwnn);
+			if (sscanf(optarg, "%jx", &wwnn_tmp) == 1)
+				wwnn = (u64)wwnn_tmp;
+			else
+				help(-1);
 			break;
 		}
 	}