diff mbox

[rdma-core/rdma-ndd] Use integer as getopt_long returns integer

Message ID 1493099392-1883-1-git-send-email-honli@redhat.com (mailing list archive)
State Accepted
Headers show

Commit Message

Honggang LI April 25, 2017, 5:49 a.m. UTC
From: Honggang Li <honli@redhat.com>

ARM chars are unsigned by default. getopt_long return 255 instead -1.
That will cause an endless loop for aarch64 platform.

Signed-off-by: Honggang Li <honli@redhat.com>
---
 rdma-ndd/rdma-ndd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jason Gunthorpe April 25, 2017, 7:47 p.m. UTC | #1
On Tue, Apr 25, 2017 at 01:49:52PM +0800, Honggang LI wrote:
> From: Honggang Li <honli@redhat.com>
> 
> ARM chars are unsigned by default. getopt_long return 255 instead -1.
> That will cause an endless loop for aarch64 platform.
>
> Signed-off-by: Honggang Li <honli@redhat.com>

Yep

Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jonathan Toppins April 25, 2017, 8:10 p.m. UTC | #2
On 04/25/2017 01:49 AM, Honggang LI wrote:
> From: Honggang Li <honli@redhat.com>
> 
> ARM chars are unsigned by default. getopt_long return 255 instead -1.
> That will cause an endless loop for aarch64 platform.
> 
> Signed-off-by: Honggang Li <honli@redhat.com>
> ---
>  rdma-ndd/rdma-ndd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/rdma-ndd/rdma-ndd.c b/rdma-ndd/rdma-ndd.c
> index 1579a02..e7be22b 100644
> --- a/rdma-ndd/rdma-ndd.c
> +++ b/rdma-ndd/rdma-ndd.c
> @@ -297,7 +297,7 @@ int main(int argc, char *argv[])
>  			{ }
>  		};
>  
> -		char c = getopt_long(argc, argv, "fh", long_opts, &opt_idx);
> +		int c = getopt_long(argc, argv, "fh", long_opts, &opt_idx);
>  		if (c == -1)
>  			break;
>  
> 

int is the return type of the function signature anyway so this was
wrong from the start.

https://linux.die.net/man/3/getopt_long

Acked-by: Jonathan Toppins <jtoppins@redhat.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Leon Romanovsky April 26, 2017, 6:21 a.m. UTC | #3
On Tue, Apr 25, 2017 at 01:49:52PM +0800, Honggang LI wrote:
> From: Honggang Li <honli@redhat.com>
>
> ARM chars are unsigned by default. getopt_long return 255 instead -1.
> That will cause an endless loop for aarch64 platform.
>
> Signed-off-by: Honggang Li <honli@redhat.com>
> ---
>  rdma-ndd/rdma-ndd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/rdma-ndd/rdma-ndd.c b/rdma-ndd/rdma-ndd.c

Thanks, applied.
diff mbox

Patch

diff --git a/rdma-ndd/rdma-ndd.c b/rdma-ndd/rdma-ndd.c
index 1579a02..e7be22b 100644
--- a/rdma-ndd/rdma-ndd.c
+++ b/rdma-ndd/rdma-ndd.c
@@ -297,7 +297,7 @@  int main(int argc, char *argv[])
 			{ }
 		};
 
-		char c = getopt_long(argc, argv, "fh", long_opts, &opt_idx);
+		int c = getopt_long(argc, argv, "fh", long_opts, &opt_idx);
 		if (c == -1)
 			break;