Skip to content

Commit

Permalink
add explicitly sized fields for addresses/values/ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras committed Oct 16, 2023
1 parent 94a2ba5 commit 6481983
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 81 deletions.
63 changes: 33 additions & 30 deletions src/rc_libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,46 +676,49 @@ void rc_libretro_hash_set_init(struct rc_libretro_hash_set_t* hash_set,
rc_file_seek(file_handle, 0, SEEK_SET);

m3u_contents = (char*)malloc((size_t)file_len + 1);
rc_file_read(file_handle, m3u_contents, (int)file_len);
m3u_contents[file_len] = '\0';

rc_file_close(file_handle);

ptr = m3u_contents;
do
if (m3u_contents)
{
/* ignore whitespace */
while (isspace((int)*ptr))
++ptr;
rc_file_read(file_handle, m3u_contents, (int)file_len);
m3u_contents[file_len] = '\0';

rc_file_close(file_handle);

if (*ptr == '#')
ptr = m3u_contents;
do
{
/* ignore comment unless it's the special SAVEDISK extension */
if (memcmp(ptr, "#SAVEDISK:", 10) == 0)
/* ignore whitespace */
while (isspace((int)*ptr))
++ptr;

if (*ptr == '#')
{
/* get the path to the save disk from the frontend, assign it a bogus hash so
* it doesn't get hashed later */
if (get_image_path(index, image_path, sizeof(image_path)))
/* ignore comment unless it's the special SAVEDISK extension */
if (memcmp(ptr, "#SAVEDISK:", 10) == 0)
{
const char save_disk_hash[33] = "[SAVE DISK]";
rc_libretro_hash_set_add(hash_set, image_path, -1, save_disk_hash);
++index;
/* get the path to the save disk from the frontend, assign it a bogus hash so
* it doesn't get hashed later */
if (get_image_path(index, image_path, sizeof(image_path)))
{
const char save_disk_hash[33] = "[SAVE DISK]";
rc_libretro_hash_set_add(hash_set, image_path, -1, save_disk_hash);
++index;
}
}
}
}
else
{
/* non-empty line, tally a file */
++index;
}
else
{
/* non-empty line, tally a file */
++index;
}

/* find the end of the line */
while (*ptr && *ptr != '\n')
++ptr;
/* find the end of the line */
while (*ptr && *ptr != '\n')
++ptr;

} while (*ptr);
} while (*ptr);

free(m3u_contents);
free(m3u_contents);
}

if (hash_set->entries_count > 0)
{
Expand Down
16 changes: 8 additions & 8 deletions src/rc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void rc_buffer_destroy(rc_buffer_t* buffer)
#endif
}

char* rc_buffer_reserve(rc_buffer_t* buffer, size_t amount)
uint8_t* rc_buffer_reserve(rc_buffer_t* buffer, size_t amount)
{
rc_buffer_chunk_t* chunk = &buffer->chunk;
size_t remaining;
Expand All @@ -70,9 +70,9 @@ char* rc_buffer_reserve(rc_buffer_t* buffer, size_t amount)
if (!chunk->next)
break;

chunk->next->start = (char*)chunk->next + chunk_header_size;
chunk->next->start = (uint8_t*)chunk->next + chunk_header_size;
chunk->next->write = chunk->next->start;
chunk->next->end = (char*)chunk->next + alloc_size;
chunk->next->end = (uint8_t*)chunk->next + alloc_size;
chunk->next->next = NULL;
}

Expand All @@ -82,7 +82,7 @@ char* rc_buffer_reserve(rc_buffer_t* buffer, size_t amount)
return NULL;
}

void rc_buffer_consume(rc_buffer_t* buffer, const char* start, char* end)
void rc_buffer_consume(rc_buffer_t* buffer, const uint8_t* start, uint8_t* end)
{
rc_buffer_chunk_t* chunk = &buffer->chunk;
do
Expand All @@ -104,14 +104,14 @@ void rc_buffer_consume(rc_buffer_t* buffer, const char* start, char* end)

void* rc_buffer_alloc(rc_buffer_t* buffer, size_t amount)
{
char* ptr = rc_buffer_reserve(buffer, amount);
uint8_t* ptr = rc_buffer_reserve(buffer, amount);
rc_buffer_consume(buffer, ptr, ptr + amount);
return (void*)ptr;
}

char* rc_buffer_strncpy(rc_buffer_t* buffer, const char* src, size_t len)
{
char* dst = rc_buffer_reserve(buffer, len + 1);
char* dst = (char*)rc_buffer_reserve(buffer, len + 1);
memcpy(dst, src, len);
dst[len] = '\0';
rc_buffer_consume(buffer, dst, dst + len + 2);
Expand All @@ -133,9 +133,9 @@ void rc_format_md5(char checksum[33], const unsigned char digest[16])
);
}

unsigned rc_djb2(const char* input)
uint32_t rc_djb2(const char* input)
{
unsigned result = 5381;
uint32_t result = 5381;
char c;

while ((c = *input++) != '\0')
Expand Down
15 changes: 8 additions & 7 deletions src/rc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define RC_UTIL_H

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -12,11 +13,11 @@ extern "C" {
*/
typedef struct rc_buffer_chunk_t {
/* The current location where data is being written */
char* write;
uint8_t* write;
/* The first byte past the end of data where writing cannot occur */
char* end;
uint8_t* end;
/* The first byte of the data */
char* start;
uint8_t* start;
/* The next block in the allocated memory chain */
struct rc_buffer_chunk_t* next;
}
Expand All @@ -29,19 +30,19 @@ typedef struct rc_buffer_t {
/* The chunk data (will point at the local data member) */
struct rc_buffer_chunk_t chunk;
/* Small chunk of memory pre-allocated for the chunk */
char data[256];
uint8_t data[256];
}
rc_buffer_t;

void rc_buffer_init(rc_buffer_t* buffer);
void rc_buffer_destroy(rc_buffer_t* buffer);
char* rc_buffer_reserve(rc_buffer_t* buffer, size_t amount);
void rc_buffer_consume(rc_buffer_t* buffer, const char* start, char* end);
uint8_t* rc_buffer_reserve(rc_buffer_t* buffer, size_t amount);
void rc_buffer_consume(rc_buffer_t* buffer, const uint8_t* start, uint8_t* end);
void* rc_buffer_alloc(rc_buffer_t* buffer, size_t amount);
char* rc_buffer_strcpy(rc_buffer_t* buffer, const char* src);
char* rc_buffer_strncpy(rc_buffer_t* buffer, const char* src, size_t len);

unsigned rc_djb2(const char* input);
uint32_t rc_djb2(const char* input);

void rc_format_md5(char checksum[33], const unsigned char digest[16]);

Expand Down
2 changes: 0 additions & 2 deletions src/rcheevos/rc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ void* rc_alloc(void* pointer, int* offset, int size, int alignment, rc_scratch_t
void* rc_alloc_scratch(void* pointer, int* offset, int size, int alignment, rc_scratch_t* scratch, int scratch_object_pointer_offset);
char* rc_alloc_str(rc_parse_state_t* parse, const char* text, int length);

unsigned rc_djb2(const char* input);

rc_memref_t* rc_alloc_memref(rc_parse_state_t* parse, uint32_t address, uint8_t size, uint8_t is_indirect);
int rc_parse_memref(const char** memaddr, uint8_t* size, uint32_t* address);
void rc_update_memref_values(rc_memref_t* memref, rc_peek_t peek, void* ud);
Expand Down
Loading

0 comments on commit 6481983

Please sign in to comment.