Skip to content

Commit ad6d34a

Browse files
committed
Manually covnert bytes to avoid snprintf
1 parent 9307017 commit ad6d34a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/wh_utils.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,29 @@ void wh_Utils_Hexdump(const char* initial, const uint8_t* ptr, size_t size)
143143
int count = 0;
144144
char line[80]; /* Buffer for a line of hex output */
145145
size_t linePos = 0;
146+
const char hex[] = "0123456789ABCDEF";
146147

147148
if(initial != NULL)
148149
WOLFHSM_CFG_PRINTF("%s",initial);
149150
while(size > 0) {
150151
if ((count % HEXDUMP_BYTES_PER_LINE) == 0) {
151152
linePos = 0;
152153
}
153-
linePos += snprintf(line + linePos, sizeof(line) - linePos, "%02X ", *ptr);
154+
line[linePos++] = hex[*ptr >> 4];
155+
line[linePos++] = hex[*ptr & 0x0F];
156+
line[linePos++] = ' ';
154157
ptr++;
155158
size --;
156159
count++;
157160
if (count % HEXDUMP_BYTES_PER_LINE == 0) {
158-
linePos += snprintf(line + linePos, sizeof(line) - linePos, "\n");
161+
line[linePos++] = '\n';
162+
line[linePos] = '\0';
159163
WOLFHSM_CFG_PRINTF("%s", line);
160164
}
161165
}
162166
if((count % HEXDUMP_BYTES_PER_LINE) != 0) {
163-
linePos += snprintf(line + linePos, sizeof(line) - linePos, "\n");
167+
line[linePos++] = '\n';
168+
line[linePos] = '\0';
164169
WOLFHSM_CFG_PRINTF("%s", line);
165170
}
166171
}

0 commit comments

Comments
 (0)