(bzero, bcopy): Obsolete BSDisms; remove. Remove some calls without

effect.  Replace calls by struct assignment where possible.  Replace
clear buffer, copy string to buffer by strncpy().  Use assignment to
clear when that's clearer.  Replace overlapping copy through bounce
buffer by memmove().  Replace rest by standard memset() and memcpy().
Also use sizeof() instead of literal array sizes for robustness, and
instead of symbolic array sizes for clarity.
This commit is contained in:
Markus Armbruster 2004-01-08 17:54:28 +00:00
parent 2910da23ea
commit 4ae9c417b3
79 changed files with 172 additions and 256 deletions

View file

@ -207,7 +207,7 @@ add(void)
natp->nat_xorg = 0;
natp->nat_dayno = 0;
natp->nat_minused = 0;
bzero((s_char *)natp->nat_b, sizeof(natp->nat_b));
memset(natp->nat_b, 0, sizeof(natp->nat_b));
(void)time(&natp->nat_last_login);
(void)time(&natp->nat_last_logout);
natp->nat_money = 0;

View file

@ -76,7 +76,7 @@ army(void)
while ((r = nxtitem(&ni, (s_char *)&land2)) &&
(land2.lnd_army != c)) ;
if (r) {
bcopy(land2.lnd_rpath, land.lnd_rpath, 10);
memcpy(land.lnd_rpath, land2.lnd_rpath, sizeof(land.lnd_rpath));
land.lnd_rflags = land2.lnd_rflags;
}
putland(land.lnd_uid, &land);

View file

@ -523,7 +523,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
int gun;
int shell;
bzero((s_char *)&head, sizeof(struct shiplook));
memset(&head, 0, sizeof(struct shiplook));
head.uid = -1;
onsea = (target->sct_type == SCT_WATER) ? 1 : 0;
for (qp = list->q_forw; qp != list && !player->aborted;
@ -536,7 +536,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
free(s2);
}
}
bzero((s_char *)&head, sizeof(struct shiplook));
memset(&head, 0, sizeof(struct shiplook));
head.uid = -1;
plp = (struct plist *)qp;
if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
@ -963,7 +963,7 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
eff = pp->pln_effic;
if (dam <= 0)
return 0;
bzero(dmess, 255);
memset(dmess, 0, sizeof(dmess));
eff -= dam;
if (eff < 0)
eff = 0;

View file

@ -94,7 +94,7 @@ budg(void)
s_char buf[1024];
s_char in[80];
bzero((s_char *)p_sect, sizeof(p_sect));
memset(p_sect, 0, sizeof(p_sect));
etu = etu_per_update;
np = getnatp(player->cnum);

View file

@ -416,7 +416,7 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp,
if (freeship == 0) {
ef_extend(EF_SHIP, 50);
}
bzero(&ship, sizeof(struct shpstr));
memset(&ship, 0, sizeof(struct shpstr));
ship.shp_x = sp->sct_x;
ship.shp_y = sp->sct_y;
ship.shp_destx[0] = sp->sct_x;
@ -572,7 +572,7 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp,
if (freeland == 0) {
ef_extend(EF_LAND, 50);
}
bzero(&land, sizeof(struct lndstr));
memset(&land, 0, sizeof(struct lndstr));
land.lnd_x = sp->sct_x;
land.lnd_y = sp->sct_y;
land.lnd_own = player->cnum;
@ -598,7 +598,7 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp,
land.lnd_fuel = lp->l_fuelc;
land.lnd_nxlight = 0;
land.lnd_rflags = 0;
bzero(land.lnd_rpath, 10);
memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
land.lnd_rad_max = 0;
land.lnd_nv = 0;
land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech);
@ -636,7 +636,7 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp,
vec[I_FOOD] -= max_amt;
bzero(lvec, sizeof(lvec));
memset(lvec, 0, sizeof(lvec));
getvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
lvec[I_FOOD] += max_amt;
putvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
@ -937,7 +937,7 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp,
if (freeplane == 0) {
ef_extend(EF_PLANE, 50);
}
bzero(&plane, sizeof(struct plnstr));
memset(&plane, 0, sizeof(struct plnstr));
plane.pln_x = sp->sct_x;
plane.pln_y = sp->sct_y;
plane.pln_own = sp->sct_own;

View file

@ -209,7 +209,7 @@ grab_sect(register struct sctstr *sp, natid to)
int vec[I_MAX + 1];
/* Wipe all the distribution info */
bzero((s_char *)vec, sizeof(vec));
memset(vec, 0, sizeof(vec));
putvec(VT_DIST, vec, (s_char *)sp, EF_SECTOR);
putvec(VT_DEL, vec, (s_char *)sp, EF_SECTOR);
sp->sct_dist_x = sp->sct_x;

View file

@ -149,7 +149,7 @@ coll(void)
makenotlost(EF_SECTOR, player->cnum, 0, sect.sct_x, sect.sct_y);
sect.sct_own = player->cnum;
bzero((s_char *)vec, sizeof(vec));
memset(vec, 0, sizeof(vec));
putvec(VT_DIST, vec, (s_char *)&sect, EF_SECTOR);
putvec(VT_DEL, vec, (s_char *)&sect, EF_SECTOR);
sect.sct_off = 1;

View file

@ -119,7 +119,7 @@ cons_choose(struct ltcomstr *ltcp)
s_char prompt[128];
s_char buf[1024];
bzero((s_char *)ltcp, sizeof(*ltcp));
memset(ltcp, 0, sizeof(*ltcp));
if (getstarg(player->argp[1], "loan or treaty? ", buf) == 0)
return RET_SYN;
ltcp->type = ef_byname(buf);

View file

@ -800,7 +800,7 @@ doship(s_char op, int arg, s_char *p, struct shpstr *ship)
putvar(V_PTIME, arg, (s_char *)ship, EF_SHIP);
break;
case 'R':
bcopy(p, ship->shp_rpath, 10);
memcpy(ship->shp_rpath, p, sizeof(ship->shp_rpath));
break;
case 'W':
ship->shp_rflags = arg;
@ -1041,7 +1041,7 @@ dounit(s_char op, int arg, s_char *p, struct lndstr *land)
land->lnd_retreat = arg;
break;
case 'R':
bcopy(p, land->lnd_rpath, 10);
memcpy(land->lnd_rpath, p, sizeof(land->lnd_rpath));
break;
case 'W':
land->lnd_rflags = arg;

View file

