always null-terminate limited-length strings

This commit is contained in:
Martin Michelsen
2022-03-31 10:04:37 -07:00
parent f39dd5a0af
commit 832135a505
6 changed files with 40 additions and 38 deletions
+1 -11
View File
@@ -30,16 +30,6 @@ int char16ncmp(const char16_t* s1, const char16_t* s2, size_t count) {
return 0;
}
void char16ncpy(char16_t* dest, const char16_t* src, size_t count) {
size_t x;
for (x = 0; x < count && src[x] != 0; x++) {
dest[x] = src[x];
}
if (x < count) {
dest[x] = 0;
}
}
size_t char16len(const char16_t* s) {
size_t x;
for (x = 0; s[x] != 0; x++);
@@ -209,7 +199,7 @@ void remove_language_marker_inplace(char* a) {
void remove_language_marker_inplace(char16_t* a) {
if ((a[0] == '\t') && (a[1] != 'C')) {
char16ncpy(a, &a[2], char16len(a) - 2);
strcpy_z(a, &a[2], char16len(a) - 2);
}
}