more use of memcpy(3) when we know destination and source sizes

This commit is contained in:
tg 2009-08-01 20:32:45 +00:00
parent 66b4399881
commit ed0299042c
4 changed files with 20 additions and 19 deletions

4
edit.c
View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.172 2009/07/05 13:56:47 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.173 2009/08/01 20:32:43 tg Exp $");
/* tty driver characters we are interested in */
typedef struct {
@ -3850,7 +3850,7 @@ vi_hook(int ch)
}
} else {
locpat[srchlen] = '\0';
(void)strlcpy(srchpat, locpat, sizeof(srchpat));
memcpy(srchpat, locpat, srchlen + 1);
}
state = VCMD;
} else if (ch == edchars.erase || ch == Ctrl('h')) {

6
jobs.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.58 2009/07/25 21:31:25 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.59 2009/08/01 20:32:44 tg Exp $");
#if HAVE_KILLPG
#define mksh_killpg killpg
@ -1297,7 +1297,7 @@ j_print(Job *j, int how, struct shf *shf)
coredumped = 0;
switch (p->state) {
case PRUNNING:
strlcpy(buf, "Running", sizeof(buf));
memcpy(buf, "Running", 8);
break;
case PSTOPPED:
strlcpy(buf, sigtraps[WSTOPSIG(p->status)].mess,
@ -1307,7 +1307,7 @@ j_print(Job *j, int how, struct shf *shf)
if (how == JP_SHORT)
buf[0] = '\0';
else if (WEXITSTATUS(p->status) == 0)
strlcpy(buf, "Done", sizeof(buf));
memcpy(buf, "Done", 5);
else
shf_snprintf(buf, sizeof(buf), "Done (%d)",
WEXITSTATUS(p->status));

15
sh.h
View File

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

14
var.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.75 2009/06/11 12:42:21 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.76 2009/08/01 20:32:45 tg Exp $");
/*
* Variables
@ -1239,7 +1239,7 @@ static struct tbl *
arraysearch(struct tbl *vp, uint32_t val)
{
struct tbl *prev, *curr, *new;
size_t namelen = strlen(vp->name) + 1;
size_t len;
vp->flag |= ARRAY|DEFINED;
vp->index = 0;
@ -1255,11 +1255,13 @@ arraysearch(struct tbl *vp, uint32_t val)
if (curr && curr->index == val) {
if (curr->flag&ISSET)
return (curr);
else
new = curr;
new = curr;
} else
new = alloc(sizeof(struct tbl) + namelen, vp->areap);
strlcpy(new->name, vp->name, namelen);
new = NULL;
len = strlen(vp->name) + 1;
if (!new)
new = alloc(offsetof(struct tbl, name[0]) + len, vp->areap);
memcpy(new->name, vp->name, len);
new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL);
new->type = vp->type;
new->areap = vp->areap;