Skip to contentSkip to conversation

xfs_db: fix complaints about unsigned char casting

PATCH In review Darrick J. Wong 3 participants 5 messages Mar 15, 2023 – Mar 18, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_db: fix complaints about unsigned char casting

From: Darrick J. Wong <[email protected]>

Make the warnings about signed/unsigned char pointer casting go away. For printing dirent names it doesn't matter at all.

---
 db/namei.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
db/namei.c +2 -2
index 00e8c8dc6d5..063721ca98f 100644
@@ -98,7 +98,7 @@ path_navigate(
 
 	for (i = 0; i < dirpath->depth; i++) {
 		struct xfs_name	xname = {
-			.name	= dirpath->path[i],
+			.name	= (unsigned char *)dirpath->path[i],
 			.len	= strlen(dirpath->path[i]),
 		};
 
@@ -250,7 +250,7 @@ dir_emit(
 	uint8_t			dtype)
 {
 	char			*display_name;
-	struct xfs_name		xname = { .name = name };
+	struct xfs_name		xname = { .name = (unsigned char *)name };
 	const char		*dstr = get_dstr(mp, dtype);
 	xfs_dahash_t		hash;
 	bool			good;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Make the warnings about signed/unsigned char pointer casting go away. For printing dirent names it doesn't matter at all.

Looks good, will test.

Quoted 26 lines
---
 db/namei.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
db/namei.c +2 -2
index 00e8c8dc6d5..063721ca98f 100644
@@ -98,7 +98,7 @@ path_navigate(
 
 	for (i = 0; i < dirpath->depth; i++) {
 		struct xfs_name	xname = {
-			.name	= dirpath->path[i],
+			.name	= (unsigned char *)dirpath->path[i],
 			.len	= strlen(dirpath->path[i]),
 		};
 
@@ -250,7 +250,7 @@ dir_emit(
 	uint8_t			dtype)
 {
 	char			*display_name;
-	struct xfs_name		xname = { .name = name };
+	struct xfs_name		xname = { .name = (unsigned char *)name };
 	const char		*dstr = get_dstr(mp, dtype);
 	xfs_dahash_t		hash;
 	bool			good;
Signature · 1 line
Carlos Maiolino
#2 lore raw

Is there any reason keep these definition with different types? Question from a newbie...

Thanks,
Alan

Quoted 43 lines

2023年3月17日 下午6:25,Carlos Maiolino <[email protected]> 写道:

Quoted 6 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Make the warnings about signed/unsigned char pointer casting go away. For printing dirent names it doesn't matter at all.

Looks good, will test.

Quoted 26 lines

---
db/namei.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
db/namei.c +2 -2
index 00e8c8dc6d5..063721ca98f 100644
@@ -98,7 +98,7 @@ path_navigate(
 
 	for (i = 0; i < dirpath->depth; i++) {
 		struct xfs_name	xname = {
-			.name	= dirpath->path[i],
+			.name	= (unsigned char *)dirpath->path[i],
 			.len	= strlen(dirpath->path[i]),
 		};
 
@@ -250,7 +250,7 @@ dir_emit(
 	uint8_t			dtype)
 {
 	char			*display_name;
-	struct xfs_name		xname = { .name = name };
+	struct xfs_name		xname = { .name = (unsigned char *)name };
 	const char		*dstr = get_dstr(mp, dtype);
 	xfs_dahash_t		hash;
 	bool			good;
Signature · 1 line
Carlos Maiolino
#3 lore raw
Quoted 1 line · Alan Huang

Is there any reason keep these definition with different types? Question from a newbie...

Probably not, but char* handling in C is a mess if you don't specify signedness -- on some arches gcc interprets "char" as "signed char", and on others it uses "unsigned char". The C library string functions all operate on "char *", so if you start changing types you quickly end up in compiler warning hell over that.

libxfs seems to use "unsigned char*" and "uint8_t *". I don't know if that was just an SGI thing, or merely a quirk of the codebase? The Linux VFS code all take "char *", though as of 6.2 the makefiles force those to unsigned everywhere. As far as directory entry and extended attribute names go, all eight bits are allowed.

UTF8 encoding uses the upper bit of a char, which means that we really want unsigned to avoid problems with sign extension when computing hashes and things like that, because emoji and kanji characters are in use around the world.

IOWS: it's a giant auditing headache to research what parts use the type declarations they do, figure out what subtleties go with them, and decide on appropriate fixes. And in the end... the system still behaves the same way it did.

--D

Quoted 47 lines

Thanks,
Alan

Quoted 43 lines

2023年3月17日 下午6:25,Carlos Maiolino <[email protected]> 写道:

Quoted 6 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Make the warnings about signed/unsigned char pointer casting go away. For printing dirent names it doesn't matter at all.

Looks good, will test.

Quoted 26 lines

---
db/namei.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
db/namei.c +2 -2
index 00e8c8dc6d5..063721ca98f 100644
@@ -98,7 +98,7 @@ path_navigate(
 
 	for (i = 0; i < dirpath->depth; i++) {
 		struct xfs_name	xname = {
-			.name	= dirpath->path[i],
+			.name	= (unsigned char *)dirpath->path[i],
 			.len	= strlen(dirpath->path[i]),
 		};
 
@@ -250,7 +250,7 @@ dir_emit(
 	uint8_t			dtype)
 {
 	char			*display_name;
-	struct xfs_name		xname = { .name = name };
+	struct xfs_name		xname = { .name = (unsigned char *)name };
 	const char		*dstr = get_dstr(mp, dtype);
 	xfs_dahash_t		hash;
 	bool			good;
Signature · 1 line
Carlos Maiolino
#4 lore raw

Thank you for your detailed explanation!

Thanks,
Alan

Quoted 76 lines

2023年3月18日 上午4:29,Darrick J. Wong <[email protected]> 写道:

Quoted 1 line · Alan Huang

Is there any reason keep these definition with different types? Question from a newbie...

Probably not, but char* handling in C is a mess if you don't specify signedness -- on some arches gcc interprets "char" as "signed char", and on others it uses "unsigned char". The C library string functions all operate on "char *", so if you start changing types you quickly end up in compiler warning hell over that.

libxfs seems to use "unsigned char*" and "uint8_t *". I don't know if that was just an SGI thing, or merely a quirk of the codebase? The Linux VFS code all take "char *", though as of 6.2 the makefiles force those to unsigned everywhere. As far as directory entry and extended attribute names go, all eight bits are allowed.

UTF8 encoding uses the upper bit of a char, which means that we really want unsigned to avoid problems with sign extension when computing hashes and things like that, because emoji and kanji characters are in use around the world.

IOWS: it's a giant auditing headache to research what parts use the type declarations they do, figure out what subtleties go with them, and decide on appropriate fixes. And in the end... the system still behaves the same way it did.

--D

Quoted 47 lines

Thanks,
Alan

Quoted 43 lines

2023年3月17日 下午6:25,Carlos Maiolino <[email protected]> 写道:

Quoted 6 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Make the warnings about signed/unsigned char pointer casting go away. For printing dirent names it doesn't matter at all.

Looks good, will test.

Quoted 26 lines

---
db/namei.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
db/namei.c +2 -2
index 00e8c8dc6d5..063721ca98f 100644
@@ -98,7 +98,7 @@ path_navigate(
 
 	for (i = 0; i < dirpath->depth; i++) {
 		struct xfs_name	xname = {
-			.name	= dirpath->path[i],
+			.name	= (unsigned char *)dirpath->path[i],
 			.len	= strlen(dirpath->path[i]),
 		};
 
@@ -250,7 +250,7 @@ dir_emit(
 	uint8_t			dtype)
 {
 	char			*display_name;
-	struct xfs_name		xname = { .name = name };
+	struct xfs_name		xname = { .name = (unsigned char *)name };
 	const char		*dstr = get_dstr(mp, dtype);
 	xfs_dahash_t		hash;
 	bool			good;
Signature · 1 line
Carlos Maiolino