mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-08-05 13:14:19 -04:00
fw: Safer memory functions + asserts
Introduce memcpy_s() and wordcpy_s() that takes the destination buffer size as an argument. Use assert() which aborts our program to an eternal loop if we hit problems. Sprinkle asserts elsewhere as well. Signed-off-by: Daniel Lublin <daniel@lublin.se>
This commit is contained in:
parent
f386cec1ed
commit
ccc3b16569
7 changed files with 81 additions and 23 deletions
25
hw/application_fpga/fw/tk1/assert.c
Normal file
25
hw/application_fpga/fw/tk1/assert.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (C) 2022, 2023 - Tillitis AB
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*/
|
||||
|
||||
#include "assert.h"
|
||||
#include "lib.h"
|
||||
|
||||
void __assert_fail(const char *__assertion, const char *__file,
|
||||
unsigned int __line, const char *__function)
|
||||
{
|
||||
htif_puts("assert: ");
|
||||
htif_puts(__assertion);
|
||||
htif_puts(" ");
|
||||
htif_puts(__file);
|
||||
htif_puts(":");
|
||||
htif_putinthex(__line);
|
||||
htif_puts(" ");
|
||||
htif_puts(__function);
|
||||
htif_lf();
|
||||
|
||||
for (;;);
|
||||
|
||||
// Not reached
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue