diff --git a/compiler/pre.h b/compiler/pre.h index 743f2ca..19b19c7 100644 --- a/compiler/pre.h +++ b/compiler/pre.h @@ -86,8 +86,6 @@ typedef Slice(u8) Str; /* Creates a `Str` from a string literal */ #define Sl(s) ((Str){ (u8 *)s, (isize)lengthof(s) }) -/* Creates a `Str` from a buffer of size `len` */ -#define Sb(s, len) ((Str){ (u8 *)s, (isize)len }) /* Creates a `Str` from a C string. */ #define Str_from_c(s) ((Str){ (u8 *)s, (isize)(s != nil ? strlen(s) : 0) }) #define Str_empty(s) ((s).len == 0) @@ -96,6 +94,16 @@ typedef Slice(u8) Str; int vsnprintf(char *, unsigned long, const char *, va_list); +/* Creates a `Str` from a buffer of size `len` */ +static inline Str +Str_from_buf(u8 *buf, isize len) +{ + /* If this triggers an OOB, its because the code that created the string was + * broken anyways. ASan will catch it. */ + Assert(buf[len] == '\0'); + return (Str){ buf, len }; +} + /* "Converts" a `Str` into a C string. Since `Str` are meant to be * null-terminated already, no conversion is made, but ensures that the * null terminator is present. */