summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authortylov <[email protected]>2023-08-15 10:34:05 +0200
committertylov <[email protected]>2023-08-15 10:34:05 +0200
commit5be09e526bc4ee4d1f586aa906e1f9a9c8e3e165 (patch)
tree0eecf57ae25269e25ca14153eb53568351a5e79e /include
parent5898353f686619a5345df7babae9c3e2ed84db29 (diff)
downloadSTC-modified-5be09e526bc4ee4d1f586aa906e1f9a9c8e3e165.tar.gz
STC-modified-5be09e526bc4ee4d1f586aa906e1f9a9c8e3e165.zip
Fixed c_i2u() didn't trigger -Wsign-conversion warning.
Diffstat (limited to 'include')
-rw-r--r--include/stc/ccommon.h6
-rw-r--r--include/stc/clist.h6
-rw-r--r--include/stc/cmap.h2
-rw-r--r--include/stc/cstr.h2
4 files changed, 8 insertions, 8 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 42631f85..e33e657a 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -88,16 +88,16 @@ typedef long long _llong;
#define c_const_cast(T, p) ((T)(1 ? (p) : (T)0))
#define c_swap(T, xp, yp) do { T *_xp = xp, *_yp = yp, \
_tv = *_xp; *_xp = *_yp; *_yp = _tv; } while (0)
+// use with gcc -Wsign-conversion
#define c_sizeof (intptr_t)sizeof
#define c_strlen(s) (intptr_t)strlen(s)
-
#define c_strncmp(a, b, ilen) strncmp(a, b, c_i2u(ilen))
#define c_memcpy(d, s, ilen) memcpy(d, s, c_i2u(ilen))
#define c_memmove(d, s, ilen) memmove(d, s, c_i2u(ilen))
#define c_memset(d, val, ilen) memset(d, val, c_i2u(ilen))
#define c_memcmp(a, b, ilen) memcmp(a, b, c_i2u(ilen))
-#define c_u2i(u) ((intptr_t)(1 ? (u) : (size_t)1))
-#define c_i2u(i) ((size_t)(1 ? (i) : (intptr_t)1))
+#define c_u2i(u) (intptr_t)(1 ? (u) : (size_t)1)
+#define c_i2u(i) (size_t)(1 ? (i) : -1)
#define c_LTu(a, b) ((size_t)(a) < (size_t)(b))
// x and y are i_keyraw* type, defaults to i_key*:
diff --git a/include/stc/clist.h b/include/stc/clist.h
index d7cf30b9..6a205c2b 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -385,17 +385,17 @@ STC_DEF int _cx_MEMB(_sort_cmp_)(const _cx_value* x, const _cx_value* y) {
}
STC_DEF bool _cx_MEMB(_sort_with)(_cx_Self* self, int(*cmp)(const _cx_value*, const _cx_value*)) {
- size_t len = 0, cap = 0;
+ intptr_t len = 0, cap = 0;
_cx_value *a = NULL, *p = NULL;
_cx_iter i;
for (i = _cx_MEMB(_begin)(self); i.ref; _cx_MEMB(_next)(&i)) {
if (len == cap) {
- if ((p = (_cx_value *)i_realloc(a, (cap += cap/2 + 4)*sizeof *a))) a = p;
+ if ((p = (_cx_value *)i_realloc(a, (cap += cap/2 + 4)*c_sizeof *a))) a = p;
else { i_free(a); return false; }
}
a[len++] = *i.ref;
}
- qsort(a, len, sizeof *a, (int(*)(const void*, const void*))cmp);
+ qsort(a, (size_t)len, sizeof *a, (int(*)(const void*, const void*))cmp);
for (i = _cx_MEMB(_begin)(self); i.ref; _cx_MEMB(_next)(&i), ++p)
*i.ref = *p;
i_free(a); return true;
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index e0134964..deee1f59 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -417,7 +417,7 @@ _cx_MEMB(_reserve)(_cx_Self* self, const intptr_t _newcap) {
_newbucks = cnextpow2(_newbucks);
_cx_Self m = {
(_cx_value *)i_malloc(_newbucks*c_sizeof(_cx_value)),
- (struct chash_slot *)i_calloc(_newbucks + 1, sizeof(struct chash_slot)),
+ (struct chash_slot *)i_calloc(_newbucks + 1, c_sizeof(struct chash_slot)),
self->size, _newbucks
};
bool ok = m.data && m.slot;
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 3822020f..bc147469 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -509,7 +509,7 @@ STC_DEF char* cstr_reserve(cstr* self, const intptr_t cap) {
char* data = (char *)c_malloc(cap + 1);
const intptr_t len = cstr_s_size(self);
/* copy full short buffer to emulate realloc() */
- c_memcpy(data, self->sml.data, sizeof self->sml);
+ c_memcpy(data, self->sml.data, c_sizeof self->sml);
self->lon.data = data;
self->lon.size = (size_t)len;
cstr_l_set_cap(self, cap);