more use of memcpy(3) when we know destination and source sizes
This commit is contained in:
parent
66b4399881
commit
ed0299042c
4
edit.c
4
edit.c
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#include "sh.h"
|
#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 */
|
/* tty driver characters we are interested in */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -3850,7 +3850,7 @@ vi_hook(int ch)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
locpat[srchlen] = '\0';
|
locpat[srchlen] = '\0';
|
||||||
(void)strlcpy(srchpat, locpat, sizeof(srchpat));
|
memcpy(srchpat, locpat, srchlen + 1);
|
||||||
}
|
}
|
||||||
state = VCMD;
|
state = VCMD;
|
||||||
} else if (ch == edchars.erase || ch == Ctrl('h')) {
|
} else if (ch == edchars.erase || ch == Ctrl('h')) {
|
||||||
|
|
6
jobs.c
6
jobs.c
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include "sh.h"
|
#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
|
#if HAVE_KILLPG
|
||||||
#define mksh_killpg killpg
|
#define mksh_killpg killpg
|
||||||
|
@ -1297,7 +1297,7 @@ j_print(Job *j, int how, struct shf *shf)
|
||||||
coredumped = 0;
|
coredumped = 0;
|
||||||
switch (p->state) {
|
switch (p->state) {
|
||||||
case PRUNNING:
|
case PRUNNING:
|
||||||
strlcpy(buf, "Running", sizeof(buf));
|
memcpy(buf, "Running", 8);
|
||||||
break;
|
break;
|
||||||
case PSTOPPED:
|
case PSTOPPED:
|
||||||
strlcpy(buf, sigtraps[WSTOPSIG(p->status)].mess,
|
strlcpy(buf, sigtraps[WSTOPSIG(p->status)].mess,
|
||||||
|
@ -1307,7 +1307,7 @@ j_print(Job *j, int how, struct shf *shf)
|
||||||
if (how == JP_SHORT)
|
if (how == JP_SHORT)
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
else if (WEXITSTATUS(p->status) == 0)
|
else if (WEXITSTATUS(p->status) == 0)
|
||||||
strlcpy(buf, "Done", sizeof(buf));
|
memcpy(buf, "Done", 5);
|
||||||
else
|
else
|
||||||
shf_snprintf(buf, sizeof(buf), "Done (%d)",
|
shf_snprintf(buf, sizeof(buf), "Done (%d)",
|
||||||
WEXITSTATUS(p->status));
|
WEXITSTATUS(p->status));
|
||||||
|
|
15
sh.h
15
sh.h
|
@ -134,7 +134,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#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
|
#endif
|
||||||
#define MKSH_VERSION "R39 2009/08/01"
|
#define MKSH_VERSION "R39 2009/08/01"
|
||||||
|
|
||||||
|
@ -422,10 +422,9 @@ 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); \
|
size_t strdup_len = strlen(strdup_src) + 1; \
|
||||||
strdup_dst = alloc(strdup_len + 1, (ap)); \
|
strdup_dst = alloc(strdup_len, (ap)); \
|
||||||
memcpy(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)
|
||||||
|
@ -434,10 +433,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); \
|
size_t strndup_len = (n); \
|
||||||
strdup_dst = alloc(strdup_len + 1, (ap)); \
|
strdup_dst = alloc(strndup_len + 1, (ap)); \
|
||||||
memcpy(strdup_dst, strdup_src, strdup_len); \
|
memcpy(strdup_dst, strdup_src, strndup_len); \
|
||||||
strdup_dst[strdup_len] = '\0'; \
|
strdup_dst[strndup_len] = '\0'; \
|
||||||
} \
|
} \
|
||||||
(d) = strdup_dst; \
|
(d) = strdup_dst; \
|
||||||
} while (/* CONSTCOND */ 0)
|
} while (/* CONSTCOND */ 0)
|
||||||
|
|
14
var.c
14
var.c
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include "sh.h"
|
#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
|
* Variables
|
||||||
|
@ -1239,7 +1239,7 @@ static struct tbl *
|
||||||
arraysearch(struct tbl *vp, uint32_t val)
|
arraysearch(struct tbl *vp, uint32_t val)
|
||||||
{
|
{
|
||||||
struct tbl *prev, *curr, *new;
|
struct tbl *prev, *curr, *new;
|
||||||
size_t namelen = strlen(vp->name) + 1;
|
size_t len;
|
||||||
|
|
||||||
vp->flag |= ARRAY|DEFINED;
|
vp->flag |= ARRAY|DEFINED;
|
||||||
vp->index = 0;
|
vp->index = 0;
|
||||||
|
@ -1255,11 +1255,13 @@ arraysearch(struct tbl *vp, uint32_t val)
|
||||||
if (curr && curr->index == val) {
|
if (curr && curr->index == val) {
|
||||||
if (curr->flag&ISSET)
|
if (curr->flag&ISSET)
|
||||||
return (curr);
|
return (curr);
|
||||||
else
|
new = curr;
|
||||||
new = curr;
|
|
||||||
} else
|
} else
|
||||||
new = alloc(sizeof(struct tbl) + namelen, vp->areap);
|
new = NULL;
|
||||||
strlcpy(new->name, vp->name, namelen);
|
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->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL);
|
||||||
new->type = vp->type;
|
new->type = vp->type;
|
||||||
new->areap = vp->areap;
|
new->areap = vp->areap;
|
||||||
|
|
Loading…
Reference in New Issue