]> git.ozlabs.org Git - petitboot/commitdiff
lib/util: Avoid sprintf in mac_str
authorJeremy Kerr <jk@ozlabs.org>
Mon, 16 Dec 2013 03:21:22 +0000 (11:21 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 18 Dec 2013 01:52:42 +0000 (09:52 +0800)
The conversion is simple, no need for sprintf.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/util/util.c

index 75b1c23620176ff4ded978ae15c362a831cc8443..a18926c1ac74c9446629d0ad01199db467c9d449 100644 (file)
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <stdio.h>
 #include <string.h>
 #include <assert.h>
 
 #include <util/util.h>
 
 #include <string.h>
 #include <assert.h>
 
 #include <util/util.h>
 
+static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
+                           '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', };
+
 void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen)
 {
        unsigned int i;
 void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen)
 {
        unsigned int i;
@@ -36,8 +38,9 @@ void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen)
        pos = buf;
 
        for (i = 0; i < maclen; i++) {
        pos = buf;
 
        for (i = 0; i < maclen; i++) {
-               snprintf(pos, 4, "%02x:", mac[i]);
-               pos += 3;
+               *(pos++) = hex[mac[i] >> 4 & 0xf];
+               *(pos++) = hex[mac[i] & 0xf];
+               *(pos++) = ':';
        }
 
        *(pos - 1) = '\0';
        }
 
        *(pos - 1) = '\0';