1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

emulator: Refactor strlcpy

Performance is unimportant and this implementation makes it easier to
fuzz.
This commit is contained in:
Saleem Rashid 2018-02-14 10:48:47 +00:00 committed by Pavol Rusnak
parent e3a0b6e7b4
commit b4e3cd3e0c

View File

@ -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) {