diff options
| author | Tyge Løvset <[email protected]> | 2022-11-22 16:12:35 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-11-22 16:12:35 +0100 |
| commit | 72f75574edea7a864d5784e38d7d90315c2b2190 (patch) | |
| tree | 74e5b097b75c8d13faacc781106c4b99a1040169 /include | |
| parent | 512cba08af831a864e09d34f02250820d3d76883 (diff) | |
| download | STC-modified-72f75574edea7a864d5784e38d7d90315c2b2190.tar.gz STC-modified-72f75574edea7a864d5784e38d7d90315c2b2190.zip | |
Fixes of -Wconversion warnings (not examples).
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/cbits.h | 2 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 6 | ||||
| -rw-r--r-- | include/stc/cdeq.h | 28 | ||||
| -rw-r--r-- | include/stc/cmap.h | 18 | ||||
| -rw-r--r-- | include/stc/coption.h | 2 | ||||
| -rw-r--r-- | include/stc/crandom.h | 4 | ||||
| -rw-r--r-- | include/stc/cregex.h | 2 | ||||
| -rw-r--r-- | include/stc/csmap.h | 4 | ||||
| -rw-r--r-- | include/stc/cstr.h | 28 | ||||
| -rw-r--r-- | include/stc/csview.h | 14 | ||||
| -rw-r--r-- | include/stc/cvec.h | 31 | ||||
| -rw-r--r-- | include/stc/utf8.h | 4 |
12 files changed, 71 insertions, 72 deletions
diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 0b5c4db8..3a5c63e6 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -60,7 +60,7 @@ int main() { #define _cbits_bytes(n) (_cbits_words(n) * sizeof(uint64_t)) #if defined(__GNUC__) || defined(__clang__) - STC_INLINE uint64_t cpopcount64(uint64_t x) {return __builtin_popcountll(x);} + STC_INLINE uint64_t cpopcount64(uint64_t x) {return (uint64_t)__builtin_popcountll(x);} #elif defined(_MSC_VER) && defined(_WIN64) #include <intrin.h> STC_INLINE uint64_t cpopcount64(uint64_t x) {return __popcnt64(x);} diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 8d6fa0ea..f2d21099 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -183,7 +183,7 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, #define c_forfilter_s(i, C, start, filter) \ for (struct {C##_iter it; C##_value *ref; \ uint32_t s1[c_FLT_STACK], index, count; \ - uint8_t s2[c_FLT_STACK], s1top, s2top;} \ + bool s2[c_FLT_STACK]; uint8_t s1top, s2top;} \ i = {.it=start, .ref=i.it.ref}; i.it.ref \ ; C##_next(&i.it), i.ref = i.it.ref, ++i.index, i.s1top=0, i.s2top=0) \ if (!((filter) && ++i.count)) ; else @@ -203,9 +203,9 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, #define c_forrange1(stop) c_forrange3(_c_i, 0, stop) #define c_forrange2(i, stop) c_forrange3(i, 0, stop) #define c_forrange3(i, start, stop) \ - for (long long i=start, _end=stop; i < _end; ++i) + for (long long i=start, _end=(long long)(stop); i < _end; ++i) #define c_forrange4(i, start, stop, step) \ - for (long long i=start, _inc=step, _end=(stop) - (_inc > 0) \ + for (long long i=start, _inc=step, _end=(long long)(stop) - (_inc > 0) \ ; (_inc > 0) ^ (i > _end); i += _inc) #ifndef __cplusplus #define c_forlist(it, T, ...) \ diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 93e806ae..8bc68f3d 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -114,7 +114,7 @@ STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t n) #if !defined _i_queue STC_INLINE size_t _cx_memb(_index)(const _cx_self* self, _cx_iter it) - { return it.ref - self->data; } + { return (size_t)(it.ref - self->data); } STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) { _cx_value* p = &self->data[--self->_len]; i_keydrop(p); } @@ -192,7 +192,7 @@ _cx_memb(_get_mut)(_cx_self* self, _cx_raw raw) STC_INLINE void _cx_memb(_sort_range)(_cx_iter i1, _cx_iter i2, int(*cmp)(const _cx_value*, const _cx_value*)) { - qsort(i1.ref, _it2_ptr(i1, i2) - i1.ref, sizeof *i1.ref, + qsort(i1.ref, (size_t)(_it2_ptr(i1, i2) - i1.ref), sizeof *i1.ref, (int(*)(const void*, const void*)) cmp); } @@ -205,7 +205,7 @@ _cx_memb(_sort)(_cx_self* self) { /* -------------------------- IMPLEMENTATION ------------------------- */ #if defined(i_implement) -#define _cdeq_nfront(self) ((self)->data - (self)->_base) +#define _cdeq_nfront(self) (size_t)((self)->data - (self)->_base) STC_DEF _cx_self _cx_memb(_init)(void) { @@ -245,7 +245,7 @@ _cx_memb(_drop)(_cx_self* self) { static size_t _cx_memb(_realloc_)(_cx_self* self, const size_t n) { - const size_t cap = (size_t)(self->_len*1.7) + n + 7; + const size_t cap = (size_t)((float)self->_len*1.7f) + n + 7U; const size_t nfront = _cdeq_nfront(self); _cx_value* d = (_cx_value*)c_realloc(self->_base, cap*sizeof(i_key)); if (!d) @@ -260,7 +260,7 @@ static bool _cx_memb(_expand_right_half_)(_cx_self* self, const size_t idx, const size_t n) { const size_t sz = self->_len, cap = self->_cap; const size_t nfront = _cdeq_nfront(self), nback = cap - sz - nfront; - if (nback >= n || sz*1.3 + n > cap) { + if (nback >= n || (size_t)((float)sz*1.3f) + n > cap) { if (!_cx_memb(_realloc_)(self, n)) return false; memmove(self->data + idx + n, self->data + idx, (sz - idx)*sizeof(i_key)); @@ -300,7 +300,7 @@ _cx_memb(_push)(_cx_self* self, i_key value) { return v; } -#if !c_option(c_no_clone) +#if !defined i_no_clone STC_DEF _cx_self _cx_memb(_clone)(_cx_self cx) { _cx_self out = _cx_memb(_with_capacity)(cx._len); @@ -321,7 +321,7 @@ _cx_memb(_expand_left_half_)(_cx_self* self, const size_t idx, const size_t n) { if (nfront >= n) { self->data = (_cx_value *)memmove(self->data - n, self->data, idx*sizeof(i_key)); } else { - if (sz*1.3 + n > cap) + if ((size_t)((float)sz*1.3f) > cap) cap = _cx_memb(_realloc_)(self, n); const size_t unused = cap - (sz + n); const size_t pos = (nback*2 < unused) ? unused - nback : unused/2; @@ -334,7 +334,7 @@ static _cx_iter _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) { if (n) { if (!pos) pos = self->data + self->_len; - const size_t idx = pos - self->data; + const size_t idx = (size_t)(pos - self->data); if (idx*2 < self->_len) _cx_memb(_expand_left_half_)(self, idx, n); else @@ -359,9 +359,9 @@ _cx_memb(_push_front)(_cx_self* self, i_key value) { STC_DEF _cx_iter _cx_memb(_insert_range)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2) { - _cx_iter it = _cx_memb(_insert_uninit)(self, pos, p2 - p1); + _cx_iter it = _cx_memb(_insert_uninit)(self, pos, (size_t)(p2 - p1)); if (it.ref) - memcpy(it.ref, p1, (p2 - p1)*sizeof *p1); + memcpy(it.ref, p1, (size_t)(p2 - p1)*sizeof *p1); return it; } @@ -372,8 +372,8 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { _cx_value* p = p1, *end = self->data + self->_len; for (; p != p2; ++p) { i_keydrop(p); } - memmove(p1, p2, (end - p2) * sizeof *p1); - self->_len -= len; + memmove(p1, p2, (size_t)(end - p2)*sizeof *p1); + self->_len -= (size_t)len; return c_init(_cx_iter){p2 == end ? NULL : p1, end - len}; } @@ -381,7 +381,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { STC_DEF _cx_iter _cx_memb(_copy_range)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2) { - _cx_iter it = _cx_memb(_insert_uninit)(self, pos, p2 - p1); + _cx_iter it = _cx_memb(_insert_uninit)(self, pos, (size_t)(p2 - p1)); if (it.ref) for (_cx_value* p = it.ref; p1 != p2; ++p1) *p++ = i_keyclone((*p1)); @@ -393,7 +393,7 @@ _cx_memb(_copy_range)(_cx_self* self, _cx_value* pos, STC_DEF _cx_iter _cx_memb(_emplace_range)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2) { - _cx_iter it = _cx_memb(_insert_uninit)(self, pos, p2 - p1); + _cx_iter it = _cx_memb(_insert_uninit)(self, pos, (size_t)(p2 - p1)); if (it.ref) for (_cx_value* p = it.ref; p1 != p2; ++p1) *p++ = i_keyfrom((*p1)); diff --git a/include/stc/cmap.h b/include/stc/cmap.h index a6b63679..ff7c7840 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -109,12 +109,12 @@ STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* val); STC_INLINE _cx_self _cx_memb(_init)(void) { return c_init(_cx_self){0}; } STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) { _cx_memb(_reserve)(self, self->size); } -STC_INLINE float _cx_memb(_max_load_factor)(const _cx_self* self) { return i_max_load_factor; } +STC_INLINE float _cx_memb(_max_load_factor)(const _cx_self* self) { return (float)(i_max_load_factor); } STC_INLINE bool _cx_memb(_empty)(const _cx_self* map) { return !map->size; } STC_INLINE size_t _cx_memb(_size)(const _cx_self* map) { return map->size; } STC_INLINE size_t _cx_memb(_bucket_count)(_cx_self* map) { return map->bucket_count; } STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* map) - { return (size_t)(map->bucket_count * (i_max_load_factor)); } + { return (size_t)((float)map->bucket_count * (i_max_load_factor)); } STC_INLINE void _cx_memb(_swap)(_cx_self *map1, _cx_self *map2) {c_swap(_cx_self, *map1, *map2); } STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, _cx_rawkey rkey) { return self->size && self->_hashx[_cx_memb(_bucket_)(self, &rkey).idx]; } @@ -224,7 +224,7 @@ _cx_memb(_advance)(_cx_iter it, size_t n) { STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) { - i_size idx; + size_t idx; if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx]) return c_init(_cx_iter){self->table + idx, self->table + self->bucket_count, @@ -234,7 +234,7 @@ _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) { STC_INLINE const _cx_value* _cx_memb(_get)(const _cx_self* self, _cx_rawkey rkey) { - i_size idx; + size_t idx; if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx]) return self->table + idx; return NULL; @@ -249,7 +249,7 @@ _cx_memb(_erase)(_cx_self* self, _cx_rawkey rkey) { if (self->size == 0) return 0; chash_bucket_t b = _cx_memb(_bucket_)(self, &rkey); - return self->_hashx[b.idx] ? _cx_memb(_erase_entry)(self, self->table + b.idx), 1 : 0; + return self->_hashx[b.idx] ? _cx_memb(_erase_entry)(self, self->table + b.idx), 1U : 0U; } STC_INLINE _cx_iter @@ -355,7 +355,7 @@ _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey* rkeyptr) { STC_DEF _cx_result _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey) { bool nomem = false; - if (self->size + 2 > (i_size)(self->bucket_count * (i_max_load_factor))) + if (self->size + 2 > (i_size)((float)self->bucket_count * (i_max_load_factor))) nomem = !_cx_memb(_reserve)(self, self->size*3/2); chash_bucket_t b = _cx_memb(_bucket_)(self, &rkey); _cx_result res = {&self->table[b.idx], !self->_hashx[b.idx], nomem}; @@ -389,7 +389,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) { const i_size _oldbuckets = self->bucket_count; if (_newcap != self->size && _newcap <= _oldbuckets) return true; - i_size _nbuckets = (i_size)(_newcap / (i_max_load_factor)) + 4; + i_size _nbuckets = (i_size)((float)_newcap / (i_max_load_factor)) + 4; #if _i_expandby == 2 _nbuckets = (i_size)next_power_of_2(_nbuckets); #else @@ -420,7 +420,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) { STC_DEF void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) { - i_size i = _val - self->table, j = i, k; + i_size i = (i_size)(_val - self->table), j = i, k; const i_size _cap = self->bucket_count; _cx_value* _slot = self->table; uint8_t* _hashx = self->_hashx; @@ -431,7 +431,7 @@ _cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) { if (! _hashx[j]) break; const _cx_rawkey _raw = i_keyto(_i_keyref(_slot + j)); - k = c_paste(fastrange_,_i_expandby)(i_hash_functor(self, (&_raw)), _cap); + k = (i_size)c_paste(fastrange_,_i_expandby)(i_hash_functor(self, (&_raw)), _cap); if ((j < i) ^ (k <= i) ^ (k > j)) /* is k outside (i, j]? */ _slot[i] = _slot[j], _hashx[i] = _hashx[j], i = j; } diff --git a/include/stc/coption.h b/include/stc/coption.h index db715f5c..6b01c5a3 100644 --- a/include/stc/coption.h +++ b/include/stc/coption.h @@ -129,7 +129,7 @@ static int coption_get(coption *opt, int argc, char *argv[], const coption_long *o = 0, *o_exact = 0, *o_partial = 0; for (j = 2; argv[opt->_i][j] != '\0' && argv[opt->_i][j] != '='; ++j) {} /* find the end of the option name */ for (k = 0; longopts[k].name != 0; ++k) - if (strncmp(&argv[opt->_i][2], longopts[k].name, j - 2) == 0) { + if (strncmp(&argv[opt->_i][2], longopts[k].name, (size_t)(j - 2)) == 0) { if (longopts[k].name[j - 2] == 0) ++n_exact, o_exact = &longopts[k]; else ++n_partial, o_partial = &longopts[k]; } diff --git a/include/stc/crandom.h b/include/stc/crandom.h index b46c0430..6c41be83 100644 --- a/include/stc/crandom.h +++ b/include/stc/crandom.h @@ -148,7 +148,7 @@ STC_DEF stc64_uniform_t stc64_uniform_new(int64_t low, int64_t high) { #if defined(__SIZEOF_INT128__) #define c_umul128(a, b, lo, hi) \ do { __uint128_t _z = (__uint128_t)(a)*(b); \ - *(lo) = (uint64_t)_z, *(hi) = _z >> 64; } while(0) + *(lo) = (uint64_t)_z, *(hi) = (uint64_t)(_z >> 64U); } while(0) #elif defined(_MSC_VER) && defined(_WIN64) #include <intrin.h> #define c_umul128(a, b, lo, hi) ((void)(*(lo) = _umul128(a, b, hi))) @@ -162,7 +162,7 @@ STC_DEF int64_t stc64_uniform(stc64_t* rng, stc64_uniform_t* d) { #ifdef c_umul128 uint64_t lo, hi; do { c_umul128(stc64_rand(rng), d->range, &lo, &hi); } while (lo < d->threshold); - return d->lower + hi; + return d->lower + (int64_t)hi; #else uint64_t x, r; do { diff --git a/include/stc/cregex.h b/include/stc/cregex.h index d88bb6a8..43dc7ac0 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -99,7 +99,7 @@ cregex cregex_from(const char* pattern, int cflags) { } /* number of capture groups in a regex pattern, 0 if regex is invalid */ -int cregex_captures(const cregex* self); +unsigned cregex_captures(const cregex* self); /* return cre_success, cre_nomatch or cre_matcherror. */ int cregex_find(const cregex* re, const char* input, diff --git a/include/stc/csmap.h b/include/stc/csmap.h index b503fc9b..84cf2c22 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -241,7 +241,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t cap) { return false; nodes[0] = c_init(_cx_node){{0, 0}, 0}; self->nodes = nodes; - self->cap = cap; + self->cap = (i_size)cap; return true; } @@ -276,7 +276,7 @@ _cx_memb(_new_node_)(_cx_self* self, int level) { tn = ++self->head; /* start with 1, 0 is nullnode. */ } _cx_node* dn = &self->nodes[tn]; - dn->link[0] = dn->link[1] = 0; dn->level = level; + dn->link[0] = dn->link[1] = 0; dn->level = (int8_t)level; return tn; } diff --git a/include/stc/cstr.h b/include/stc/cstr.h index c762d0e0..ec5cd3c9 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -85,8 +85,8 @@ STC_API bool cstr_getdelim(cstr *self, int delim, FILE *fp); STC_API void cstr_erase(cstr* self, size_t pos, size_t len); STC_API void cstr_u8_erase(cstr* self, size_t bytepos, size_t u8len); STC_API cstr cstr_from_fmt(const char* fmt, ...); -STC_API int cstr_append_fmt(cstr* self, const char* fmt, ...); -STC_API int cstr_printf(cstr* self, const char* fmt, ...); +STC_API size_t cstr_append_fmt(cstr* self, const char* fmt, ...); +STC_API size_t cstr_printf(cstr* self, const char* fmt, ...); STC_API void cstr_replace(cstr* self, const char* search, const char* repl, unsigned count); STC_API cstr cstr_replace_sv(csview sv, csview search, csview repl, unsigned count); @@ -361,7 +361,7 @@ STC_INLINE void cstr_pop(cstr* self) { csview sv = cstr_sv(self); const char* s = sv.str + sv.size; while ((*--s & 0xC0) == 0x80) ; - _cstr_set_size(self, s - sv.str); + _cstr_set_size(self, (size_t)(s - sv.str)); } STC_INLINE char* cstr_append(cstr* self, const char* str) @@ -425,17 +425,17 @@ STC_DEF size_t cstr_find_sv(const cstr* self, csview search) { STC_DEF char* _cstr_internal_move(cstr* self, const size_t pos1, const size_t pos2) { cstr_buf r = cstr_buffer(self); if (pos1 != pos2) { - const intptr_t newlen = r.size + pos2 - pos1; + const intptr_t newlen = (intptr_t)(r.size + pos2 - pos1); if (newlen > (intptr_t)r.cap) r.data = cstr_reserve(self, r.size*3/2 + pos2 - pos1); memmove(&r.data[pos2], &r.data[pos1], r.size - pos1); - _cstr_set_size(self, newlen); + _cstr_set_size(self, (size_t)newlen); } return r.data; } STC_DEF char* _cstr_init(cstr* self, const size_t len, const size_t cap) { - if (cap > cstr_s_cap) { + if (cap > cstr_s_cap) { self->lon.data = (char *)c_malloc(cap + 1); cstr_l_set_size(self, len); cstr_l_set_cap(self, cap); @@ -539,10 +539,10 @@ STC_DEF cstr cstr_replace_sv(csview in, csview search, csview repl, unsigned count) { cstr out = cstr_null; size_t from = 0; char* res; - if (!count) count = ~0; + if (!count) count = ~0U; if (search.size) while (count-- && (res = cstrnstrn(in.str + from, search.str, in.size - from, search.size))) { - const size_t pos = res - in.str; + const size_t pos = (size_t)(res - in.str); cstr_append_n(&out, in.str + from, pos - from); cstr_append_n(&out, repl.str, repl.size); from = pos + search.size; @@ -580,10 +580,10 @@ STC_DEF void cstr_u8_erase(cstr* self, const size_t bytepos, const size_t u8len) # pragma warning(disable: 4996) #endif -STC_DEF int cstr_vfmt(cstr* self, size_t start, const char* fmt, va_list args) { +STC_DEF size_t cstr_vfmt(cstr* self, size_t start, const char* fmt, va_list args) { va_list args2; va_copy(args2, args); - const int n = vsnprintf(NULL, (size_t)0, fmt, args); + const size_t n = (size_t)vsnprintf(NULL, (size_t)0, fmt, args); vsprintf(cstr_reserve(self, start + n) + start, fmt, args2); va_end(args2); _cstr_set_size(self, start + n); @@ -604,19 +604,19 @@ STC_DEF cstr cstr_from_fmt(const char* fmt, ...) { return s; } -STC_DEF int cstr_append_fmt(cstr* self, const char* fmt, ...) { +STC_DEF size_t cstr_append_fmt(cstr* self, const char* fmt, ...) { va_list args; va_start(args, fmt); - const int n = cstr_vfmt(self, cstr_size(self), fmt, args); + const size_t n = cstr_vfmt(self, cstr_size(self), fmt, args); va_end(args); return n; } /* NB! self-data in args is UB */ -STC_DEF int cstr_printf(cstr* self, const char* fmt, ...) { +STC_DEF size_t cstr_printf(cstr* self, const char* fmt, ...) { va_list args; va_start(args, fmt); - const int n = cstr_vfmt(self, 0, fmt, args); + const size_t n = cstr_vfmt(self, 0, fmt, args); va_end(args); return n; } diff --git a/include/stc/csview.h b/include/stc/csview.h index cccf21ea..149759ce 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -172,23 +172,23 @@ STC_DEF uint64_t csview_hash(const csview *self) STC_DEF csview csview_substr_ex(csview sv, intptr_t pos, size_t n) { if (pos < 0) { - pos += sv.size; + pos += (intptr_t)sv.size; if (pos < 0) pos = 0; } - if (pos > (intptr_t)sv.size) pos = sv.size; - if (pos + n > sv.size) n = sv.size - pos; + if ((size_t)pos > sv.size) pos = (intptr_t)sv.size; + if ((size_t)pos + n > sv.size) n = sv.size - (size_t)pos; sv.str += pos, sv.size = n; return sv; } STC_DEF csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2) { if (p1 < 0) { - p1 += sv.size; + p1 += (intptr_t)sv.size; if (p1 < 0) p1 = 0; } - if (p2 < 0) p2 += sv.size; - if (p2 > (intptr_t)sv.size) p2 = sv.size; - sv.str += p1, sv.size = p2 > p1 ? p2 - p1 : 0; + if (p2 < 0) p2 += (intptr_t)sv.size; + if (p2 > (intptr_t)sv.size) p2 = (intptr_t)sv.size; + sv.str += p1, sv.size = (size_t)(p2 > p1 ? p2 - p1 : 0); return sv; } diff --git a/include/stc/cvec.h b/include/stc/cvec.h index c8025343..7a674228 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -44,16 +44,16 @@ struct MyStruct { #include <stc/cvec.h> int main() { - cvec_i32 vec = cvec_i32_init(); - cvec_i32_push_back(&vec, 123); + cvec_i32 vec = {0}; + cvec_i32_push(&vec, 123); cvec_i32_drop(&vec); - cvec_float fvec = cvec_float_init(); - cvec_float_push_back(&fvec, 123.3); + cvec_float fvec = {0}; + cvec_float_push(&fvec, 123.3); cvec_float_drop(&fvec); - cvec_str svec = cvec_str_init(); - cvec_str_emplace_back(&svec, "Hello, friend"); + cvec_str svec = {0}; + cvec_str_emplace(&svec, "Hello, friend"); cvec_str_drop(&svec); } */ @@ -209,7 +209,7 @@ STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t n) { if ((it.ref += n) >= it.end) it.ref = NULL; return it; } STC_INLINE size_t _cx_memb(_index)(const _cx_self* self, _cx_iter it) - { return it.ref - self->data; } + { return (size_t)(it.ref - self->data); } #if !defined i_no_cmp @@ -242,7 +242,7 @@ _cx_memb(_lower_bound)(const _cx_self* self, _cx_raw raw) { STC_INLINE void _cx_memb(_sort_range)(_cx_iter i1, _cx_iter i2, int(*cmp)(const _cx_value*, const _cx_value*)) { - qsort(i1.ref, _it2_ptr(i1, i2) - i1.ref, sizeof(_cx_value), + qsort(i1.ref, (size_t)(_it2_ptr(i1, i2) - i1.ref), sizeof(_cx_value), (int(*)(const void*, const void*)) cmp); } @@ -316,7 +316,7 @@ STC_DEF _cx_iter _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) { if (n) { if (!pos) pos = self->data + self->_len; - const size_t idx = pos - self->data; + const size_t idx = (size_t)(pos - self->data); if (self->_len + n > self->_cap) { if (!_cx_memb(_reserve)(self, self->_len*3/2 + n)) return _cx_memb(_end)(self); @@ -331,20 +331,19 @@ _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) { STC_DEF _cx_iter _cx_memb(_insert_range)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2) { - _cx_iter it = _cx_memb(_insert_uninit)(self, pos, p2 - p1); + _cx_iter it = _cx_memb(_insert_uninit)(self, pos, (size_t)(p2 - p1)); if (it.ref) - memcpy(it.ref, p1, (p2 - p1)*sizeof *p1); + memcpy(it.ref, p1, (size_t)(p2 - p1)*sizeof *p1); return it; } STC_DEF _cx_iter _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { - assert(p1 && p2); - intptr_t len = p2 - p1; + size_t len = (size_t)(p2 - p1); _cx_value* p = p1, *end = self->data + self->_len; for (; p != p2; ++p) { i_keydrop(p); } - memmove(p1, p2, (end - p2) * sizeof *p1); + memmove(p1, p2, (size_t)(end - p2)*sizeof *p1); self->_len -= len; return c_init(_cx_iter){p2 == end ? NULL : p1, end - len}; } @@ -360,7 +359,7 @@ _cx_memb(_clone)(_cx_self cx) { STC_DEF _cx_iter _cx_memb(_copy_range)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2) { - _cx_iter it = _cx_memb(_insert_uninit)(self, pos, p2 - p1); + _cx_iter it = _cx_memb(_insert_uninit)(self, pos, (size_t)(p2 - p1)); if (it.ref) for (_cx_value* p = it.ref; p1 != p2; ++p1) *p++ = i_keyclone((*p1)); @@ -372,7 +371,7 @@ _cx_memb(_copy_range)(_cx_self* self, _cx_value* pos, STC_DEF _cx_iter _cx_memb(_emplace_range)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2) { - _cx_iter it = _cx_memb(_insert_uninit)(self, pos, p2 - p1); + _cx_iter it = _cx_memb(_insert_uninit)(self, pos, (size_t)(p2 - p1)); if (it.ref) for (_cx_value* p = it.ref; p1 != p2; ++p1) *p++ = i_keyfrom((*p1)); diff --git a/include/stc/utf8.h b/include/stc/utf8.h index 7a4ba921..0ff79fb9 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -31,7 +31,7 @@ STC_INLINE uint32_t utf8_decode(utf8_decode_t* d, const uint32_t byte) { extern const uint8_t utf8_dtab[]; /* utf8code.c */ const uint32_t type = utf8_dtab[byte]; d->codep = d->state ? (byte & 0x3fu) | (d->codep << 6) - : (0xff >> type) & byte; + : (0xffU >> type) & byte; return d->state = utf8_dtab[256 + d->state + type]; } @@ -86,6 +86,6 @@ STC_INLINE const char* utf8_at(const char *s, size_t index) { } STC_INLINE size_t utf8_pos(const char* s, size_t index) - { return utf8_at(s, index) - s; } + { return (size_t)(utf8_at(s, index) - s); } #endif |
