From bde5af4fa16c836f9369ce5ca8cc9eef2abc4fbb Mon Sep 17 00:00:00 2001
From: Avi Kivity <avi.kivity@gmail.com>
Date: Mon, 7 Jan 2013 16:26:59 +0200
Subject: [PATCH] sprintf(), snprintf(): add missing terminator

---
 libc/printf.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libc/printf.cc b/libc/printf.cc
index f5fd7dd22..7ef9c8231 100644
--- a/libc/printf.cc
+++ b/libc/printf.cc
@@ -5,6 +5,7 @@
 #include <vector>
 #include <stdint.h>
 #include <cctype>
+#include <string.h>
 #include "debug.hh"
 
 namespace {
@@ -330,7 +331,7 @@ int sprintf(char* str, const char* format, ...)
     va_start(ap, format);
     auto out = strprintf(format, ap);
     va_end(ap);
-    std::copy(out.begin(), out.end(), str);
+    strcpy(str, out.c_str());
     return out.length();
 }
 
@@ -342,6 +343,6 @@ int snprintf(char* str, size_t n, const char* format, ...)
     auto out = strprintf(format, ap);
     va_end(ap);
     std::string trunc = out.substr(0, n - 1);
-    std::copy(out.begin(), out.end(), str);
+    strcpy(str, trunc.c_str());
     return out.length();
 }
-- 
GitLab