Skip to contentSkip to conversation

net: Use g_strdup_printf instead of snprintf.

PATCH Applied Hani Benhabiles 2 participants 2 messages Jan 9, 2014 – Jan 13, 2014 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: Use g_strdup_printf instead of snprintf.

assign_name() in net/net.c is using snprintf + g_strdup to get the same result as g_strdup_printf.

---
 net/net.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
net/net.c +1 -4
index 9db88cc..9363b35 100644
@@ -164,7 +164,6 @@ void qemu_macaddr_default_if_unset(MACAddr *macaddr)
 static char *assign_name(NetClientState *nc1, const char *model)
 {
     NetClientState *nc;
-    char buf[256];
     int id = 0;
 
     QTAILQ_FOREACH(nc, &net_clients, next) {
@@ -176,9 +175,7 @@ static char *assign_name(NetClientState *nc1, const char *model)
         }
     }
 
-    snprintf(buf, sizeof(buf), "%s.%d", model, id);
-
-    return g_strdup(buf);
+    return g_strdup_printf("%s.%d", model, id);
 }
 
 static void qemu_net_client_destructor(NetClientState *nc)
Signature · 1 line
1.8.3.2