Skip to content

Commit

Permalink
Fix issue #114.
Browse files Browse the repository at this point in the history
  • Loading branch information
sheredom committed Nov 24, 2023
1 parent b174838 commit 0f66f4a
Show file tree
Hide file tree
Showing 5 changed files with 525 additions and 264 deletions.
30 changes: 18 additions & 12 deletions test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ UTEST(utf8casestr, latin) {

UTEST(utf8chr, a) { ASSERT_EQ(data + 21, utf8chr(data, 0x3bc)); }

UTEST(utf8chr, b) { ASSERT_EQ(0, utf8chr(data, 0x20ac)); }
UTEST(utf8chr, b) { ASSERT_EQ(NULL, utf8chr(data, 0x20ac)); }

UTEST(utf8chr, null_terminator) { ASSERT_EQ(data + 104, utf8chr(data, '\0')); }

Expand Down Expand Up @@ -755,14 +755,20 @@ UTEST(utf8cspn, cspnmultisearch) {

UTEST(utf8rchr, a) { ASSERT_EQ(data + 21, utf8rchr(data, 0x3bc)); }

UTEST(utf8rchr, b) { ASSERT_EQ(0, utf8rchr(data, 0x20ac)); }
UTEST(utf8rchr, b) { ASSERT_EQ(NULL, utf8rchr(data, 0x20ac)); }

UTEST(utf8rchr, null_terminator) {
ASSERT_EQ(data + 104, utf8rchr(data, '\0'));
}

UTEST(utf8rchr, 0x20) { ASSERT_EQ(data + 90, utf8rchr(data, 0x20)); }

UTEST(utf8rchr, overrun) {
const char ascii[] = "Hello\0Hello ";

ASSERT_EQ(4, utf8rchr(ascii, 'o') - ascii);
}

UTEST(utf8dup, data) {
void *const dup = utf8dup(data);
ASSERT_TRUE(dup);
Expand Down Expand Up @@ -992,11 +998,11 @@ UTEST(utf8valid, n) {
ASSERT_EQ(invalid, utf8valid(invalid));
}

UTEST(utf8valid, data) { ASSERT_EQ(0, utf8valid(data)); }
UTEST(utf8valid, data) { ASSERT_EQ(NULL, utf8valid(data)); }

UTEST(utf8valid, ascii) { ASSERT_EQ(0, utf8valid("ab")); }
UTEST(utf8valid, ascii) { ASSERT_EQ(NULL, utf8valid("ab")); }

UTEST(utf8valid, empty) { ASSERT_EQ(0, utf8valid("")); }
UTEST(utf8valid, empty) { ASSERT_EQ(NULL, utf8valid("")); }

UTEST(utf8nvalid, a) {
char valid[3];
Expand Down Expand Up @@ -1039,11 +1045,11 @@ UTEST(utf8nvalid, c) {
ASSERT_EQ(invalid, utf8nvalid(valid, invalid_size));
}

UTEST(utf8nvalid, data) { ASSERT_EQ(0, utf8nvalid(data, 105)); }
UTEST(utf8nvalid, data) { ASSERT_EQ(NULL, utf8nvalid(data, 105)); }

UTEST(utf8nvalid, ascii) { ASSERT_EQ(0, utf8nvalid("ab", 3)); }
UTEST(utf8nvalid, ascii) { ASSERT_EQ(NULL, utf8nvalid("ab", 3)); }

UTEST(utf8nvalid, empty) { ASSERT_EQ(0, utf8nvalid("", 1)); }
UTEST(utf8nvalid, empty) { ASSERT_EQ(NULL, utf8nvalid("", 1)); }

UTEST(utf8ncat, ascii_cat_data) {
char cat[512] = {'\0'};
Expand All @@ -1064,7 +1070,7 @@ UTEST(utf8ncat, bad_cat) {

UTEST(utf8ncat, zero_n) {
char cat[512] = {'\0'};
ASSERT_EQ(0, utf8valid(utf8ncat(cat, data, 0)));
ASSERT_EQ(NULL, utf8valid(utf8ncat(cat, data, 0)));
}

UTEST(utf8ncmp, lt_large) { ASSERT_LT(0, utf8ncmp(data, lt, 4000)); }
Expand Down Expand Up @@ -1122,13 +1128,13 @@ UTEST(utf8ncpy, truncated_copy_valid) {
char cpy3[1] = {'\0'};

utf8ncpy(cpy1, data, 32);
ASSERT_EQ(0, utf8valid(cpy1));
ASSERT_EQ(NULL, utf8valid(cpy1));

utf8ncpy(cpy2, data, 3);
ASSERT_EQ(0, utf8valid(cpy2));
ASSERT_EQ(NULL, utf8valid(cpy2));

utf8ncpy(cpy3, data, 1);
ASSERT_EQ(0, utf8valid(cpy3));
ASSERT_EQ(NULL, utf8valid(cpy3));
}

UTEST(utf8ncpy, truncated_copy_null_terminated) {
Expand Down
6 changes: 5 additions & 1 deletion test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@

#include "utf8.h"

int main(const int argc, const char* const argv[]) { (void)argc; (void)argv; return 0; }
int main(const int argc, const char *const argv[]) {
(void)argc;
(void)argv;
return 0;
}
12 changes: 12 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

// We don't care about the results. We only want to check compilation

#if defined(__clang__)
#pragma clang diagnostic push

#if __has_warning("-Wunsafe-buffer-usage")
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif
#endif

#if defined(__cplusplus) && __cplusplus >= 201402L
constexpr void test() {
constexpr utf8_int8_t in_str[20]{};
Expand Down Expand Up @@ -63,4 +71,8 @@ constexpr void test() {
static void test() {}
#endif

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

int main() { test(); }
Loading

0 comments on commit 0f66f4a

Please sign in to comment.