mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-23 07:58:09 +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 "strl.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
size_t strlcpy(char *dst, const char *src, size_t size) {
|
size_t strlcpy(char *dst, const char *src, size_t size) {
|
||||||
if (size == 0) {
|
size_t ret = strlen(src);
|
||||||
return strlen(src);
|
|
||||||
|
if (size) {
|
||||||
|
size_t len = MIN(ret, size - 1);
|
||||||
|
memcpy(dst, src, len);
|
||||||
|
dst[len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t i;
|
return ret;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t strlcat(char *dst, const char *src, size_t size) {
|
size_t strlcat(char *dst, const char *src, size_t size) {
|
||||||
|
Loading…
Reference in New Issue
Block a user