EIP-712 code linting

This commit is contained in:
Alexandre Paillier
2022-07-19 11:49:18 +02:00
parent 0cf21cdf73
commit de9e895ad9
44 changed files with 778 additions and 1402 deletions

View File

@@ -5,23 +5,20 @@
#define SIZE_MEM_BUFFER 5120
static uint8_t mem_buffer[SIZE_MEM_BUFFER];
static size_t mem_idx;
static uint8_t mem_buffer[SIZE_MEM_BUFFER];
static size_t mem_idx;
/**
* Initializes the memory buffer index
*/
void mem_init(void)
{
void mem_init(void) {
mem_idx = 0;
}
/**
* Resets the memory buffer index
*/
void mem_reset(void)
{
void mem_reset(void) {
mem_init();
}
@@ -34,9 +31,8 @@ void mem_reset(void)
* @param[in] size Requested allocation size in bytes
* @return Allocated memory pointer; \ref NULL if not enough space left.
*/
void *mem_alloc(size_t size)
{
if ((mem_idx + size) > SIZE_MEM_BUFFER) // Buffer exceeded
void *mem_alloc(size_t size) {
if ((mem_idx + size) > SIZE_MEM_BUFFER) // Buffer exceeded
{
return NULL;
}
@@ -49,16 +45,13 @@ void *mem_alloc(size_t size)
*
* @param[in] size Requested deallocation size in bytes
*/
void mem_dealloc(size_t size)
{
if (size > mem_idx) // More than is already allocated
void mem_dealloc(size_t size) {
if (size > mem_idx) // More than is already allocated
{
mem_idx = 0;
}
else
{
} else {
mem_idx -= size;
}
}
#endif // HAVE_DYN_MEM_ALLOC
#endif // HAVE_DYN_MEM_ALLOC

View File

@@ -5,11 +5,11 @@
#include <stdlib.h>
void mem_init(void);
void mem_reset(void);
void *mem_alloc(size_t size);
void mem_dealloc(size_t size);
void mem_init(void);
void mem_reset(void);
void *mem_alloc(size_t size);
void mem_dealloc(size_t size);
#endif // HAVE_DYN_MEM_ALLOC
#endif // HAVE_DYN_MEM_ALLOC
#endif // MEM_H_
#endif // MEM_H_

View File

@@ -14,26 +14,22 @@
*
* @return pointer to memory area or \ref NULL if the allocation failed
*/
char *mem_alloc_and_format_uint(uint32_t value, uint8_t *const length)
{
char *mem_ptr;
uint32_t value_copy;
uint8_t size;
char *mem_alloc_and_format_uint(uint32_t value, uint8_t *const length) {
char *mem_ptr;
uint32_t value_copy;
uint8_t size;
size = 1; // minimum size, even if 0
size = 1; // minimum size, even if 0
value_copy = value;
while (value_copy >= 10)
{
while (value_copy >= 10) {
value_copy /= 10;
size += 1;
}
// +1 for the null character
if ((mem_ptr = mem_alloc(sizeof(char) * (size + 1))))
{
if ((mem_ptr = mem_alloc(sizeof(char) * (size + 1)))) {
snprintf(mem_ptr, (size + 1), "%u", value);
mem_dealloc(sizeof(char)); // to skip the null character
if (length != NULL)
{
mem_dealloc(sizeof(char)); // to skip the null character
if (length != NULL) {
*length = size;
}
}
@@ -49,18 +45,16 @@ char *mem_alloc_and_format_uint(uint32_t value, uint8_t *const length)
*
* @return pointer to the memory area, \ref NULL if the allocation failed
*/
void *mem_alloc_and_align(size_t size, size_t alignment)
{
uint8_t align_diff = (uintptr_t)mem_alloc(0) % alignment;
void *mem_alloc_and_align(size_t size, size_t alignment) {
uint8_t align_diff = (uintptr_t) mem_alloc(0) % alignment;
if (align_diff > 0) // alignment needed
if (align_diff > 0) // alignment needed
{
if (mem_alloc(alignment - align_diff) == NULL)
{
if (mem_alloc(alignment - align_diff) == NULL) {
return NULL;
}
}
return mem_alloc(size);
}
#endif // HAVE_DYN_MEM_ALLOC
#endif // HAVE_DYN_MEM_ALLOC

View File

@@ -6,11 +6,11 @@
#include <stdint.h>
#include <stdbool.h>
#define MEM_ALLOC_AND_ALIGN_TYPE(type) mem_alloc_and_align(sizeof(type), __alignof__(type))
#define MEM_ALLOC_AND_ALIGN_TYPE(type) mem_alloc_and_align(sizeof(type), __alignof__(type))
char *mem_alloc_and_format_uint(uint32_t value, uint8_t *const written_chars);
void *mem_alloc_and_align(size_t size, size_t alignment);
char *mem_alloc_and_format_uint(uint32_t value, uint8_t *const written_chars);
void *mem_alloc_and_align(size_t size, size_t alignment);
#endif // HAVE_DYN_MEM_ALLOC
#endif // HAVE_DYN_MEM_ALLOC
#endif // MEM_UTILS_H_
#endif // MEM_UTILS_H_

View File

@@ -21,7 +21,7 @@
#include <string.h>
#include "uint128.h"
#include "uint_common.h"
#include "ethUtils.h" // HEXDIGITS
#include "ethUtils.h" // HEXDIGITS
void readu128BE(const uint8_t *const buffer, uint128_t *const target) {
UPPER_P(target) = readUint64BE(buffer);

View File

@@ -21,8 +21,8 @@
#include <string.h>
#include "uint256.h"
#include "uint_common.h"
#include "ethUstream.h" // INT256_LENGTH
#include "ethUtils.h" // HEXDIGITS
#include "ethUstream.h" // INT256_LENGTH
#include "ethUtils.h" // HEXDIGITS
void readu256BE(const uint8_t *const buffer, uint256_t *const target) {
readu128BE(buffer, &UPPER_P(target));

View File

@@ -58,5 +58,4 @@ bool tostring256_signed(const uint256_t *const number,
char *const out,
uint32_t out_length);
#endif // _UINT256_H_

View File

@@ -32,4 +32,4 @@ void read_u64_be(const uint8_t *const in, uint64_t *const out);
uint64_t readUint64BE(const uint8_t *const buffer);
void reverseString(char *const str, uint32_t length);
#endif //_UINT_COMMON_H_
#endif //_UINT_COMMON_H_