@ -53,7 +53,7 @@ int
explore(void)
{
register int amount;
struct sctstr orig, sect;
struct sctstr sect;
struct sctstr endsect;
struct sctstr start;
struct sctstr chksect;
@ -91,7 +91,6 @@ explore(void)
pr("Not yours\n");
return RET_FAIL;
}
bcopy((s_char *)&sect, (s_char *)&orig, sizeof(struct sctstr));
infected = getvar(V_PSTAGE, (s_char *)&sect, EF_SECTOR) == PLG_INFECT;
if ((amt_src = getvar(vtype, (s_char *)&sect, EF_SECTOR)) <= 0) {
pr("No %s in %s\n", ip->i_name,

View file

@ -76,7 +76,7 @@ flee(void)
while ((r = nxtitem(&ni, (s_char *)&ship2))
&& (ship2.shp_fleet != c)) ;
if (r) {
bcopy(ship2.shp_rpath, ship.shp_rpath, 10);
memcpy(ship.shp_rpath, ship2.shp_rpath, sizeof(ship.shp_rpath));
ship.shp_rflags = ship2.shp_rflags;
}
putship(ship.shp_uid, &ship);

View file

@ -90,7 +90,7 @@ head(void)
pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n");
pr(" %s", ctime(&now));
pr("\n");
bzero((s_char *)hist, sizeof(hist));
memset(hist, 0, sizeof(hist));
snxtitem_all(&nstr, EF_NEWS);
maxcnum = 0;
while (nxtitem(&nstr, (s_char *)&news)) {

View file

@ -69,7 +69,7 @@ look(void)
pr("Memory error. Tell the deity.\n");
return RET_FAIL;
}
bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8);
memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
while (nxtitem(&ni, (s_char *)&myship)) {
if (!player->owner)
continue;
@ -195,7 +195,7 @@ llook(void)
pr("Memory error. Tell the deity.\n");
return RET_FAIL;
}
bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8);
memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
while (nxtitem(&ni, (s_char *)&myland)) {
if (!player->owner)
continue;

View file

@ -694,7 +694,7 @@ defend(struct emp_qelem *al, struct emp_qelem *dl, enum targ_type target,
if (nfiring > *nd)
*nd = nfiring;
fp = (struct flist *)malloc(sizeof(struct flist));
bzero((s_char *)fp, sizeof(struct flist));
memset(fp, 0, sizeof(struct flist));
fp->defdam = dam;
fp->victim = vict;
switch (attacker) {
@ -837,7 +837,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
(*nfiring)++;
fp = (struct flist *)malloc(sizeof(struct flist));
bzero((s_char *)fp, sizeof(struct flist));
memset(fp, 0, sizeof(struct flist));
fp->type = targ_ship;
fp->uid = ship.shp_uid;
add_to_fired_queue(&fp->queue, list);
@ -869,7 +869,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
continue;
(*nfiring)++;
fp = (struct flist *)malloc(sizeof(struct flist));
bzero((s_char *)fp, sizeof(struct flist));
memset(fp, 0, sizeof(struct flist));
fp->type = targ_ship;
fp->uid = ship.shp_uid;
add_to_fired_queue(&fp->queue, list);
@ -922,7 +922,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
(*nfiring)++;
fp = (struct flist *)malloc(sizeof(struct flist));
bzero((s_char *)fp, sizeof(struct flist));
memset(fp, 0, sizeof(struct flist));
fp->type = targ_unit;
fp->uid = land.lnd_uid;
add_to_fired_queue(&fp->queue, list);
@ -973,7 +973,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
continue;
(*nfiring)++;
fp = (struct flist *)malloc(sizeof(struct flist));
bzero((s_char *)fp, sizeof(struct flist));
memset(fp, 0, sizeof(struct flist));
fp->x = firing.sct_x;
fp->y = firing.sct_y;
fp->type = targ_land;

View file

@ -394,14 +394,11 @@ want_to_abandon(struct sctstr *sp, int vtype, int amnt, struct lndstr *lp)
int
would_abandon(struct sctstr *sp, int vtype, int amnt, struct lndstr *lp)
{
struct sctstr sect;
int mil, civs, loyalcivs;
if ((vtype != V_CIVIL) && (vtype != V_MILIT))
return 0;
bcopy((s_char *)sp, (s_char *)&sect, sizeof(struct sctstr));
mil = getvar(V_MILIT, (s_char *)sp, EF_SECTOR);
civs = getvar(V_CIVIL, (s_char *)sp, EF_SECTOR);

View file

@ -259,7 +259,7 @@ nav_map(int x, int y, int show_designations)
logerror("malloc failed in navi\n");
return RET_FAIL;
}
bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8);
memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
/* zap any conditionals */
ns.ncond = 0;
xyrelrange(np, &ns.range, &range);

View file

@ -258,7 +258,7 @@ isok(int x, int y)
pr("Memory error. Tell the deity.\n");
return 0;
}
bzero((s_char *)map, (WORLD_X * WORLD_Y) / 2);
memset(map, 0, (WORLD_X * WORLD_Y) / 2);
ok(map, x, y);
free((s_char *)map);
if (nfree < 5)
@ -360,7 +360,7 @@ deity_build_land(int type, coord x, coord y, natid own, int tlev)
land.lnd_fuel = lp->l_fuelc;
land.lnd_nxlight = 0;
land.lnd_rflags = 0;
bzero((s_char *)land.lnd_rpath, 10);
memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
land.lnd_rad_max = lp->l_rad;
land.lnd_nv = 0;
@ -381,7 +381,7 @@ deity_build_land(int type, coord x, coord y, natid own, int tlev)
land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech);
land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech);
bzero((s_char *)lvec, sizeof(lvec));
memset(lvec, 0, sizeof(lvec));
getvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
lvec[I_FOOD] +=
vl_find(V_FOOD, lp->l_vtype, lp->l_vamt, (int)lp->l_nv);

View file

@ -67,8 +67,8 @@ news(void)
s_char num[128];
s_char *verb;
bzero((s_char *)page_has_news, sizeof(page_has_news));
bzero((s_char *)sectors_taken, sizeof(sectors_taken));
memset(page_has_news, 0, sizeof(page_has_news));
memset(sectors_taken, 0, sizeof(sectors_taken));
(void)head();
(void)time(&now);
natp = getnatp(player->cnum);

View file

@ -105,8 +105,9 @@ path(void)
xyrelrange(natp, &absrange, &relrange);
blankfill((s_char *)mapbuf, &ns.range, 3);
while (*pp && (i = chkdir(*pp, DIR_STOP, DIR_LAST)) >= 0) {
bcopy(routech[i][0], &map[deltay(cy, ns.range.ly)]
[deltax(cx, ns.range.lx) * 2], 3);
memcpy(&map[deltay(cy, ns.range.ly)][deltax(cx, ns.range.lx) * 2],
routech[i][0],
3);
cx += diroff[i][0];
cy += diroff[i][1];
++pp;

View file

@ -85,7 +85,7 @@ powe(void)
int no_numbers = 0;
s_char *p;
bzero((s_char *)targets, sizeof(targets));
memset(targets, 0, sizeof(targets));
natp = getnatp(player->cnum);
num = MAXNOC;
if (player->argp[1] && player->argp[1][0] == 'n') {
@ -247,7 +247,7 @@ gen_power(void)
float f;
player->btused += powe_cost;
bzero((s_char *)powbuf, sizeof(powbuf));
memset(powbuf, 0, sizeof(powbuf));
snxtsct_all(&ns);
while (nxtsct(&ns, &sect)) {
if (sect.sct_own == 0)

View file

@ -80,7 +80,7 @@ rea(void)
int first = 1;
int readit;
bzero(kind, 80);
memset(kind, 0, sizeof(kind));
(void)time(&now);
if (*player->argp[0] == 'w') {

View file

@ -76,7 +76,7 @@ repo(void)
return RET_SYN;
prdate();
natp = getnatp(player->cnum);
bzero((s_char *)&mystat, sizeof(struct stats));
memset(&mystat, 0, sizeof(struct stats));
mystat.stat = natp->nat_stat;
if (mystat.stat & STAT_NORM) {
mystat.res = natp->nat_level[NAT_RLEV];

View file

@ -144,11 +144,10 @@ retr(void)
continue;
}
if (zero)
bzero(ship.shp_rpath, RET_LEN);
memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
if (pq != (s_char *)0) {
bzero(ship.shp_rpath, RET_LEN);
bcopy(pq, ship.shp_rpath, strlen(pq));
strncpy(ship.shp_rpath, pq, sizeof(ship.shp_rpath));
putship(ship.shp_uid, &ship);
}
if (rflags >= 0) {
@ -273,11 +272,10 @@ lretr(void)
continue;
}
if (zero)
bzero(land.lnd_rpath, RET_LEN);
memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
if (pq != (s_char *)0) {
bzero(land.lnd_rpath, RET_LEN);
bcopy(pq, land.lnd_rpath, strlen(pq));
strncpy(land.lnd_rpath, pq, sizeof(land.lnd_rpath));
putland(land.lnd_uid, &land);
}
if (rflags >= 0) {

View file

@ -109,13 +109,12 @@ rout(void)
return RET_FAIL;
}
ncond = ns.ncond;
bcopy((s_char *)ns.cond, (s_char *)cond,
sizeof(struct nscstr) * ncond);
memcpy(cond, ns.cond, sizeof(struct nscstr) * ncond);
ns.ncond = 0;
natp = getnatp(player->cnum);
xyrelrange(natp, &ns.range, &relrange);
bzero((s_char *)mapbuf, ((WORLD_Y * MAPWIDTH(3)) * sizeof(s_char)));
memset(mapbuf, 0, ((WORLD_Y * MAPWIDTH(3))));
blankfill((s_char *)mapbuf, &ns.range, 3);
border(&relrange, " ", " ");
@ -125,14 +124,14 @@ rout(void)
p = &map[ns.dy][ns.dx * 2];
if ((dir = getvar(i_del, (s_char *)&sect, EF_SECTOR) & 0x7) &&
nstr_exec(cond, ncond, (s_char *)&sect, EF_SECTOR))
bcopy(routech[dir][0], p, 3);
memcpy(p, routech[dir][0], 3);
p[1] = dchr[sect.sct_type].d_mnem;
}
for (row = 0, y = ns.range.ly; row < ns.range.height; y++, row++) {
ry = yrel(natp, y);
bzero(buf, (MAPWIDTH(3) + 10) * sizeof(s_char));
memset(buf, 0, (MAPWIDTH(3) + 10));
sprintf(buf, "%4d ", ry);
bcopy(map[row], buf + 5, ns.range.width * 2 + 1);
memcpy(buf + 5, map[row], ns.range.width * 2 + 1);
sprintf(buf + 5 + ns.range.width * 2 + 1, " %-4d\n", ry);
pr("%s", buf);
if (y >= WORLD_Y)

View file

@ -147,7 +147,6 @@ cmd_sail_ship(struct nstr_item *nstr)
if (!check_ship_ok(&ship))
continue;
if (!player->aborted) {
bzero(ship.shp_path, sizeof(ship.shp_path));
strncpy(ship.shp_path, cp, sizeof(ship.shp_path) - 2);
ship.shp_mission = 0;
putship(ship.shp_uid, &ship);

View file

@ -100,7 +100,7 @@ scra(void)
|| islist(p))) {
s_char y_or_n[80], bbuf[80];
bzero(y_or_n, 80);
memset(y_or_n, 0, sizeof(y_or_n));
if (type == EF_SHIP) {
if (*p == '*')
sprintf(bbuf, "all ships");

View file

@ -102,7 +102,7 @@ sct(void)
}
np = getnatp(player->cnum);
ncond = ns.ncond;
bcopy((s_char *)ns.cond, (s_char *)cond, sizeof(*cond) * ncond);
memcpy(cond, ns.cond, sizeof(*cond) * ncond);
ns.ncond = 0;
xyrelrange(getnatp(player->cnum), &ns.range, &range);
border(&range, " ", "");

View file

@ -158,7 +158,7 @@ sona(void)
rad[ns.dy][ns.dx], 0);
}
bzero((s_char *)visbuf, (WORLD_Y * (WORLD_X + 1)));
memset(visbuf, 0, (WORLD_Y * (WORLD_X + 1)));
snxtitem_dist(&nit, EF_SHIP, ship.shp_x, ship.shp_y, range);
while (nxtitem(&nit, (caddr_t)&targ)) {

View file

@ -105,7 +105,7 @@ spy(void)
* 6 = neighbors, 2 = x,y
*/
table = (coord *)malloc((nsects + 1) * 6 * 2 * sizeof(coord));
bzero((s_char *)table, (nsects + 1) * 6 * 2 * sizeof(coord));
memset(table, 0, (nsects + 1) * 6 * 2 * sizeof(coord));
pr("SPY report\n");
prdate();
pr(" old sct rd rl def\n");

View file

@ -111,8 +111,7 @@ surv(void)
return RET_FAIL;
}
ncond = nstr.ncond;
bcopy((s_char *)nstr.cond, (s_char *)cond,
sizeof(struct nscstr) * ncond);
memcpy(cond, nstr.cond, sizeof(struct nscstr) * ncond);
nstr.ncond = 0;
np = getnatp(player->cnum);
xyrelrange(np, &nstr.range, &range);

View file

@ -139,7 +139,6 @@ torp(void)
pr("Ship #%d has insufficient mobility\n", sub.shp_uid);
continue;
}
bzero(buf, 80);
subno = sub.shp_uid;
sprintf(prompt, "Ship %d, target? ", sub.shp_uid);
if ((ptr = getstarg(player->argp[2], prompt, buf)) == 0)

View file

@ -51,7 +51,7 @@ wipe(void)
if (!snxtsct(&nstr, player->argp[1]))
return RET_SYN;
bzero((s_char *)vec, sizeof(vec));
memset(vec, 0, sizeof(vec));
while (nxtsct(&nstr, &sect)) {
if (!player->owner)
continue;