Skip to content

Strings without null-termination #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 25, 2021
Prev Previous commit
fixup! Make string concat, copy and move work on non-terminated strings
  • Loading branch information
matthijskooijman committed Jan 25, 2021
commit d6fd84fc7e42703a541de9b0837c1f6e78f97bae
3 changes: 3 additions & 0 deletions api/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ String & String::copy(const char *cstr, unsigned int length)
}
len = length;
memcpy(buffer, cstr, length);
buffer[len] = '\0';
return *this;
}

Expand All @@ -220,6 +221,7 @@ void String::move(String &rhs)
if (rhs && capacity >= rhs.len) {
memcpy(buffer, rhs.buffer, rhs.len);
len = rhs.len;
buffer[len] = '\0';
rhs.len = 0;
return;
} else {
Expand Down Expand Up @@ -292,6 +294,7 @@ unsigned char String::concat(const char *cstr, unsigned int length)
if (!reserve(newlen)) return 0;
memcpy(buffer + len, cstr, length);
len = newlen;
buffer[len] = '\0';
return 1;
}

Expand Down