From d403503d5af9fc02978b469df91908f3f390b8dc Mon Sep 17 00:00:00 2001 From: Jamiras Date: Sat, 4 Nov 2023 12:46:51 -0600 Subject: [PATCH] more fixed size types --- src/rapi/rc_api_common.c | 8 ++++---- src/rc_util.c | 2 +- src/rcheevos/alloc.c | 12 +++++++----- src/rcheevos/runtime.c | 2 +- src/rhash/hash.c | 6 +++--- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/rapi/rc_api_common.c b/src/rapi/rc_api_common.c index 481aee07..96c32b32 100644 --- a/src/rapi/rc_api_common.c +++ b/src/rapi/rc_api_common.c @@ -18,7 +18,7 @@ static char* g_imagehost = NULL; /* --- rc_json --- */ -static int rc_json_parse_object(rc_json_iterator_t* iterator, rc_json_field_t* fields, size_t field_count, unsigned* fields_seen); +static int rc_json_parse_object(rc_json_iterator_t* iterator, rc_json_field_t* fields, size_t field_count, uint32_t* fields_seen); static int rc_json_parse_array(rc_json_iterator_t* iterator, rc_json_field_t* field); static int rc_json_match_char(rc_json_iterator_t* iterator, char c) @@ -182,7 +182,7 @@ static int rc_json_get_next_field(rc_json_iterator_t* iterator, rc_json_field_t* return RC_OK; } -static int rc_json_parse_object(rc_json_iterator_t* iterator, rc_json_field_t* fields, size_t field_count, unsigned* fields_seen) { +static int rc_json_parse_object(rc_json_iterator_t* iterator, rc_json_field_t* fields, size_t field_count, uint32_t* fields_seen) { size_t i; uint32_t num_fields = 0; rc_json_field_t field; @@ -437,14 +437,14 @@ int rc_json_get_required_unum_array(uint32_t** entries, uint32_t* num_entries, r rc_json_iterator_t iterator; rc_json_field_t array; rc_json_field_t value; - unsigned* entry; + uint32_t* entry; memset(&array, 0, sizeof(array)); if (!rc_json_get_required_array(num_entries, &array, response, field, field_name)) return RC_MISSING_VALUE; if (*num_entries) { - *entries = (unsigned*)rc_buffer_alloc(&response->buffer, *num_entries * sizeof(unsigned)); + *entries = (uint32_t*)rc_buffer_alloc(&response->buffer, *num_entries * sizeof(uint32_t)); if (!*entries) return RC_OUT_OF_MEMORY; diff --git a/src/rc_util.c b/src/rc_util.c index 9deee91b..fa369a3b 100644 --- a/src/rc_util.c +++ b/src/rc_util.c @@ -35,7 +35,7 @@ void rc_buffer_destroy(rc_buffer_t* buffer) { rc_buffer_chunk_t* next = chunk->next; #ifdef DEBUG_BUFFERS - total += (int)(chunk->end - chunk->data); + total += (int)(chunk->end - chunk->start); wasted += (int)(chunk->end - chunk->write); ++count; #endif diff --git a/src/rcheevos/alloc.c b/src/rcheevos/alloc.c index 7c2af1f3..7b43a2c7 100644 --- a/src/rcheevos/alloc.c +++ b/src/rcheevos/alloc.c @@ -22,11 +22,13 @@ void* rc_alloc_scratch(void* pointer, int32_t* offset, uint32_t size, uint32_t a buffer = &scratch->buffer; do { const uint32_t aligned_buffer_offset = (buffer->offset + alignment - 1) & ~(alignment - 1); - const uint32_t remaining = sizeof(buffer->buffer) - aligned_buffer_offset; + if (aligned_buffer_offset < sizeof(buffer->buffer)) { + const uint32_t remaining = sizeof(buffer->buffer) - aligned_buffer_offset; - if (remaining >= size) { - /* claim the required space from an existing buffer */ - return rc_alloc(buffer->buffer, &buffer->offset, size, alignment, NULL, -1); + if (remaining >= size) { + /* claim the required space from an existing buffer */ + return rc_alloc(buffer->buffer, &buffer->offset, size, alignment, NULL, -1); + } } if (!buffer->next) @@ -76,7 +78,7 @@ void* rc_alloc(void* pointer, int32_t* offset, uint32_t size, uint32_t alignment void** scratch_object_pointer = (void**)((char*)&scratch->objs + scratch_object_pointer_offset); ptr = *scratch_object_pointer; if (!ptr) { - int used; + int32_t used; ptr = *scratch_object_pointer = rc_alloc_scratch(NULL, &used, size, alignment, scratch, -1); } } diff --git a/src/rcheevos/runtime.c b/src/rcheevos/runtime.c index d663b7a9..1821558d 100644 --- a/src/rcheevos/runtime.c +++ b/src/rcheevos/runtime.c @@ -128,7 +128,7 @@ int rc_runtime_activate_achievement(rc_runtime_t* self, uint32_t id, const char* rc_runtime_trigger_t* runtime_trigger; rc_parse_state_t parse; uint8_t md5[16]; - int size; + uint32_t size; uint32_t i; if (memaddr == NULL) diff --git a/src/rhash/hash.c b/src/rhash/hash.c index a953d525..06fc03f2 100644 --- a/src/rhash/hash.c +++ b/src/rhash/hash.c @@ -1612,7 +1612,7 @@ static int rc_hash_dreamcast(char hash[33], const char* path) } static int rc_hash_find_playstation_executable(void* track_handle, const char* boot_key, const char* cdrom_prefix, - char exe_name[], uint32_t exe_name_size, unsigned* exe_size) + char exe_name[], uint32_t exe_name_size, uint32_t* exe_size) { uint8_t buffer[2048]; uint32_t size; @@ -1626,7 +1626,7 @@ static int rc_hash_find_playstation_executable(void* track_handle, const char* b if (!sector) return 0; - size = (unsigned)rc_cd_read_sector(track_handle, sector, buffer, sizeof(buffer) - 1); + size = (uint32_t)rc_cd_read_sector(track_handle, sector, buffer, sizeof(buffer) - 1); buffer[size] = '\0'; sector = 0; @@ -1653,7 +1653,7 @@ static int rc_hash_find_playstation_executable(void* track_handle, const char* b while (!isspace((unsigned char)*ptr) && *ptr != ';') ++ptr; - size = (unsigned)(ptr - start); + size = (uint32_t)(ptr - start); if (size >= exe_name_size) size = exe_name_size - 1;