xiaoxiang781216 commented on code in PR #3722:
URL: https://github.com/apache/nuttx-apps/pull/3722#discussion_r3769526406


##########
system/toybox/patch/0023-hash-fix-x-format-vs-uint32_t-type-mismatch.patch:
##########
@@ -0,0 +1,42 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: "Alan C. Assis" <[email protected]>
+Date: Wed, 12 Aug 2026 15:35:00 +0000
+Subject: [PATCH 23/23] hash: fix %x format vs uint32_t type mismatch
+
+hash->state.i32[] is "unsigned" (unsigned int), matching "%08x", but
+the ternary that conditionally byteswaps it doesn't: bswap_32() returns
+uint32_t, which some NuttX arm builds typedef to "unsigned long" rather
+than "unsigned int" (arch/arm/include/types.h's __UINT32_TYPE__
+fallback). The usual arithmetic conversions then give the whole ?:
+expression that wider-looking type even though both branches are the
+same 32 bits, so it stops matching "%x" on those targets. An explicit
+(unsigned) cast on the result sidesteps whatever uint32_t happens to
+alias to.
+
+Co-Authored-By: Claude Sonnet 5 <[email protected]>
+---
+ lib/hash.c | 9 +++++++--
+ 1 file changed, 7 insertions(+), 2 deletions(-)
+
+diff --git a/lib/hash.c b/lib/hash.c
+index 2ba4014..2aa33ca 100644
+--- a/lib/hash.c
++++ b/lib/hash.c
+@@ -383,8 +383,13 @@ void hash_by_name(int fd, char *name, char *result)
+   if (method>=4) for (i=0; i<digestlen/8; i++)
+     result += sprintf(result, "%016llx", hash->state.i64[i]);
+   else for (i=0; i<digestlen/4; i++)
+-    result += sprintf(result, "%08x",
+-            !method ? bswap_32(hash->state.i32[i]) : hash->state.i32[i]);
++    // The (unsigned) cast matters on targets (some NuttX/arm builds) where
++    // uint32_t is "unsigned long" rather than "unsigned int": bswap_32()
++    // returns uint32_t, so without it the ?: here has type unsigned long
++    // (usual arithmetic conversions promote to the wider-looking type even
++    // though both are 32 bits), which doesn't match "%x"'s unsigned int.
++    result += sprintf(result, "%08x", (unsigned)

Review Comment:
   why not change the format string to `PRIx32`



##########
system/toybox/patch/0022-hostname-don-t-declare-struct-hostent-when-unused.patch:
##########
@@ -0,0 +1,31 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: "Alan C. Assis" <[email protected]>
+Date: Wed, 12 Aug 2026 15:30:00 +0000
+Subject: [PATCH 22/23] hostname: don't declare struct hostent when unused
+
+Patch 0009 stubbed out -d/-f's gethostbyname() lookup on NuttX (no
+resolver without CONFIG_NET), but left the "struct hostent *h" it read
+the result into declared unconditionally, unused on NuttX now that
+nothing assigns to it there.
+
+Co-Authored-By: Claude Sonnet 5 <[email protected]>
+---
+ toys/lsb/hostname.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/toys/lsb/hostname.c b/toys/lsb/hostname.c
+index 4a07fb9..c56788e 100644
+--- a/toys/lsb/hostname.c
++++ b/toys/lsb/hostname.c
+@@ -41,7 +41,9 @@ GLOBALS(
+ void hostname_main(void)
+ {
+   char *hostname = toybuf, *dot;
++#ifndef __NuttX__
+   struct hostent *h;
++#endif
+
+   gethostname(toybuf, sizeof(toybuf)-1);
+   if (TT.F && (hostname = xreadfile(TT.F, 0, 0))) {

Review Comment:
   but where do you skip gethostbyname invocation?



##########
system/toybox/patch/0022-hostname-don-t-declare-struct-hostent-when-unused.patch:
##########
@@ -0,0 +1,31 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: "Alan C. Assis" <[email protected]>
+Date: Wed, 12 Aug 2026 15:30:00 +0000
+Subject: [PATCH 22/23] hostname: don't declare struct hostent when unused
+
+Patch 0009 stubbed out -d/-f's gethostbyname() lookup on NuttX (no
+resolver without CONFIG_NET), but left the "struct hostent *h" it read
+the result into declared unconditionally, unused on NuttX now that
+nothing assigns to it there.
+
+Co-Authored-By: Claude Sonnet 5 <[email protected]>
+---
+ toys/lsb/hostname.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/toys/lsb/hostname.c b/toys/lsb/hostname.c
+index 4a07fb9..c56788e 100644
+--- a/toys/lsb/hostname.c
++++ b/toys/lsb/hostname.c
+@@ -41,7 +41,9 @@ GLOBALS(
+ void hostname_main(void)
+ {
+   char *hostname = toybuf, *dot;
++#ifndef __NuttX__

Review Comment:
   let's guard by CONFIG_NET



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to