From 35a06b702a63ff9aa62180a9f1fa9e7526ddf4f7 Mon Sep 17 00:00:00 2001 From: tezc Date: Sun, 27 Dec 2020 08:34:10 +0300 Subject: [PATCH] Fix array, url and bump uarch version --- .github/workflows/.aarch64.yml | 2 +- .github/workflows/.armv6.yml | 2 +- .github/workflows/.armv7.yml | 2 +- .github/workflows/.ppc64le.yml | 2 +- .github/workflows/.s390x.yml | 2 +- array/array_test.c | 2 ++ condition/sc_cond.c | 6 +++--- url/sc_url.c | 18 +++++++++++------- url/url_test.c | 20 ++++++++++++++++++++ 9 files changed, 41 insertions(+), 15 deletions(-) diff --git a/.github/workflows/.aarch64.yml b/.github/workflows/.aarch64.yml index a0835c7..dd5e5e9 100644 --- a/.github/workflows/.aarch64.yml +++ b/.github/workflows/.aarch64.yml @@ -12,7 +12,7 @@ jobs: name: Build on aarch64 steps: - uses: actions/checkout@v2.1.0 - - uses: uraimo/run-on-arch-action@v2.0.7 + - uses: uraimo/run-on-arch-action@v2.0.8 name: Build artifact id: build with: diff --git a/.github/workflows/.armv6.yml b/.github/workflows/.armv6.yml index 5cb05f0..6ecbfa2 100644 --- a/.github/workflows/.armv6.yml +++ b/.github/workflows/.armv6.yml @@ -12,7 +12,7 @@ jobs: name: Build on armv6 steps: - uses: actions/checkout@v2.1.0 - - uses: uraimo/run-on-arch-action@v2.0.7 + - uses: uraimo/run-on-arch-action@v2.0.8 name: Build artifact id: build with: diff --git a/.github/workflows/.armv7.yml b/.github/workflows/.armv7.yml index 019998a..c8e1535 100644 --- a/.github/workflows/.armv7.yml +++ b/.github/workflows/.armv7.yml @@ -12,7 +12,7 @@ jobs: name: Build on armv7 steps: - uses: actions/checkout@v2.1.0 - - uses: uraimo/run-on-arch-action@v2.0.7 + - uses: uraimo/run-on-arch-action@v2.0.8 name: Build artifact id: build with: diff --git a/.github/workflows/.ppc64le.yml b/.github/workflows/.ppc64le.yml index 97de91b..9e2e05e 100644 --- a/.github/workflows/.ppc64le.yml +++ b/.github/workflows/.ppc64le.yml @@ -12,7 +12,7 @@ jobs: name: Build on ppc64le steps: - uses: actions/checkout@v2.1.0 - - uses: uraimo/run-on-arch-action@v2.0.7 + - uses: uraimo/run-on-arch-action@v2.0.8 name: Build artifact id: build with: diff --git a/.github/workflows/.s390x.yml b/.github/workflows/.s390x.yml index 734b83a..9f47277 100644 --- a/.github/workflows/.s390x.yml +++ b/.github/workflows/.s390x.yml @@ -12,7 +12,7 @@ jobs: name: Build on s390x steps: - uses: actions/checkout@v2.1.0 - - uses: uraimo/run-on-arch-action@v2.0.7 + - uses: uraimo/run-on-arch-action@v2.0.8 name: Build artifact id: build with: diff --git a/array/array_test.c b/array/array_test.c index f3f6092..715085c 100644 --- a/array/array_test.c +++ b/array/array_test.c @@ -220,4 +220,6 @@ int main(int argc, char *argv[]) test1(); fail_test(); bounds_test(); + + return 0; } diff --git a/condition/sc_cond.c b/condition/sc_cond.c index a25adea..ab0f9d1 100644 --- a/condition/sc_cond.c +++ b/condition/sc_cond.c @@ -137,7 +137,7 @@ cleanup_mutex: cleanup_attr: pthread_mutexattr_destroy(&attr); error: - strncpy(cond->err, strerror(rc), sizeof(cond->err)); + strncpy(cond->err, strerror(rc), sizeof(cond->err) - 1); return -1; } @@ -148,13 +148,13 @@ int sc_cond_term(struct sc_cond *cond) rv = pthread_mutex_destroy(&cond->mtx); if (rv != 0) { rc = -1; - strncpy(cond->err, strerror(rv), sizeof(cond->err)); + strncpy(cond->err, strerror(rv), sizeof(cond->err) - 1); } rv = pthread_cond_destroy(&cond->cond); if (rv != 0) { rc = -1; - strncpy(cond->err, strerror(rv), sizeof(cond->err)); + strncpy(cond->err, strerror(rv), sizeof(cond->err) - 1); } return rc; diff --git a/url/sc_url.c b/url/sc_url.c index f2ee4c5..523055d 100644 --- a/url/sc_url.c +++ b/url/sc_url.c @@ -35,6 +35,7 @@ struct sc_url *sc_url_create(const char *str) const char *s2 = "%.*s%c%.*s%c%.*s%c%.*s%c%.*s%c%.*s%c%.*s%c"; const char *authority = "//"; + int diff; unsigned long val; size_t len, full_len, parts_len; size_t scheme_len = 0, authority_len = 0, userinfo_len = 0; @@ -120,7 +121,7 @@ struct sc_url *sc_url_create(const char *str) parts_len -= (query_len != 0); parts_len -= (fragment_len != 0); - url = sc_url_malloc(sizeof(struct sc_url) + parts_len + full_len); + url = sc_url_malloc(sizeof(*url) + parts_len + full_len); if (url == NULL) { return NULL; } @@ -135,12 +136,15 @@ struct sc_url *sc_url_create(const char *str) scheme_len -= (scheme_len != 0); // Skip ":" userinfo_len -= (userinfo_len != 0); // Skip "@" - port_len -= (port_len != 0); // Skip ":" - port += (port_len != 0); // Skip ":" - query_len -= (query_len != 0); // Skip "?" - query += (query_len != 0); // Skip "?" - fragment_len -= (fragment_len != 0); // Skip "#" - fragment += (fragment_len != 0); // Skip "#" + diff = port_len != 0; + port_len -= diff; // Skip ":" + port += diff; // Skip ":" + diff = (query_len != 0); + query_len -= diff; // Skip "?" + query += diff; // Skip "?" + diff = (fragment_len != 0); + fragment_len -= diff; // Skip "#" + fragment += diff; // Skip "#" len = sprintf(dest, s2, scheme_len, scheme, 0, userinfo_len, userinfo, 0, host_len, host, 0, port_len, port, 0, path_len, path, 0, diff --git a/url/url_test.c b/url/url_test.c index ee036ef..82b88a4 100644 --- a/url/url_test.c +++ b/url/url_test.c @@ -210,6 +210,25 @@ void test11(void) sc_url_destroy(url); } +void test12(void) +{ + struct sc_url *url; + const char* f = "foo://user:password@example.com:1/over/there?x#3"; + + url = sc_url_create(f); + assert(url != NULL); + assert(strcmp(url->str, f) == 0); + assert(strcmp(url->scheme, "foo") == 0); + assert(strcmp(url->userinfo, "user:password") == 0); + assert(strcmp(url->host, "example.com") == 0); + assert(strcmp(url->port, "1") == 0); + assert(strcmp(url->path, "/over/there") == 0); + assert(strcmp(url->query, "x") == 0); + assert(strcmp(url->fragment, "3") == 0); + + sc_url_destroy(url); +} + #ifdef SC_HAVE_WRAP bool fail_malloc = false; @@ -255,6 +274,7 @@ int main(int argc, char *argv[]) test9(); test10(); test11(); + test12(); fail_test(); return 0; }