summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/str.c9
1 files changed, 7 insertions, 2 deletions
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;
}