Tweaked refstring, thanks SchuperJesse!

This commit is contained in:
2023-01-23 08:21:51 +00:00
parent 33f360c9cf
commit 6d961cea78

View File

@@ -19,7 +19,7 @@ void setRefStringAllocatorFn(RefStringAllocatorFn allocator) {
//API
RefString* createRefString(char* cstring) {
int length = strlen(cstring);
int length = strnlen(cstring, 4096);
return createRefStringLength(cstring, length);
}
@@ -39,13 +39,11 @@ RefString* createRefStringLength(char* cstring, int length) {
}
void deleteRefString(RefString* refString) {
if (refString->refcount > 0) {
//decrement, then check
refString->refcount--;
if (refString->refcount <= 0) {
allocate(refString, sizeof(int) * 2 + sizeof(char) * refString->length + 1, 0);
}
}
}
int countRefString(RefString* refString) {
@@ -88,7 +86,7 @@ bool equalsRefString(RefString* lhs, RefString* rhs) {
bool equalsRefStringCString(RefString* lhs, char* cstring) {
//get the rhs length
int length = strlen(cstring);
int length = strnlen(cstring, 4096);
//different length
if (lhs->length != length) {