fix some warnings

This commit is contained in:
jacob 2025-03-01 11:46:29 -06:00
parent 0b92a1e8a4
commit b909a392f1
11 changed files with 38 additions and 43 deletions

13
build.c
View File

@ -476,20 +476,17 @@ void OnBuild(StringList cli_args)
String warnings = Lit("-Weverything -Werror " String warnings = Lit("-Weverything -Werror "
"-Wframe-larger-than=65536 " "-Wframe-larger-than=65536 "
"-Wno-unused-macros -Wno-gnu-zero-variadic-macro-arguments -Wno-documentation " "-Wno-unused-macros -Wno-gnu-zero-variadic-macro-arguments -Wno-documentation "
"-Wno-old-style-cast -Wno-conversion -Wno-sign-conversion " "-Wno-old-style-cast -Wno-conversion -Wno-double-promotion "
"-Wno-declaration-after-statement -Wno-extra-semi -Wno-extra-semi-stmt " "-Wno-declaration-after-statement "
"-Wno-bad-function-cast -Wno-class-varargs -Wno-unreachable-code-break " "-Wno-bad-function-cast -Wno-class-varargs -Wno-unreachable-code-break "
"-Wno-cast-align -Wno-float-equal -Wno-zero-as-null-pointer-constant " "-Wno-cast-align -Wno-float-equal -Wno-zero-as-null-pointer-constant "
"-Wno-cast-qual -Wno-missing-noreturn " "-Wno-cast-qual -Wno-missing-noreturn "
"-Wno-missing-braces -Wno-initializer-overrides " "-Wno-initializer-overrides "
"-Wno-c99-extensions -Wno-c++98-compat-pedantic -Wno-c++98-compat " "-Wno-c99-extensions -Wno-c++98-compat-pedantic -Wno-c++98-compat "
"-Wno-switch-enum -Wno-switch-default " "-Wno-switch-enum -Wno-switch-default "
"-Wno-reserved-identifier -Wno-reserved-macro-identifier " "-Wno-reserved-identifier -Wno-reserved-macro-identifier "
"-Wno-unsafe-buffer-usage -Wno-writable-strings " "-Wno-unsafe-buffer-usage "
"" "-Wno-c11-extensions -Wno-gnu-anonymous-struct -Wno-nested-anon-types ");
"-Wno-c11-extensions -Wno-gnu-anonymous-struct -Wno-nested-anon-types "
""
"-Wno-double-promotion");
/* -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter */ /* -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter */

View File

