diff options
| author | Tyge Løvset <[email protected]> | 2023-05-01 10:00:07 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-05-01 10:02:12 +0200 |
| commit | f916573e2b3652d9b3f6fb82aadd5f2cfb3ce2fe (patch) | |
| tree | 22283c2d74f2cac441ce04b3106e144f440b8137 | |
| parent | 49e7d9cc0a888b0b19aa4e737d55a2bc33bec824 (diff) | |
| download | STC-modified-f916573e2b3652d9b3f6fb82aadd5f2cfb3ce2fe.tar.gz STC-modified-f916573e2b3652d9b3f6fb82aadd5f2cfb3ce2fe.zip | |
Remove warnings when using -Wextra.
| -rw-r--r-- | include/stc/cbits.h | 4 | ||||
| -rw-r--r-- | include/stc/csmap.h | 2 | ||||
| -rw-r--r-- | misc/benchmarks/shootout_hashmaps.cpp | 1 | ||||
| -rw-r--r-- | misc/examples/birthday.c | 4 | ||||
| -rw-r--r-- | misc/examples/complex.c | 2 | ||||
| -rw-r--r-- | misc/examples/gauss2.c | 2 | ||||
| -rw-r--r-- | misc/examples/inits.c | 2 | ||||
| -rwxr-xr-x | misc/examples/make.sh | 4 | ||||
| -rw-r--r-- | misc/examples/new_list.c | 2 | ||||
| -rw-r--r-- | misc/examples/new_map.c | 6 | ||||
| -rw-r--r-- | misc/examples/new_pque.c | 2 | ||||
| -rw-r--r-- | misc/examples/new_queue.c | 2 | ||||
| -rw-r--r-- | misc/examples/new_smap.c | 2 | ||||
| -rw-r--r-- | misc/examples/new_vec.c | 4 | ||||
| -rw-r--r-- | misc/examples/prime.c | 12 | ||||
| -rw-r--r-- | misc/examples/random.c | 14 | ||||
| -rw-r--r-- | misc/examples/regex_match.c | 2 | ||||
| -rw-r--r-- | misc/examples/shape.c | 8 | ||||
| -rw-r--r-- | src/cregex.c | 9 |
19 files changed, 43 insertions, 41 deletions
diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 19e281a8..855d6eb7 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -125,7 +125,7 @@ STC_INLINE bool _cbits_disjoint(const uint64_t* set, const uint64_t* other, cons #define _i_assert(x) assert(x) #define i_type cbits -struct { uint64_t *data64; int64_t _size; } typedef i_type; +typedef struct { uint64_t *data64; int64_t _size; } i_type; STC_INLINE cbits cbits_init(void) { return c_LITERAL(cbits){NULL}; } STC_INLINE void cbits_create(cbits* self) { self->data64 = NULL; self->_size = 0; } @@ -197,7 +197,7 @@ STC_INLINE cbits cbits_with_pattern(const int64_t size, const uint64_t pattern) #define i_type c_PASTE(cbits, i_capacity) #endif -struct { uint64_t data64[(i_capacity - 1)/64 + 1]; } typedef i_type; +typedef struct { uint64_t data64[(i_capacity - 1)/64 + 1]; } i_type; STC_INLINE i_type _i_memb(_init)(void) { return c_LITERAL(i_type){0}; } STC_INLINE void _i_memb(_create)(i_type* self) {} diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 6b8475eb..fbfea8dd 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -283,7 +283,7 @@ _cx_memb(_reserve)(_cx_self* self, const intptr_t cap) { _cx_node* nodes = (_cx_node*)i_realloc(self->nodes, (cap + 1)*c_sizeof(_cx_node)); if (!nodes) return false; - nodes[0] = c_LITERAL(_cx_node){{0, 0}, 0}; + nodes[0] = c_LITERAL(_cx_node){0}; self->nodes = nodes; self->cap = (int32_t)cap; return true; diff --git a/misc/benchmarks/shootout_hashmaps.cpp b/misc/benchmarks/shootout_hashmaps.cpp index 54680402..c6a81777 100644 --- a/misc/benchmarks/shootout_hashmaps.cpp +++ b/misc/benchmarks/shootout_hashmaps.cpp @@ -36,6 +36,7 @@ KHASH_MAP_INIT_INT64(ii, IValue) #define i_key IKey #define i_val IValue #define i_tag ii +//#define i_expandby 1 #define i_max_load_factor MAX_LOAD_FACTOR / 100.0f #include <stc/cmap.h> diff --git a/misc/examples/birthday.c b/misc/examples/birthday.c index c301128a..2820c42f 100644 --- a/misc/examples/birthday.c +++ b/misc/examples/birthday.c @@ -13,8 +13,8 @@ static uint64_t seed = 12345; static void test_repeats(void) { enum {BITS = 46, BITS_TEST = BITS/2 + 2}; - const static uint64_t N = 1ull << BITS_TEST; - const static uint64_t mask = (1ull << BITS) - 1; + static const uint64_t N = 1ull << BITS_TEST; + static const uint64_t mask = (1ull << BITS) - 1; printf("birthday paradox: value range: 2^%d, testing repeats of 2^%d values\n", BITS, BITS_TEST); crand_t rng = crand_init(seed); diff --git a/misc/examples/complex.c b/misc/examples/complex.c index 7dde981d..c730db33 100644 --- a/misc/examples/complex.c +++ b/misc/examples/complex.c @@ -44,7 +44,7 @@ int main() const ListMap* lmap_p = MapMap_at(&mmap, "first"); const StackList* list_p = ListMap_at(lmap_p, 42); const FloatStack* stack_p = StackList_back(list_p); - printf("value is: %f\n", *FloatStack_at(stack_p, 3)); // pi + printf("value is: %f\n", (double)*FloatStack_at(stack_p, 3)); // pi MapMap_drop(&mmap); } diff --git a/misc/examples/gauss2.c b/misc/examples/gauss2.c index df709d03..e786824b 100644 --- a/misc/examples/gauss2.c +++ b/misc/examples/gauss2.c @@ -14,7 +14,7 @@ int main() enum {N = 5000000}; uint64_t seed = (uint64_t)time(NULL); crand_t rng = crand_init(seed); - const double Mean = round(crand_f64(&rng)*98.f - 49.f), StdDev = crand_f64(&rng)*10.f + 1.f, Scale = 74.f; + const double Mean = round(crand_f64(&rng)*98.0 - 49.0), StdDev = crand_f64(&rng)*10.0 + 1.0, Scale = 74.0; printf("Demo of gaussian / normal distribution of %d random samples\n", N); printf("Mean %f, StdDev %f\n", Mean, StdDev); diff --git a/misc/examples/inits.c b/misc/examples/inits.c index 81bcdd3e..e098422e 100644 --- a/misc/examples/inits.c +++ b/misc/examples/inits.c @@ -45,7 +45,7 @@ int main(void) puts("\npop and show high priorites first:"); while (! cpque_f_empty(&floats)) { - printf("%.1f ", *cpque_f_top(&floats)); + printf("%.1f ", (double)*cpque_f_top(&floats)); cpque_f_pop(&floats); } puts("\n"); diff --git a/misc/examples/make.sh b/misc/examples/make.sh index 0297e5a1..ee8d2267 100755 --- a/misc/examples/make.sh +++ b/misc/examples/make.sh @@ -1,12 +1,12 @@ #!/bin/sh if [ "$(uname)" = 'Linux' ]; then - sanitize='-fsanitize=address' + sanitize='-fsanitize=address -fsanitize=undefined -fsanitize-trap' clibs='-lm' # -pthread oflag='-o ' fi -cc=gcc; cflags="-s -O3 -std=c99 -Wconversion -Wpedantic -Wall -Wsign-compare -Wwrite-strings" +cc=gcc; cflags="-s -O3 -std=c99 -Wall -Wextra -Wpedantic -Wconversion -Wwrite-strings -Wdouble-promotion -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-maybe-uninitialized -Wno-missing-field-initializers" #cc=gcc; cflags="-g -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall $sanitize" #cc=tcc; cflags="-Wall -std=c99" #cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -Wno-unused-function -Wsign-compare -Wwrite-strings" diff --git a/misc/examples/new_list.c b/misc/examples/new_list.c index 8b291d34..14fabb4a 100644 --- a/misc/examples/new_list.c +++ b/misc/examples/new_list.c @@ -61,7 +61,7 @@ int main() clist_float_sort(&flst); c_foreach (i, clist_float, flst) - printf(" %g", *i.ref); + printf(" %g", (double)*i.ref); puts(""); clist_float_drop(&flst); diff --git a/misc/examples/new_map.c b/misc/examples/new_map.c index 3a4f934d..f01db64f 100644 --- a/misc/examples/new_map.c +++ b/misc/examples/new_map.c @@ -3,10 +3,10 @@ forward_cmap(cmap_pnt, struct Point, int); -struct MyStruct { +typedef struct MyStruct { cmap_pnt pntmap; cstr name; -} typedef MyStruct; +} MyStruct; // int => int map #define i_key int @@ -14,7 +14,7 @@ struct MyStruct { #include <stc/cmap.h> // Point => int map -struct Point { int x, y; } typedef Point; +typedef struct Point { int x, y; } Point; int point_cmp(const Point* a, const Point* b) { int c = a->x - b->x; diff --git a/misc/examples/new_pque.c b/misc/examples/new_pque.c index 9147e3f2..5b26b3de 100644 --- a/misc/examples/new_pque.c +++ b/misc/examples/new_pque.c @@ -1,6 +1,6 @@ #include <stdio.h> -struct Point { int x, y; } typedef Point; +typedef struct Point { int x, y; } Point; #define i_type PointQ #define i_val Point diff --git a/misc/examples/new_queue.c b/misc/examples/new_queue.c index 916f4dbc..b784bc18 100644 --- a/misc/examples/new_queue.c +++ b/misc/examples/new_queue.c @@ -5,7 +5,7 @@ forward_cqueue(cqueue_pnt, struct Point); -struct Point { int x, y; } typedef Point; +typedef struct Point { int x, y; } Point; int point_cmp(const Point* a, const Point* b) { int c = c_default_cmp(&a->x, &b->x); return c ? c : c_default_cmp(&a->y, &b->y); diff --git a/misc/examples/new_smap.c b/misc/examples/new_smap.c index d8245b8b..f930eba2 100644 --- a/misc/examples/new_smap.c +++ b/misc/examples/new_smap.c @@ -10,7 +10,7 @@ typedef struct { } MyStruct; // Point => int map -struct Point { int x, y; } typedef Point; +typedef struct Point { int x, y; } Point; int point_cmp(const Point* a, const Point* b) { int c = a->x - b->x; return c ? c : a->y - b->y; diff --git a/misc/examples/new_vec.c b/misc/examples/new_vec.c index df443b7f..d4b66883 100644 --- a/misc/examples/new_vec.c +++ b/misc/examples/new_vec.c @@ -4,10 +4,10 @@ forward_cvec(cvec_i32, int); forward_cvec(cvec_pnt, struct Point); -struct MyStruct { +typedef struct MyStruct { cvec_i32 intvec; cvec_pnt pntvec; -} typedef MyStruct; +} MyStruct; #define i_val int #define i_is_forward diff --git a/misc/examples/prime.c b/misc/examples/prime.c index d0887353..7efa26ff 100644 --- a/misc/examples/prime.c +++ b/misc/examples/prime.c @@ -26,15 +26,15 @@ cbits sieveOfEratosthenes(int64_t n) int main(void) { - int64_t n = 1000000000; - printf("Computing prime numbers up to %" c_ZI "\n", n); + int n = 1000000000; + printf("Computing prime numbers up to %d\n", n); - clock_t t1 = clock(); + clock_t t = clock(); cbits primes = sieveOfEratosthenes(n + 1); - int64_t np = cbits_count(&primes); - clock_t t2 = clock(); + int np = (int)cbits_count(&primes); + t = t - clock(); - printf("Number of primes: %" c_ZI ", time: %f\n\n", np, (float)(t2 - t1) / (float)CLOCKS_PER_SEC); + printf("Number of primes: %d, time: %f\n\n", np, (double)t/CLOCKS_PER_SEC); puts("Show all the primes in the range [2, 1000):"); printf("2"); c_forrange (i, 3, 1000, 2) diff --git a/misc/examples/random.c b/misc/examples/random.c index ea9c483e..e783fe55 100644 --- a/misc/examples/random.c +++ b/misc/examples/random.c @@ -4,7 +4,7 @@ int main() { - const size_t N = 1000000000; + const int N = 1000000000; const uint64_t seed = (uint64_t)time(NULL), range = 1000000; crand_t rng = crand_init(seed); @@ -18,8 +18,8 @@ int main() sum += (uint32_t)crand_u64(&rng); } diff = clock() - before; - printf("full range\t\t: %f secs, %" c_ZI ", avg: %f\n", - (float)diff / CLOCKS_PER_SEC, N, (float)sum / (float)N); + printf("full range\t\t: %f secs, %d, avg: %f\n", + (double)diff/CLOCKS_PER_SEC, N, (double)sum/N); crand_unif_t dist1 = crand_unif_init(0, range); rng = crand_init(seed); @@ -29,8 +29,8 @@ int main() sum += crand_unif(&rng, &dist1); // unbiased } diff = clock() - before; - printf("unbiased 0-%" PRIu64 "\t: %f secs, %" c_ZI ", avg: %f\n", - range, (float)diff/CLOCKS_PER_SEC, N, (float)sum / (float)N); + printf("unbiased 0-%" PRIu64 "\t: %f secs, %d, avg: %f\n", + range, (double)diff/CLOCKS_PER_SEC, N, (double)sum/N); sum = 0; rng = crand_init(seed); @@ -39,7 +39,7 @@ int main() sum += (int64_t)(crand_u64(&rng) % (range + 1)); // biased } diff = clock() - before; - printf("biased 0-%" PRIu64 " \t: %f secs, %" c_ZI ", avg: %f\n", - range, (float)diff / CLOCKS_PER_SEC, N, (float)sum / (float)N); + printf("biased 0-%" PRIu64 " \t: %f secs, %d, avg: %f\n", + range, (double)diff/CLOCKS_PER_SEC, N, (double)sum/N); } diff --git a/misc/examples/regex_match.c b/misc/examples/regex_match.c index def0ae7a..e49ebd0b 100644 --- a/misc/examples/regex_match.c +++ b/misc/examples/regex_match.c @@ -24,7 +24,7 @@ int main() cstack_float_push(&vec, (float)atof(i.match[0].str)); c_foreach (i, cstack_float, vec) - printf(" %g\n", *i.ref); + printf(" %g\n", (double)*i.ref); // extracts the numbers only to a comma separated string. cstr nums = cregex_replace_sv(&re, csview_from(str), " $0,", 0, NULL, CREG_R_STRIP); diff --git a/misc/examples/shape.c b/misc/examples/shape.c index d7116039..22e993db 100644 --- a/misc/examples/shape.c +++ b/misc/examples/shape.c @@ -62,9 +62,9 @@ static void Triangle_draw(const Shape* shape) { const Triangle* self = DYN_CAST(Triangle, shape); printf("Triangle : (%g,%g), (%g,%g), (%g,%g)\n", - self->p[0].x, self->p[0].y, - self->p[1].x, self->p[1].y, - self->p[2].x, self->p[2].y); + (double)self->p[0].x, (double)self->p[0].y, + (double)self->p[1].x, (double)self->p[1].y, + (double)self->p[2].x, (double)self->p[2].y); } struct ShapeAPI Triangle_api = { @@ -109,7 +109,7 @@ static void Polygon_draw(const Shape* shape) const Polygon* self = DYN_CAST(Polygon, shape); printf("Polygon :"); c_foreach (i, PointVec, self->points) - printf(" (%g,%g)", i.ref->x, i.ref->y); + printf(" (%g,%g)", (double)i.ref->x, (double)i.ref->y); puts(""); } diff --git a/src/cregex.c b/src/cregex.c index 0688d9e1..a1d43944 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -842,16 +842,17 @@ _bldcclass(_Parser *par) static _Reprog* -_regcomp1(_Reprog *progp, _Parser *par, const char *s, int cflags) +_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); - _Reprog* pp = (_Reprog *)c_realloc(progp, sizeof(_Reprog) + par->instcap*sizeof(_Reinst)); - if (pp == NULL) { + _Reprog* old_pp = pp; + pp = (_Reprog *)c_realloc(pp, sizeof(_Reprog) + par->instcap*sizeof(_Reinst)); + if (! pp) { + c_free(old_pp); par->error = CREG_OUTOFMEMORY; - c_free(progp); return NULL; } pp->flags.icase = (cflags & CREG_C_ICASE) != 0; |
