Skip to content

Commit

Permalink
use compile-time constants for buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
janmazak committed Jun 22, 2022
1 parent 2855f6a commit bc4f169
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/base58.c
Expand Up @@ -20,7 +20,7 @@
#include "common.h"
#include "base58.h"

static const uint32_t MAX_BUFFER_SIZE = 124;
#define MAX_BUFFER_SIZE 124

static const char BASE58ALPHABET[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

Expand Down
8 changes: 4 additions & 4 deletions src/bech32.c
Expand Up @@ -84,13 +84,13 @@ void bech32_encode_5bit(const char *hrp, const uint8_t *data,
APPEND_OUT(0);
}

// we are not supposed to use more for Cardano Shelley
// WARNING: increasing this would take more stack space, see data5bit definition below
#define MAX_BYTES 65

size_t bech32_encode(const char *hrp, const uint8_t *bytes, size_t bytesSize,
char *output, size_t maxOutputSize)
{
// we are not supposed to use more for Cardano Shelley
// WARNING: increasing this would take more stack space, see data5bit definition below
const size_t MAX_BYTES = 65;

ASSERT(bytesSize <= MAX_BYTES);
ASSERT(strlen(hrp) >= 1); // not allowed for bech32

Expand Down
2 changes: 1 addition & 1 deletion src/cardano.h
Expand Up @@ -152,7 +152,7 @@ typedef struct {
// ============================== NATIVE SCRIPTS ==============================

// depth of n means it can handle up to n-1 levels of nesting
static const uint8_t MAX_SCRIPT_DEPTH = 11;
#define MAX_SCRIPT_DEPTH 11

typedef enum {
NATIVE_SCRIPT_PUBKEY = 0,
Expand Down
5 changes: 4 additions & 1 deletion src/getSerial.c
Expand Up @@ -4,6 +4,10 @@
#include "getSerial.h"
#include "uiHelpers.h"

// required by os_serial
#define SERIAL_LENGTH 7


void getSerial_handleAPDU(
uint8_t p1,
uint8_t p2,
Expand All @@ -19,7 +23,6 @@ void getSerial_handleAPDU(
STATIC_ASSERT(sizeof(uint8_t) == sizeof(unsigned char), "bad unsigned char size");
STATIC_ASSERT(sizeof(size_t) >= sizeof(unsigned int), "bad unsigned int size");

const size_t SERIAL_LENGTH = 7; // if too short, exception 2 is thrown by os_serial
uint8_t response[SERIAL_LENGTH] = {0};
size_t len = os_serial(response, SERIAL_LENGTH);
ASSERT(len == SERIAL_LENGTH);
Expand Down

0 comments on commit bc4f169

Please sign in to comment.