@ -125,15 +125,15 @@ extern "C" {
#if COMPILER_MSVC #if COMPILER_MSVC
# if DEBINFO # if DEBINFO
# define DEBUG_ALIAS(var, alias) *(alias) = &(var); # define DEBUG_ALIAS(var, alias) *(alias) = &(var)
# else # else
# define DEBUG_ALIAS(var, alias) *(alias) = &(var); # define DEBUG_ALIAS(var, alias) *(alias) = &(var)
# endif # endif
#else #else
# if DEBINFO # if DEBINFO
# define DEBUG_ALIAS(var, alias) __attribute((used)) *(alias) = &(var); # define DEBUG_ALIAS(var, alias) __attribute((used)) *(alias) = &(var)
# else # else
# define DEBUG_ALIAS(var, alias) __attribute((unused)) *(alias) = &(var); # define DEBUG_ALIAS(var, alias) __attribute((unused)) *(alias) = &(var)
# endif # endif
#endif #endif
@ -145,7 +145,7 @@ extern "C" {
# define ASSERT(cond) ((cond) ? 1 : (__builtin_trap(), 0)) # define ASSERT(cond) ((cond) ? 1 : (__builtin_trap(), 0))
# define DEBUGBREAK __builtin_debugtrap() # define DEBUGBREAK __builtin_debugtrap()
# endif # endif
# define DEBUGBREAKABLE { volatile i32 __DEBUGBREAKABLE_VAR = 0; (UNUSED) __DEBUGBREAKABLE_VAR; } # define DEBUGBREAKABLE { volatile i32 __DEBUGBREAKABLE_VAR = 0; (UNUSED) __DEBUGBREAKABLE_VAR; } (void)0
#else #else
# define ASSERT(cond) (void)(0) # define ASSERT(cond) (void)(0)
#endif #endif
@ -570,8 +570,8 @@ struct clip_rect {
struct v2 p0, p1; struct v2 p0, p1;
}; };
#define QUAD_UNIT_SQUARE (struct quad) { V2(0, 0), V2(0, 1), V2(1, 1), V2(1, 0) } #define QUAD_UNIT_SQUARE (struct quad) { .p0 = V2(0, 0), .p1 = V2(0, 1), .p2 = V2(1, 1), .p3 = V2(1, 0) }
#define QUAD_UNIT_SQUARE_CENTERED (struct quad) { V2(-0.5f, -0.5f), V2(0.5f, -0.5f), V2(0.5f, 0.5f), V2(-0.5f, 0.5f) } #define QUAD_UNIT_SQUARE_CENTERED (struct quad) { .p0 = V2(-0.5f, -0.5f), .p1 = V2(0.5f, -0.5f), .p2 = V2(0.5f, 0.5f), .p3 = V2(-0.5f, 0.5f) }
struct quad { struct quad {
union { union {
struct { struct v2 p0, p1, p2, p3; }; struct { struct v2 p0, p1, p2, p3; };

View File

@ -5,7 +5,7 @@
#define MEMZERO_ARRAY(a) MEMZERO((a), sizeof((a))) #define MEMZERO_ARRAY(a) MEMZERO((a), sizeof((a)))
#define MEMZERO(ptr, count) MEMSET((ptr), 0, (count)) #define MEMZERO(ptr, count) MEMSET((ptr), 0, (count))
#define MEMCPY_STRUCT(ptr_dst, ptr_src) MEMCPY((ptr_dst), (ptr_src), sizeof(*(ptr_dst))); #define MEMCPY_STRUCT(ptr_dst, ptr_src) MEMCPY((ptr_dst), (ptr_src), sizeof(*(ptr_dst)))
#define MEMCPY(dst, src, count) memcpy((dst), (src), (count)) #define MEMCPY(dst, src, count) memcpy((dst), (src), (count))
#define MEMCMP_STRUCT(p1, p2) MEMCMP((p1), (p2), sizeof(*p1)) #define MEMCMP_STRUCT(p1, p2) MEMCMP((p1), (p2), sizeof(*p1))

View File

@ -92,9 +92,7 @@ struct mp3_decode_result mp3_decode(struct arena *arena, struct string encoded,
* Read * Read
* ========================== */ * ========================== */
arena_align(arena, alignof(i16)); res.pcm.samples = arena_dry_push(arena, i16);
res.pcm.samples = (i16 *)arena_dry_push(arena, u8);
u64 sample_bytes_read = 0; u64 sample_bytes_read = 0;
while (true) { while (true) {
IMFSample *sample; IMFSample *sample;
@ -115,13 +113,13 @@ struct mp3_decode_result mp3_decode(struct arena *arena, struct string encoded,
IMFMediaBuffer *buffer; IMFMediaBuffer *buffer;
IMFSample_ConvertToContiguousBuffer(sample, &buffer); IMFSample_ConvertToContiguousBuffer(sample, &buffer);
BYTE *data; BYTE *src;
DWORD size; DWORD size_bytes;
IMFMediaBuffer_Lock(buffer, &data, NULL, &size); IMFMediaBuffer_Lock(buffer, &src, NULL, &size_bytes);
{ {
i16 *cursor = (i16 *)arena_push_array(arena, u8, size); i16 *dst = arena_push_array(arena, i16, (size_bytes + 1) >> 1);
MEMCPY(cursor, data, size); MEMCPY(dst, src, size_bytes);
sample_bytes_read += size; sample_bytes_read += size_bytes;
} }
IMFMediaBuffer_Unlock(buffer); IMFMediaBuffer_Unlock(buffer);

View File

@ -32,7 +32,7 @@ struct sim_ent *sim_ent_alloc_raw(struct sim_snapshot *ss, struct sim_ent *paren
ASSERT(ss == parent->ss); ASSERT(ss == parent->ss);
struct sim_ent *ent; struct sim_ent *ent;
if (ss->first_free_ent > 0 && ss->first_free_ent < ss->num_ents_reserved) { if (ss->first_free_ent > 0 && ss->first_free_ent < ss->num_ents_reserved) {
/* Reuse from free list */; /* Reuse from free list */
ent = &ss->ents[ss->first_free_ent]; ent = &ss->ents[ss->first_free_ent];
ss->first_free_ent = ent->next_free; ss->first_free_ent = ent->next_free;
} else { } else {

View File

@ -77,7 +77,7 @@ INTERNAL struct sock_address sock_address_from_ip_port_cstr(char *ip_cstr, char
if (status == 0) { if (status == 0) {
while (ai_res) { while (ai_res) {
if (ai_res->ai_family == AF_INET) { if (ai_res->ai_family == AF_INET) {
struct sockaddr_in *sockaddr = (struct sockaddr_in *)ai_res->ai_addr; struct sockaddr_in *sockaddr = (struct sockaddr_in *)(void *)ai_res->ai_addr;
res.valid = true; res.valid = true;
res.family = SOCK_ADDRESS_FAMILY_IPV4; res.family = SOCK_ADDRESS_FAMILY_IPV4;
res.portnb = sockaddr->sin_port; res.portnb = sockaddr->sin_port;

View File

@ -51,7 +51,7 @@ void space_reset(struct space *space)
{ {
arena_pop_to(&space->entry_arena, (u64)space->entries - (u64)space->entry_arena.base); arena_pop_to(&space->entry_arena, (u64)space->entries - (u64)space->entry_arena.base);
arena_reset(&space->cell_arena); arena_reset(&space->cell_arena);
space->bins = arena_push_array_zero(&space->cell_arena, struct space_cell_bin, space->num_bins);; space->bins = arena_push_array_zero(&space->cell_arena, struct space_cell_bin, space->num_bins);
space->num_entries_reserved = 0; space->num_entries_reserved = 0;
space->first_free_cell = NULL; space->first_free_cell = NULL;
space->first_free_cell_node = NULL; space->first_free_cell_node = NULL;

View File

@ -319,6 +319,7 @@ INTERNAL void node_refcount_add(struct cache_node *n, i32 amount)
struct cache_node_refcount new_refcount = *(struct cache_node_refcount *)&old_refcount_uncast; struct cache_node_refcount new_refcount = *(struct cache_node_refcount *)&old_refcount_uncast;
new_refcount.count += amount; new_refcount.count += amount;
new_refcount.last_modified_cycle = evictor_cycle; new_refcount.last_modified_cycle = evictor_cycle;
CT_ASSERT(sizeof(new_refcount) == sizeof(u64));
u64 v = atomic_u64_eval_compare_exchange(refcount_atomic, old_refcount_uncast, *(u64 *)&new_refcount); u64 v = atomic_u64_eval_compare_exchange(refcount_atomic, old_refcount_uncast, *(u64 *)&new_refcount);
if (v != old_refcount_uncast) { if (v != old_refcount_uncast) {
old_refcount_uncast = v; old_refcount_uncast = v;
@ -506,8 +507,7 @@ INTERNAL struct sprite_sheet init_sheet_from_ase_result(struct arena *arena, str
slice_group->name = string_copy(arena, temp_slice_group_node->name); slice_group->name = string_copy(arena, temp_slice_group_node->name);
slice_group->per_frame_count = temp_slice_group_node->per_frame_count; slice_group->per_frame_count = temp_slice_group_node->per_frame_count;
arena_align(arena, alignof(struct sprite_sheet_slice)); slice_group->frame_slices = arena_push_array_zero(arena, struct sprite_sheet_slice, ase.num_frames * slice_group->per_frame_count);
slice_group->frame_slices = (struct sprite_sheet_slice *)arena_push_array_zero(arena, u8, (ase.num_frames * slice_group->per_frame_count) * sizeof(struct sprite_sheet_slice));
u64 index_in_frame = 0; u64 index_in_frame = 0;
for (struct temp_ase_slice_key_node *node = temp_slice_group_node->temp_ase_slice_key_head; node; node = node->next) { for (struct temp_ase_slice_key_node *node = temp_slice_group_node->temp_ase_slice_key_head; node; node = node->next) {

View File

@ -1168,11 +1168,12 @@ INTERNAL LRESULT CALLBACK win32_window_proc(HWND hwnd, UINT msg, WPARAM wparam,
logf_error("GetRawInputData did not return correct size"); logf_error("GetRawInputData did not return correct size");
break; break;
} }
RAWINPUT *raw = (RAWINPUT *)buff; RAWINPUT raw = ZI;
MEMCPY(&raw, buff, sizeof(RAWINPUT));
if (raw->header.dwType == RIM_TYPEMOUSE) { if (raw.header.dwType == RIM_TYPEMOUSE) {
i32 x = raw->data.mouse.lLastX; i32 x = raw.data.mouse.lLastX;
i32 y = raw->data.mouse.lLastY; i32 y = raw.data.mouse.lLastY;
struct v2 delta = V2(x, y); struct v2 delta = V2(x, y);
win32_window_process_event( win32_window_process_event(
window, window,

View File

@ -43,7 +43,7 @@ struct thread_local_var_meta {
} \ } \
} }
#define THREAD_LOCAL_VAR_DECL_EXTERN(var_name, type) struct __thread_local_struct##var_name { struct thread_local_var_meta meta; type *_t; }; extern struct __thread_local_struct##var_name var_name; #define THREAD_LOCAL_VAR_DECL_EXTERN(var_name, type) struct __thread_local_struct##var_name { struct thread_local_var_meta meta; type *_t; }; extern struct __thread_local_struct##var_name var_name
#define THREAD_LOCAL_VAR_DEF_EXTERN(var_name, type, alloc_func, release_func) \ #define THREAD_LOCAL_VAR_DEF_EXTERN(var_name, type, alloc_func, release_func) \
struct __thread_local_struct##var_name var_name = { \ struct __thread_local_struct##var_name var_name = { \
.meta = { \ .meta = { \
@ -55,9 +55,9 @@ struct thread_local_var_meta {
} }
#if TYPEOF_DEFINED #if TYPEOF_DEFINED
# define thread_local_var_eval(var_ptr) (typeof((var_ptr)->_t))(_thread_local_var_eval(&(var_ptr)->meta)); # define thread_local_var_eval(var_ptr) (typeof((var_ptr)->_t))(_thread_local_var_eval(&(var_ptr)->meta))
#else #else
# define thread_local_var_eval(var_ptr) (void *)(_thread_local_var_eval(&(var_ptr)->meta)); # define thread_local_var_eval(var_ptr) (void *)(_thread_local_var_eval(&(var_ptr)->meta))
#endif #endif
void *_thread_local_var_eval(struct thread_local_var_meta *meta); void *_thread_local_var_eval(struct thread_local_var_meta *meta);

View File

@ -272,11 +272,10 @@ INTERNAL struct sys_event_array pop_sys_events(struct arena *arena)
struct sys_event_array array = ZI; struct sys_event_array array = ZI;
struct sys_lock lock = sys_mutex_lock_e(&G.sys_events_mutex); struct sys_lock lock = sys_mutex_lock_e(&G.sys_events_mutex);
{ {
struct string events_buff = arena_to_string(&G.sys_events_arena); struct sys_event *src_events = (struct sys_event *)G.sys_events_arena.base;
arena_align(arena, alignof(struct sys_event)); array.count = G.sys_events_arena.pos / sizeof(*src_events);
array.events = (struct sys_event *)arena_push_array(arena, u8, events_buff.len); array.events = arena_push_array(arena, struct sys_event, array.count);
array.count = events_buff.len / sizeof(struct sys_event); MEMCPY(array.events, src_events, array.count * sizeof(*src_events));
MEMCPY(array.events, events_buff.text, events_buff.len);
arena_reset(&G.sys_events_arena); arena_reset(&G.sys_events_arena);
} }
sys_mutex_unlock(&lock); sys_mutex_unlock(&lock);
@ -1747,7 +1746,7 @@ INTERNAL void user_update(void)
} }
/* Backbuffer texture */ /* Backbuffer texture */
if (!G.backbuffer_texture.handle || !v2i32_eq(renderer_texture_get_size(G.backbuffer_texture), backbuffer_resolution)) { if (!G.backbuffer_texture.handle || !v2i32_eq(renderer_texture_get_size(G.backbuffer_texture), backbuffer_resolution)) {
G.backbuffer_texture = renderer_backbuffer_recreate(backbuffer_resolution);; G.backbuffer_texture = renderer_backbuffer_recreate(backbuffer_resolution);
} }
} }