From 38e5501205573597c6b8ef92e56ca76141b8e792 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Wed, 28 Aug 2019 15:35:48 -0400 Subject: Improved types (now gives error when you annotate the wrong type) --- util/str.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/str.c b/util/str.c index b05cc63..ac4fb26 100644 --- a/util/str.c +++ b/util/str.c @@ -6,13 +6,18 @@ destsz must be greater than 0. */ size_t str_copy(char *dest, size_t destsz, const char *src) { assert(destsz); + if (!*src) { + *dest = 0; + return 0; + } for (size_t i = 0; i < destsz-1; i++) { + *dest = *src; if (!*src) { *dest = 0; return i; } - *dest++ = *src++; + src++; dest++; } - dest[destsz] = 0; + dest[destsz-1] = 0; return destsz-1; } -- cgit v1.2.3