Skip to content

Commit

Permalink
Merge pull request #144 from Zondax/feat/use_size_t
Browse files Browse the repository at this point in the history
Replace uint16_t with size_t for Buffer size definitions
  • Loading branch information
neithanmo authored Sep 17, 2024
2 parents 50df5b5 + 9629aa2 commit 33f5c38
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions include/buffering.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extern "C" {

typedef struct {
uint8_t *data;
uint16_t size;
uint16_t pos;
size_t size;
size_t pos;
uint8_t in_use: 1;
} buffer_state_t;

Expand All @@ -37,9 +37,9 @@ typedef struct {
/// \param flash_buffer
/// \param flash_buffer_size
void buffering_init(uint8_t *ram_buffer,
uint16_t ram_buffer_size,
size_t ram_buffer_size,
uint8_t *flash_buffer,
uint16_t flash_buffer_size);
size_t flash_buffer_size);

/// Reset buffer
void buffering_reset();
Expand All @@ -48,7 +48,7 @@ void buffering_reset();
/// \param data
/// \param length
/// \return the number of appended bytes
int buffering_append(uint8_t *data, int length);
int buffering_append(uint8_t *data, size_t length);

/// buffering_get_ram_buffer
/// \return
Expand Down
2 changes: 1 addition & 1 deletion include/zxversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

#define ZXLIB_MAJOR 28
#define ZXLIB_MINOR 0
#define ZXLIB_PATCH 6
#define ZXLIB_PATCH 7
10 changes: 5 additions & 5 deletions src/buffering.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ buffer_state_t ram; // Ram
buffer_state_t flash; // Flash

void buffering_init(uint8_t *ram_buffer,
uint16_t ram_buffer_size,
size_t ram_buffer_size,
uint8_t *flash_buffer,
uint16_t flash_buffer_size) {
size_t flash_buffer_size) {
ram.data = ram_buffer;
ram.size = ram_buffer_size;
ram.pos = 0;
Expand All @@ -46,11 +46,11 @@ void buffering_reset() {
flash.in_use = 0;
}

int buffering_append(uint8_t *data, int length) {
int buffering_append(uint8_t *data, size_t length) {
if (ram.in_use) {
if (ram.size - ram.pos >= length) {
// RAM in use, append to ram if there is enough space
MEMCPY(ram.data + ram.pos, data, (size_t) length);
MEMCPY(ram.data + ram.pos, data, length);
ram.pos += length;
} else {
// If RAM is not big enough copy memory to flash
Expand All @@ -66,7 +66,7 @@ int buffering_append(uint8_t *data, int length) {
} else {
// Flash in use, append to flash
if (flash.size - flash.pos >= length) {
MEMCPY_NV(flash.data + flash.pos, data, (size_t) length);
MEMCPY_NV(flash.data + flash.pos, data, length);
flash.pos += length;
} else {
return 0;
Expand Down

0 comments on commit 33f5c38

Please sign in to comment.