Skip to content

Commit e8db21c

Browse files
committed
Update GameAnalyticsExtern.cpp
1 parent 0d941cf commit e8db21c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

source/gameanalytics/GameAnalyticsExtern.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "GameAnalytics/GameAnalytics.h"
66
#include "GAUtilities.h"
7+
#include <cstring>
8+
#include <cstdlib>
79

810
gameanalytics::StringVector makeStringVector(const char** arr, int size)
911
{
@@ -29,9 +31,26 @@ GA_API void gameAnalytics_freeString(const char* ptr)
2931
std::free((void*)ptr);
3032
}
3133

34+
// Cross-platform string duplication function
35+
static char* ga_strndup(const char* s, size_t n)
36+
{
37+
if (!s) return nullptr;
38+
39+
size_t len = std::strlen(s);
40+
if (len > n) len = n;
41+
42+
char* result = (char*)std::malloc(len + 1);
43+
if (result)
44+
{
45+
std::memcpy(result, s, len);
46+
result[len] = '\0';
47+
}
48+
return result;
49+
}
50+
3251
const char* gameAnalytics_allocString(std::string const& s)
3352
{
34-
return strndup(s.c_str(), s.size());
53+
return ga_strndup(s.c_str(), s.size());
3554
}
3655

3756
static inline const char* safeString(const char* str)

0 commit comments

Comments
 (0)