boundary check on String8 in debug mode

This commit is contained in:
silverweed 2024-08-01 14:08:29 +02:00
parent d76dd022fd
commit 04680e281c
2 changed files with 6 additions and 5 deletions

View file

@ -12,6 +12,7 @@ String8 push_str8fv(Arena *arena, const char *fmt, va_list args)
return result;
}
internal
String8 push_str8f(Arena *arena, const char *fmt, ...)
{
va_list args;
@ -21,6 +22,7 @@ String8 push_str8f(Arena *arena, const char *fmt, ...)
return result;
}
internal
String8 str8_from_c(const char *str)
{
u64 size = strlen(str);

View file

@ -3,15 +3,14 @@ struct String8 {
u64 size;
const char *c() const { return reinterpret_cast<const char *>(str); }
u8 operator[](u64 idx) const { return str[idx]; }
u8 operator[](u64 idx) const {
assert(idx < size);
return str[idx];
}
};
#define str8(s) String8 { (u8*)(s), sizeof(s) - 1 }
String8 str8_from_c(const char *str);
String8 push_str8f(Arena *arena, char *fmt, ...);
struct String8_Node {
String8_Node *next;
String8 str;