diff options
| author | tylov <[email protected]> | 2023-08-15 10:34:05 +0200 |
|---|---|---|
| committer | tylov <[email protected]> | 2023-08-15 10:34:05 +0200 |
| commit | 5be09e526bc4ee4d1f586aa906e1f9a9c8e3e165 (patch) | |
| tree | 0eecf57ae25269e25ca14153eb53568351a5e79e | |
| parent | 5898353f686619a5345df7babae9c3e2ed84db29 (diff) | |
| download | STC-modified-5be09e526bc4ee4d1f586aa906e1f9a9c8e3e165.tar.gz STC-modified-5be09e526bc4ee4d1f586aa906e1f9a9c8e3e165.zip | |
Fixed c_i2u() didn't trigger -Wsign-conversion warning.
| -rw-r--r-- | include/stc/ccommon.h | 6 | ||||
| -rw-r--r-- | include/stc/clist.h | 6 | ||||
| -rw-r--r-- | include/stc/cmap.h | 2 | ||||
| -rw-r--r-- | include/stc/cstr.h | 2 | ||||
| -rw-r--r-- | src/cregex.c | 14 |
5 files changed, 15 insertions, 15 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); diff --git a/src/cregex.c b/src/cregex.c index e6da66b2..551cb6f6 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -362,7 +362,7 @@ typedef struct _Parser bool lastwasand; /* Last token was _operand */ short nbra; short nclass; - size_t instcap; + intptr_t instcap; _Rune yyrune; /* last lex'd rune */ _Reclass *yyclassp; /* last lex'd class */ _Reclass* classp; @@ -562,11 +562,11 @@ _optimize(_Parser *par, _Reprog *pp) * necessary. Reallocate to the actual space used * and then relocate the code. */ - if ((par->freep - pp->firstinst)*2 > (ptrdiff_t)par->instcap) + if ((par->freep - pp->firstinst)*2 > par->instcap) return pp; - intptr_t ipp = (intptr_t)pp; - size_t size = sizeof(_Reprog) + (size_t)(par->freep - pp->firstinst)*sizeof(_Reinst); + intptr_t ipp = (intptr_t)pp; // convert pointer to intptr_t! + intptr_t size = c_sizeof(_Reprog) + (par->freep - pp->firstinst)*c_sizeof(_Reinst); _Reprog *npp = (_Reprog *)c_realloc(pp, size); ptrdiff_t diff = (intptr_t)npp - ipp; @@ -862,9 +862,9 @@ _regcomp1(_Reprog *pp, _Parser *par, const char *s, int cflags) _Token token; /* get memory for the program. estimated max usage */ - par->instcap = 5U + 6*strlen(s); + par->instcap = 5 + 6*c_strlen(s); _Reprog* old_pp = pp; - pp = (_Reprog *)c_realloc(pp, sizeof(_Reprog) + par->instcap*sizeof(_Reinst)); + pp = (_Reprog *)c_realloc(pp, c_sizeof(_Reprog) + par->instcap*c_sizeof(_Reinst)); if (! pp) { c_free(old_pp); par->error = CREG_OUTOFMEMORY; @@ -1152,7 +1152,7 @@ _regexec2(const _Reprog *progp, /* program to run */ _Relist *relists; /* mark space */ - relists = (_Relist *)c_malloc(2 * _BIGLISTSIZE*sizeof(_Relist)); + relists = (_Relist *)c_malloc(2 * _BIGLISTSIZE*c_sizeof(_Relist)); if (relists == NULL) return -1; |
