diff --git a/build.c b/build.c index ce9d01e7..095ebf70 100644 --- a/build.c +++ b/build.c @@ -476,20 +476,17 @@ void OnBuild(StringList cli_args) String warnings = Lit("-Weverything -Werror " "-Wframe-larger-than=65536 " "-Wno-unused-macros -Wno-gnu-zero-variadic-macro-arguments -Wno-documentation " - "-Wno-old-style-cast -Wno-conversion -Wno-sign-conversion " - "-Wno-declaration-after-statement -Wno-extra-semi -Wno-extra-semi-stmt " + "-Wno-old-style-cast -Wno-conversion -Wno-double-promotion " + "-Wno-declaration-after-statement " "-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-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-switch-enum -Wno-switch-default " "-Wno-reserved-identifier -Wno-reserved-macro-identifier " - "-Wno-unsafe-buffer-usage -Wno-writable-strings " - "" - "-Wno-c11-extensions -Wno-gnu-anonymous-struct -Wno-nested-anon-types " - "" - "-Wno-double-promotion"); + "-Wno-unsafe-buffer-usage " + "-Wno-c11-extensions -Wno-gnu-anonymous-struct -Wno-nested-anon-types "); /* -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter */ diff --git a/src/common.h b/src/common.h index e8d31664..6144c404 100644 --- a/src/common.h +++ b/src/common.h @@ -125,15 +125,15 @@ extern "C" { #if COMPILER_MSVC # if DEBINFO -# define DEBUG_ALIAS(var, alias) *(alias) = &(var); +# define DEBUG_ALIAS(var, alias) *(alias) = &(var) # else -# define DEBUG_ALIAS(var, alias) *(alias) = &(var); +# define DEBUG_ALIAS(var, alias) *(alias) = &(var) # endif #else # if DEBINFO -# define DEBUG_ALIAS(var, alias) __attribute((used)) *(alias) = &(var); +# define DEBUG_ALIAS(var, alias) __attribute((used)) *(alias) = &(var) # else -# define DEBUG_ALIAS(var, alias) __attribute((unused)) *(alias) = &(var); +# define DEBUG_ALIAS(var, alias) __attribute((unused)) *(alias) = &(var) # endif #endif @@ -145,7 +145,7 @@ extern "C" { # define ASSERT(cond) ((cond) ? 1 : (__builtin_trap(), 0)) # define DEBUGBREAK __builtin_debugtrap() # endif -# define DEBUGBREAKABLE { volatile i32 __DEBUGBREAKABLE_VAR = 0; (UNUSED) __DEBUGBREAKABLE_VAR; } +# define DEBUGBREAKABLE { volatile i32 __DEBUGBREAKABLE_VAR = 0; (UNUSED) __DEBUGBREAKABLE_VAR; } (void)0 #else # define ASSERT(cond) (void)(0) #endif @@ -570,8 +570,8 @@ struct clip_rect { 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_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 (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) { .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 { union { struct { struct v2 p0, p1, p2, p3; }; diff --git a/src/memory.h b/src/memory.h index 7b9c1ea6..df204576 100644 --- a/src/memory.h +++ b/src/memory.h @@ -5,7 +5,7 @@ #define MEMZERO_ARRAY(a) MEMZERO((a), sizeof((a))) #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 MEMCMP_STRUCT(p1, p2) MEMCMP((p1), (p2), sizeof(*p1)) diff --git a/src/mp3_mmf.c b/src/mp3_mmf.c index 75784108..28d58c52 100644 --- a/src/mp3_mmf.c +++ b/src/mp3_mmf.c @@ -92,9 +92,7 @@ struct mp3_decode_result mp3_decode(struct arena *arena, struct string encoded, * Read * ========================== */ - arena_align(arena, alignof(i16)); - res.pcm.samples = (i16 *)arena_dry_push(arena, u8); - + res.pcm.samples = arena_dry_push(arena, i16); u64 sample_bytes_read = 0; while (true) { IMFSample *sample; @@ -115,13 +113,13 @@ struct mp3_decode_result mp3_decode(struct arena *arena, struct string encoded, IMFMediaBuffer *buffer; IMFSample_ConvertToContiguousBuffer(sample, &buffer); - BYTE *data; - DWORD size; - IMFMediaBuffer_Lock(buffer, &data, NULL, &size); + BYTE *src; + DWORD size_bytes; + IMFMediaBuffer_Lock(buffer, &src, NULL, &size_bytes); { - i16 *cursor = (i16 *)arena_push_array(arena, u8, size); - MEMCPY(cursor, data, size); - sample_bytes_read += size; + i16 *dst = arena_push_array(arena, i16, (size_bytes + 1) >> 1); + MEMCPY(dst, src, size_bytes); + sample_bytes_read += size_bytes; } IMFMediaBuffer_Unlock(buffer); diff --git a/src/sim_ent.c b/src/sim_ent.c index 2202ca65..d31b3bde 100644 --- a/src/sim_ent.c +++ b/src/sim_ent.c @@ -32,7 +32,7 @@ struct sim_ent *sim_ent_alloc_raw(struct sim_snapshot *ss, struct sim_ent *paren ASSERT(ss == parent->ss); struct sim_ent *ent; 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]; ss->first_free_ent = ent->next_free; } else { diff --git a/src/sock_win32.c b/src/sock_win32.c index b83d713a..7c58f543 100644 --- a/src/sock_win32.c +++ b/src/sock_win32.c @@ -77,7 +77,7 @@ INTERNAL struct sock_address sock_address_from_ip_port_cstr(char *ip_cstr, char if (status == 0) { while (ai_res) { 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.family = SOCK_ADDRESS_FAMILY_IPV4; res.portnb = sockaddr->sin_port; diff --git a/src/space.c b/src/space.c index b0e0a26c..b436c3a0 100644 --- a/src/space.c +++ b/src/space.c @@ -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_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->first_free_cell = NULL; space->first_free_cell_node = NULL; diff --git a/src/sprite.c b/src/sprite.c index 0f315064..994525af 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -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; new_refcount.count += amount; 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); if (v != old_refcount_uncast) { 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->per_frame_count = temp_slice_group_node->per_frame_count; - arena_align(arena, alignof(struct sprite_sheet_slice)); - 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)); + slice_group->frame_slices = arena_push_array_zero(arena, struct sprite_sheet_slice, ase.num_frames * slice_group->per_frame_count); 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) { diff --git a/src/sys_win32.c b/src/sys_win32.c index 26aa12b6..4d2affee 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -1168,11 +1168,12 @@ INTERNAL LRESULT CALLBACK win32_window_proc(HWND hwnd, UINT msg, WPARAM wparam, logf_error("GetRawInputData did not return correct size"); break; } - RAWINPUT *raw = (RAWINPUT *)buff; + RAWINPUT raw = ZI; + MEMCPY(&raw, buff, sizeof(RAWINPUT)); - if (raw->header.dwType == RIM_TYPEMOUSE) { - i32 x = raw->data.mouse.lLastX; - i32 y = raw->data.mouse.lLastY; + if (raw.header.dwType == RIM_TYPEMOUSE) { + i32 x = raw.data.mouse.lLastX; + i32 y = raw.data.mouse.lLastY; struct v2 delta = V2(x, y); win32_window_process_event( window, diff --git a/src/thread_local.h b/src/thread_local.h index 83450e2a..3c58f6dd 100644 --- a/src/thread_local.h +++ b/src/thread_local.h @@ -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) \ struct __thread_local_struct##var_name var_name = { \ .meta = { \ @@ -55,9 +55,9 @@ struct thread_local_var_meta { } #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 -# 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 void *_thread_local_var_eval(struct thread_local_var_meta *meta); diff --git a/src/user.c b/src/user.c index 969679a8..ad4e2853 100644 --- a/src/user.c +++ b/src/user.c @@ -272,11 +272,10 @@ INTERNAL struct sys_event_array pop_sys_events(struct arena *arena) struct sys_event_array array = ZI; struct sys_lock lock = sys_mutex_lock_e(&G.sys_events_mutex); { - struct string events_buff = arena_to_string(&G.sys_events_arena); - arena_align(arena, alignof(struct sys_event)); - array.events = (struct sys_event *)arena_push_array(arena, u8, events_buff.len); - array.count = events_buff.len / sizeof(struct sys_event); - MEMCPY(array.events, events_buff.text, events_buff.len); + struct sys_event *src_events = (struct sys_event *)G.sys_events_arena.base; + array.count = G.sys_events_arena.pos / sizeof(*src_events); + array.events = arena_push_array(arena, struct sys_event, array.count); + MEMCPY(array.events, src_events, array.count * sizeof(*src_events)); arena_reset(&G.sys_events_arena); } sys_mutex_unlock(&lock); @@ -1747,7 +1746,7 @@ INTERNAL void user_update(void) } /* Backbuffer texture */ 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); } }