diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-08-28 15:35:48 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-08-28 15:35:48 -0400 |
commit | 38e5501205573597c6b8ef92e56ca76141b8e792 (patch) | |
tree | 1ade260689696b812e45ad5d2e43a4b7a71cff38 /util | |
parent | 1661532486d742462f834d2e57f1ad827d6e8916 (diff) |
Improved types (now gives error when you annotate the wrong type)
Diffstat (limited to 'util')
-rw-r--r-- | util/str.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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; } |