MCPcopy Create free account
hub / github.com/ElementsProject/lightning / printwire_utf8_array

Function printwire_utf8_array

devtools/print_wire.c:111–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111bool printwire_utf8_array(const char *fieldname, const u8 **cursor, size_t *plen, size_t len)
112{
113 struct utf8_state utf8 = UTF8_STATE_INIT;
114 const char *p = (const char *)*cursor;
115 bool char_done = true;
116
117 printf("[");
118 for (size_t i = 0; i < len; i++) {
119 if (!p[i]) {
120 if (!memeqzero(p+i, len-i)) {
121 printf(" **INVALID PADDING** ");
122 goto hexdump;
123 }
124 break;
125 }
126 if (utf8_decode(&utf8, p[i])) {
127 if (errno != 0) {
128 printf(" **INVALID UTF-8** ");
129 goto hexdump;
130 }
131 char_done = true;
132 } else {
133 /* Don't allow unprintable characters */
134 if (utf8.total_len == 1 && !cisprint(utf8.c)) {
135 printf(" **UNPRINTABLE CHARACTER** ");
136 goto hexdump;
137 }
138 char_done = false;
139 }
140 }
141 if (!char_done) {
142 printf(" **INCOMPLETE UTF-8** ");
143 goto hexdump;
144 }
145 printf("%.*s ", (int)len, p);
146
147hexdump:
148 if (!print_hexstring(cursor, plen, len))
149 return false;
150 printf(" ]\n");
151 return true;
152}
153
154static bool printwire_addresses(const u8 **cursor, size_t *plen, size_t len)
155{

Callers 1

printwire_u8_arrayFunction · 0.85

Calls 4

memeqzeroFunction · 0.85
utf8_decodeFunction · 0.85
cisprintFunction · 0.85
print_hexstringFunction · 0.85

Tested by

no test coverage detected