if duplicating strings, it’s idiotic to use strlcpy(3) when we know

the sizes (checked)
This commit is contained in:
tg 2009-08-01 20:29:25 +00:00
parent cfa64cebd1
commit 68f9bfa689
2 changed files with 13 additions and 10 deletions

7
misc.c
View File

@ -29,7 +29,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.112 2009/07/25 21:31:26 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.113 2009/08/01 20:29:24 tg Exp $");
#undef USE_CHVT #undef USE_CHVT
/* XXX conditions correct? */ /* XXX conditions correct? */
@ -1479,8 +1479,9 @@ strndup_(const char *src, size_t len, Area *ap)
char *dst = NULL; char *dst = NULL;
if (src != NULL) { if (src != NULL) {
dst = alloc(++len, ap); dst = alloc(len + 1, ap);
strlcpy(dst, src, len); memcpy(dst, src, len);
dst[len] = '\0';
} }
return (dst); return (dst);
} }

16
sh.h
View File

@ -134,7 +134,7 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.319 2009/08/01 14:21:30 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.320 2009/08/01 20:29:25 tg Exp $");
#endif #endif
#define MKSH_VERSION "R39 2009/08/01" #define MKSH_VERSION "R39 2009/08/01"
@ -422,9 +422,10 @@ char *ucstrstr(char *, const char *);
char *strdup_dst = NULL; \ char *strdup_dst = NULL; \
\ \
if (strdup_src != NULL) { \ if (strdup_src != NULL) { \
size_t strdup_len = strlen(strdup_src) + 1; \ size_t strdup_len = strlen(strdup_src); \
strdup_dst = alloc(strdup_len, (ap)); \ strdup_dst = alloc(strdup_len + 1, (ap)); \
strlcpy(strdup_dst, strdup_src, strdup_len); \ memcpy(strdup_dst, strdup_src, strdup_len); \
strdup_dst[strdup_len] = '\0'; \
} \ } \
(d) = strdup_dst; \ (d) = strdup_dst; \
} while (/* CONSTCOND */ 0) } while (/* CONSTCOND */ 0)
@ -433,9 +434,10 @@ char *ucstrstr(char *, const char *);
char *strdup_dst = NULL; \ char *strdup_dst = NULL; \
\ \
if (strdup_src != NULL) { \ if (strdup_src != NULL) { \
size_t strdup_len = (n) + 1; \ size_t strdup_len = (n); \
strdup_dst = alloc(strdup_len, (ap)); \ strdup_dst = alloc(strdup_len + 1, (ap)); \
strlcpy(strdup_dst, strdup_src, strdup_len); \ memcpy(strdup_dst, strdup_src, strdup_len); \
strdup_dst[strdup_len] = '\0'; \
} \ } \
(d) = strdup_dst; \ (d) = strdup_dst; \
} while (/* CONSTCOND */ 0) } while (/* CONSTCOND */ 0)