laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42275?usp=email )
(
2 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: Replace snprintf() to free 4 kb ......................................................................
Replace snprintf() to free 4 kb
Change-Id: Ide644648bda86d4ae77a6713d1e140a4b78ba835 --- M usb_flash_main.c 1 file changed, 15 insertions(+), 2 deletions(-)
Approvals: Hoernchen: Looks good to me, approved laforge: Looks good to me, but someone else must approve Jenkins Builder: Verified
diff --git a/usb_flash_main.c b/usb_flash_main.c index c78c55c..6d459ed 100644 --- a/usb_flash_main.c +++ b/usb_flash_main.c @@ -91,6 +91,16 @@ return 0; }
+/* 4 bit nibble to chr */ +static char nib_to_chr(uint8_t nib) +{ + nib &= 0xf; + if (nib < 10) + return nib + '0'; + else + return nib - 10 + 'a'; +} + /* same as get_chip_unique_serial but in hex-string format */ static int get_chip_unique_serial_str(char *out, size_t len) { @@ -103,8 +113,11 @@ rc = get_chip_unique_serial(buf, sizeof(buf)); if (rc < 0) return rc; - for (int i = 0; i < sizeof(buf); i++) - sprintf(&out[i * 2], "%02x", buf[i]); + + for (int i = 0; i < sizeof(buf) && (2 * i) + 1 < len; i++) { + out[2 * i] = nib_to_chr(buf[i] >> 4); + out[(2 * i) + 1] = nib_to_chr(buf[i]); + } return 0; }