lynxis lazus has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42275?usp=email )
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(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/75/42275/1
diff --git a/usb_flash_main.c b/usb_flash_main.c
index c78c55c..ce30694 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;
}
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42275?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: Ide644648bda86d4ae77a6713d1e140a4b78ba835
Gerrit-Change-Number: 42275
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <[email protected]>