[PATCH 2/2] src/locktest: add missing struct cast with syscall getsockname()

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



The usage of variable 'myAddr' (struct sockaddr_in) is being casted into a
'struct sockaddr' when used with bind() and with connect().  This patch
adds that cast when used with getsockname() as well, otherwise we'll get the
following error:

locktest.c: In function 'main':
locktest.c:1155:39: error: passing argument 2 of 'getsockname' from incompatible pointer type [-Wincompatible-pointer-types]
 1155 |                 if (getsockname(s_fd, &myAddr, &addr_len)) {
      |                                       ^~~~~~~
      |                                       |
      |                                       struct sockaddr_in *
In file included from /usr/include/fortify/sys/socket.h:23,
                 from locktest.c:19:
/usr/include/sys/socket.h:391:23: note: expected 'struct sockaddr * restrict' but argument is of type 'struct sockaddr_in *'
  391 | int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict);
      |                       ^

Signed-off-by: Luis Henriques <luis@xxxxxxxxxx>
---
 src/locktest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/locktest.c b/src/locktest.c
index 0e7c3008d1d0..a6cf3b1d5a99 100644
--- a/src/locktest.c
+++ b/src/locktest.c
@@ -1152,7 +1152,7 @@ main(int argc, char *argv[])
 	if (port == 0) {
 	        socklen_t addr_len = sizeof(myAddr);
 
-		if (getsockname(s_fd, &myAddr, &addr_len)) {
+		if (getsockname(s_fd, (struct sockaddr *)&myAddr, &addr_len)) {
 		    perror("getsockname");
 		    exit(1);
 		}




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux