mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 17:38:39 +00:00
emulator: Refactor strlcpy
Performance is unimportant and this implementation makes it easier to fuzz.
This commit is contained in:
parent
e3a0b6e7b4
commit
b4e3cd3e0c
@ -18,27 +18,20 @@
|
||||
*/
|
||||
|
||||
#include "strl.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strlcpy(char *dst, const char *src, size_t size) {
|
||||
if (size == 0) {
|
||||
return strlen(src);
|
||||
size_t ret = strlen(src);
|
||||
|
||||
if (size) {
|
||||
size_t len = MIN(ret, size - 1);
|
||||
memcpy(dst, src, len);
|
||||
dst[len] = '\0';
|
||||
}
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < size - 1; i++) {
|
||||
dst[i] = src[i];
|
||||
|
||||
if (src[i] == '\0') {
|
||||
return i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
dst[size - 1] = '\0';
|
||||
|
||||
while (src[i++] != '\0');
|
||||
return i - 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t strlcat(char *dst, const char *src, size_t size) {
|
||||
|
Loading…
Reference in New Issue
Block a user