diff --git a/include/neo/_types.h b/include/neo/_types.h index 62c6431..39becef 100644 --- a/include/neo/_types.h +++ b/include/neo/_types.h @@ -56,7 +56,8 @@ struct _neo_string { /* The *amount of Unicode code points*, NOT amount of bytes */ NLEN_FIELD(_len); NREF_FIELD; - usize _capacity; + /* physical size in bytes, including the four NUL terminators */ + usize _size; char *_data; }; typedef struct _neo_string string; diff --git a/src/string/leftpad.c b/src/string/leftpad.c index 756e08b..75bc32c 100644 --- a/src/string/leftpad.c +++ b/src/string/leftpad.c @@ -25,7 +25,7 @@ static inline string *leftpad_unsafe(const string *s, usize len, nchar fillchr, * but that's okay because if we don't even have enough memory for three * extra bytes we are screwed anyway. */ - usize size_now = s->_capacity; + usize size_now = s->_size; usize size_after = size_now + (extra_chars * fillchr_size); char *dest = nalloc(size_after, err); catch(err) { diff --git a/src/string/nstr.c b/src/string/nstr.c index a53e89e..488035a 100644 --- a/src/string/nstr.c +++ b/src/string/nstr.c @@ -51,7 +51,7 @@ static string *nstr_unsafe(const char *restrict s, usize size_without_nul, error } str->_len = len; - str->_capacity = size_without_nul + 4; + str->_size = size_without_nul + 4; nref_init(str, nstr_destroy); memcpy(str->_data, s, size_without_nul); diff --git a/src/string/nstrcmp.c b/src/string/nstrcmp.c index 97273ec..89ceb55 100644 --- a/src/string/nstrcmp.c +++ b/src/string/nstrcmp.c @@ -23,10 +23,10 @@ int nstrcmp(const string *s1, const string *s2, error *err) int ret; usize maxbytes; - if (s1->_capacity > s2->_capacity) - maxbytes = s2->_capacity; + if (s1->_size > s2->_size) + maxbytes = s2->_size; else - maxbytes = s1->_capacity; + maxbytes = s1->_size; ret = strncmp(s1->_data, s2->_data, maxbytes); neat(err);