Fix crash in LuaPrint

This commit is contained in:
Krzosa Karol
2024-08-08 12:04:55 +02:00
parent d47482bc04
commit eecff81093
4 changed files with 17 additions and 14 deletions

View File

@@ -221,7 +221,20 @@ For(arr.reverse_iter()) {
#define For(array) ForItem(it, array)
constexpr int64_t SLICE_LAST = INT64_MIN;
int64_t WideLength(wchar_t *string);
inline int64_t StringLen(char *string) {
if (!string) return 0;
int64_t i = 0;
while (string[i]) i += 1;
return i;
}
inline int64_t WideLength(wchar_t *string) {
if (!string) return 0;
int64_t len = 0;
while (*string++ != 0)
len++;
return len;
}
template <class T>
struct Slice {
@@ -231,8 +244,8 @@ struct Slice {
Slice() = default;
Slice(T *s, int64_t l) : data(s), len(l) {}
Slice(char *s) : data(s), len(strlen(s)) {}
Slice(const char *s) : data((char *)s), len(strlen((char *)s)) {}
Slice(char *s) : data(s), len(StringLen(s)) {}
Slice(const char *s) : data((char *)s), len(StringLen((char *)s)) {}
Slice(const char *s, int64_t l) : data((char *)s), len(l) {}
Slice(wchar_t *s) : data(s), len(WideLength(s)) {}
@@ -1584,13 +1597,6 @@ String Format(Allocator allocator, const char *data, ...) PrintfFormatAttribute(
return result;
}
int64_t WideLength(wchar_t *string) {
int64_t len = 0;
while (*string++ != 0)
len++;
return len;
}
String16 ToString16(Allocator allocator, String string) {
Assert(sizeof(wchar_t) == 2);
wchar_t *buffer = (wchar_t *)AllocSize(allocator, sizeof(wchar_t) * (string.len + 1));