From a118928dee0874eef98be81531a98577c1ae3f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 5 Jan 2021 14:44:09 +0100 Subject: XUtils: add safe strncpy implementation The standard strncpy fails to null-terminate the destination in case the source is longer than the passed size. --- XUtils.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'XUtils.h') diff --git a/XUtils.h b/XUtils.h index 9e5e62cf..6066aa95 100644 --- a/XUtils.h +++ b/XUtils.h @@ -59,6 +59,9 @@ char* String_getToken(const char* line, unsigned short int numMatch); char* String_readLine(FILE* fd); +/* Always null-terminates dest. Caller must pass a strictly positive size. */ +size_t String_safeStrncpy(char *restrict dest, const char *restrict src, size_t size); + ATTR_FORMAT(printf, 2, 3) int xAsprintf(char** strp, const char* fmt, ...); -- cgit v1.2.3