From 3c379fbfb2b7301cd5c4f5371a9f0b96a1369b60 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Fri, 4 Mar 2022 13:18:35 +0100 Subject: Updated printf formatting to portable code. This was also to use http://winlibs.com gcc+clang with ucrt runtime-libs without warnings. --- include/stc/carc.h | 2 +- include/stc/ccommon.h | 2 +- include/stc/cstr.h | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/stc/carc.h b/include/stc/carc.h index 9c7d52c1..e3deb376 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -43,7 +43,7 @@ int main() { carc_person p = carc_person_from(Person_new("John", "Smiths")); carc_person q = carc_person_clone(p); // share the pointer - printf("%s %s. uses: %zu\n", q.get->name.str, q.get->last.str, *q.use_count); + printf("%s %s. uses: %" PRIuMAX "\n", q.get->name.str, q.get->last.str, *q.use_count); c_drop(carc_person, &p, &q); } */ diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index e5a595e0..263971a0 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -24,7 +24,7 @@ #define CCOMMON_H_INCLUDED #define _CRT_SECURE_NO_WARNINGS -#include +#include #include #include #include diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 937e5151..fc4c22d1 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -32,11 +32,11 @@ #include #define cstr_npos (SIZE_MAX >> 1) -typedef struct { size_t size, cap; char chr; } _cstr_rep_t; +typedef struct { size_t size, cap; char chr[1]; } _cstr_rep_t; #define _cstr_rep(self) c_container_of((self)->str, _cstr_rep_t, chr) #ifdef _i_static - static _cstr_rep_t _cstr_nullrep = {0, 0, 0}; - static const cstr cstr_null = {&_cstr_nullrep.chr}; + static _cstr_rep_t _cstr_nullrep = {0, 0, {0}}; + static const cstr cstr_null = {_cstr_nullrep.chr}; #else extern const cstr cstr_null; #endif @@ -186,7 +186,7 @@ cstr_reserve(cstr* self, const size_t cap) { const size_t oldcap = rep->cap; if (cap > oldcap) { rep = (_cstr_rep_t*) c_realloc(oldcap ? rep : NULL, _cstr_opt_mem(cap)); - self->str = &rep->chr; + self->str = rep->chr; if (oldcap == 0) self->str[rep->size = 0] = '\0'; return (rep->cap = _cstr_opt_cap(cap)); } @@ -205,7 +205,7 @@ STC_DEF cstr cstr_from_n(const char* str, const size_t n) { if (n == 0) return cstr_null; _cstr_rep_t* rep = (_cstr_rep_t*) c_malloc(_cstr_opt_mem(n)); - cstr s = {(char *) memcpy(&rep->chr, str, n)}; + cstr s = {(char *) memcpy(rep->chr, str, n)}; s.str[rep->size = n] = '\0'; rep->cap = _cstr_opt_cap(n); return s; -- cgit v1.2.3