Skip to contentSkip to conversation

getport: Fix switch case on old compilers

PATCH In review Petr Vorel 2 participants 2 messages Aug 19 – Aug 31

Subsystems (2)
lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 getport: Fix switch case on old compilers

Buildroot distro compiles with fairly old compilers, which defaults to old C11 standard (some of still used compilers don't even have newer standard than C11). Workaround code which requires C23 with using { }.

This fixes error:

    getport.c:460:3: error: a label can only be part of a statement and a declaration is not a statement
       size_t path_len = len - offsetof(struct sockaddr_un, sun_path);
       ^~~~~~
Fixes 1a6dcd74 ("Removed warnings in nfs_sockaddr2universal()")

---
Steve, other option would be to use ';'. Not sure which one you prefer.

Found with Buildroot, which still uses:

$ aarch64-linux-gcc --version
aarch64-linux-gcc.br_real (Buildroot 2017.05) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
 support/nfs/getport.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
support/nfs/getport.c +2 -1
index 6bd2f713..18ea0777 100644
@@ -456,9 +456,10 @@ char *nfs_sockaddr2universal(const struct sockaddr *sap)
 	int len = sizeof(struct sockaddr);
 
 	switch (sap->sa_family) {
-	case AF_LOCAL:
+	case AF_LOCAL: {
 		size_t path_len = len - offsetof(struct sockaddr_un, sun_path);
 		return strndup(sun->sun_path, path_len);
+	}
 	case AF_INET:
 		if (inet_ntop(AF_INET, (const void *)&sin->sin_addr.s_addr,
 					buf, (socklen_t)sizeof(buf)) == NULL)
Signature · 1 line
2.53.0
#1 lore raw
Quoted 4 lines · Petr Vorel

Buildroot distro compiles with fairly old compilers, which defaults to old C11 standard (some of still used compilers don't even have newer standard than C11). Workaround code which requires C23 with using { }.

Quoted 8 lines

This fixes error:

     getport.c:460:3: error: a label can only be part of a statement and a declaration is not a statement
        size_t path_len = len - offsetof(struct sockaddr_un, sun_path);
        ^~~~~~
Fixes 1a6dcd74 ("Removed warnings in nfs_sockaddr2universal()")

Committed... (tag: nfs-utils-2-9-3-rc2)

steved.

Quoted 28 lines

---nfs-utils-2-9-3-rc2
Steve, other option would be to use ';'. Not sure which one you prefer.

Found with Buildroot, which still uses:

$ aarch64-linux-gcc --version
aarch64-linux-gcc.br_real (Buildroot 2017.05) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
  support/nfs/getport.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
support/nfs/getport.c +2 -1
index 6bd2f713..18ea0777 100644
@@ -456,9 +456,10 @@ char *nfs_sockaddr2universal(const struct sockaddr *sap)
  	int len = sizeof(struct sockaddr);
 
  	switch (sap->sa_family) {
-	case AF_LOCAL:
+	case AF_LOCAL: {
  		size_t path_len = len - offsetof(struct sockaddr_un, sun_path);
  		return strndup(sun->sun_path, path_len);
+	}
  	case AF_INET:
  		if (inet_ntop(AF_INET, (const void *)&sin->sin_addr.s_addr,
  					buf, (socklen_t)sizeof(buf)) == NULL)