What changed, and why it matters
This commit simply moves a helper function that breaks a long text string into smaller chunks from one source file to a shared utility file. The code itself is unchanged, and there is no indication of a security fix or vulnerability.
No security action required; treat as routine code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is a pure refactor: the split_text() helper and its associated SPLIT_TEXT_LEN macro are relocated from main/ui/confirm_address.c to main/utils/util.c/main/utils/util.h. The implementation, assertions, and logic are identical. No functional or security-relevant changes are present in the diff.
Changed components
main/ui/confirm_address.cmain/utils/util.cmain/utils/util.hInspect captured patch +41 / −37
diff --git a/main/ui/confirm_address.c b/main/ui/confirm_address.c
index b2d3b69..842a57f 100644
--- a/main/ui/confirm_address.c
+++ b/main/ui/confirm_address.c
@@ -1,6 +1,7 @@
#ifndef AMALGAMATED_BUILD
#include "../button_events.h"
#include "../ui.h"
+#include "../utils/util.h"
#include "jade_assert.h"
// Should the address be displayed a formatted grid, or as a single long string (traditional)
@@ -19,43 +20,6 @@
#define ADDR_GRID_SIZE (ADDR_GRID_X * ADDR_GRID_Y)
#define ADDR_TEXTSPLITLEN (MAX_DISPLAY_ADDRESS_LEN / ADDR_GRID_SIZE)
-
-// The length of the required buffer to hold 'len' characters
-// with a nul-terminator injected every 'wordlen' characters, and
-// at the very end. eg. for "abcdefhij\0" -> "abc\0def\0ghi\0j\0"
-#define SPLIT_TEXT_LEN(len, wordlen) (len + (len / wordlen) + 1)
-
-// Helper to copy text from one buffer to another, where the destination has terminators every
-// 'wordlen' chars, eg: "abcdefghi\0" -> "abc\0def\0ghi\0j\0"
-// output 'num_words' is number of 'words' written - eg. 4
-// output 'written' is number iof bytes written, including all '\0's - eg. 14
-static void split_text(const char* src, const size_t len, const size_t wordlen, char* output, const size_t output_len,
- size_t* num_words, size_t* written)
-{
- JADE_ASSERT(src);
- JADE_ASSERT(wordlen);
- JADE_ASSERT(output);
- JADE_ASSERT(output_len >= SPLIT_TEXT_LEN(len, wordlen));
- JADE_INIT_OUT_SIZE(num_words);
- JADE_INIT_OUT_SIZE(written);
-
- size_t read = 0;
- size_t write = 0;
- while (read < len) {
- const size_t remaining = len - read;
- const size_t nchars = remaining > wordlen ? wordlen : remaining;
-
- JADE_ASSERT(write + nchars + 1 <= output_len);
- strncpy(output + write, src + read, nchars);
- read += nchars;
- write += nchars;
-
- output[write++] = '\0';
- ++*num_words;
- }
- JADE_ASSERT(write <= output_len);
- *written = write;
-}
#endif // ADDRESS_STRING_GRID
// also used in sign_tx
diff --git a/main/utils/util.c b/main/utils/util.c
index 6386078..015d97d 100644
--- a/main/utils/util.c
+++ b/main/utils/util.c
@@ -66,4 +66,32 @@ bool is_potential_green_server_path(const uint32_t* path, const size_t path_len,
*subaccount_out = path_len == MAX_GASERVICE_PATH_LEN ? path[path_len - 2] : 0;
return true;
}
+
+void split_text(const char* src, const size_t len, const size_t wordlen, char* output, const size_t output_len,
+ size_t* num_words, size_t* written)
+{
+ JADE_ASSERT(src);
+ JADE_ASSERT(wordlen);
+ JADE_ASSERT(output);
+ JADE_ASSERT(output_len >= SPLIT_TEXT_LEN(len, wordlen));
+ JADE_INIT_OUT_SIZE(num_words);
+ JADE_INIT_OUT_SIZE(written);
+
+ size_t read = 0;
+ size_t write = 0;
+ while (read < len) {
+ const size_t remaining = len - read;
+ const size_t nchars = remaining > wordlen ? wordlen : remaining;
+
+ JADE_ASSERT(write + nchars + 1 <= output_len);
+ strncpy(output + write, src + read, nchars);
+ read += nchars;
+ write += nchars;
+
+ output[write++] = '\0';
+ ++*num_words;
+ }
+ JADE_ASSERT(write <= output_len);
+ *written = write;
+}
#endif // AMALGAMATED_BUILD
diff --git a/main/utils/util.h b/main/utils/util.h
index bb370a9..e4aabca 100644
--- a/main/utils/util.h
+++ b/main/utils/util.h
@@ -86,6 +86,18 @@ static inline void map_string(char* s, int (*fnmap)(int))
}
}
+// The length of the required buffer to hold 'len' characters
+// with a nul-terminator injected every 'wordlen' characters, and
+// at the very end. eg. for "abcdefhij\0" -> "abc\0def\0ghi\0j\0"
+#define SPLIT_TEXT_LEN(len, wordlen) (len + (len / wordlen) + 1)
+
+// Helper to copy text from one buffer to another, where the destination has terminators every
+// 'wordlen' chars, eg: "abcdefghi\0" -> "abc\0def\0ghi\0j\0"
+// output 'num_words' is number of 'words' written - eg. 4
+// output 'written' is number of bytes written, including all '\0's - eg. 14
+void split_text(
+ const char* src, size_t len, size_t wordlen, char* output, size_t output_len, size_t* num_words, size_t* written);
+
// Bip32 path utils
static inline bool ishardened(const uint32_t n) { return n & 0x80000000; }
static inline uint32_t harden(const uint32_t n) { return n | 0x80000000; }
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.