Commit dd224b27a3b5179ac65620189a6afe8536eb30c4

dtremenak 2008-05-24T19:04:02

from BZFlag r17264: rewrite StringCopy. wcscpy is not a standard function; we have logic for doing it ourselves already (minus the len = 0 case), so handle len = 0 and do it all ourselves.

diff --git a/src/FTFont/FTBufferFont.cpp b/src/FTFont/FTBufferFont.cpp
index 1ea6a4b..04855e5 100644
--- a/src/FTFont/FTBufferFont.cpp
+++ b/src/FTFont/FTBufferFont.cpp
@@ -180,29 +180,37 @@ inline int StringCompare(void const *a, wchar_t const *b, int len)
 
 inline char *StringCopy(char const *s, int len)
 {
-    if(len >= 0)
-    {
-        char *s2 = (char *)malloc((len + 1) * sizeof(char));
-        memcpy(s2, s, len * sizeof(char));
-        s2[len] = 0;
-        return s2;
-    }
+	if (!s) return NULL;
+
+	if (len < 0)
+	{
+		len = (int)strlen(s);
+	}
+
+	char *s2 = (char *)malloc((len + 1) * sizeof(char));
+	if (!s2) return NULL;
 
-    return strdup(s);
+    memcpy(s2, s, len * sizeof(char));
+    s2[len] = 0;
+    return s2;
 }
 
 
 inline wchar_t *StringCopy(wchar_t const *s, int len)
 {
-    if(len >= 0)
-    {
-        wchar_t *s2 = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
-        memcpy(s2, s, len * sizeof(wchar_t));
-        s2[len] = 0;
-        return s2;
-    }
+	if (!s) return NULL;
+
+	if (len < 0)
+	{
+		len = (int)wcslen(s);
+	}
+
+	wchar_t *s2 = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
+	if (!s2) return NULL;
 
-    return wcsdup(s);
+    memcpy(s2, s, len * sizeof(wchar_t));
+    s2[len] = 0;
+    return s2;
 }