From 615681ce16896945339661a8e476c3ef01950b91 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 22 Mar 2009 18:50:43 +0100 Subject: [PATCH] Don't use 0 as null pointer constant, part 1 Use NULL instead of 0, for clarity. Except in pointer comparisons; leave that to the next two commits. --- doc/coding | 4 ++++ src/client/termlib.c | 4 ++-- src/lib/commands/assa.c | 6 +++--- src/lib/commands/atta.c | 8 ++++---- src/lib/commands/boar.c | 4 ++-- src/lib/commands/bomb.c | 2 +- src/lib/commands/buil.c | 4 ++-- src/lib/commands/coas.c | 8 ++++---- src/lib/commands/expl.c | 2 +- src/lib/commands/flash.c | 2 +- src/lib/commands/lboard.c | 4 ++-- src/lib/commands/load.c | 2 +- src/lib/commands/move.c | 2 +- src/lib/commands/para.c | 2 +- src/lib/commands/play.c | 2 +- src/lib/commands/reco.c | 4 ++-- src/lib/commands/skyw.c | 8 ++++---- src/lib/commands/stre.c | 2 +- src/lib/common/emp_config.c | 2 +- src/lib/common/nat.c | 2 +- src/lib/common/path.c | 2 +- src/lib/empthread/io.c | 4 ++-- src/lib/empthread/lwp.c | 2 +- src/lib/gen/ioqueue.c | 2 +- src/lib/lwp/lwp.c | 11 ++++++----- src/lib/lwp/queue.c | 5 +++-- src/lib/lwp/sel.c | 8 ++++---- src/lib/lwp/status.c | 4 ++-- src/lib/player/accept.c | 6 +++--- src/lib/player/empmod.c | 2 +- src/lib/player/login.c | 2 +- src/lib/subs/aircombat.c | 4 ++-- src/lib/subs/attsub.c | 9 +++++---- src/lib/subs/getstarg.c | 2 +- src/lib/subs/list.c | 2 +- src/lib/subs/lndsub.c | 2 +- src/lib/subs/mission.c | 4 ++-- src/lib/subs/mslsub.c | 8 ++++---- src/lib/subs/pr.c | 2 +- src/lib/subs/rej.c | 2 +- src/lib/subs/shpsub.c | 2 +- src/lib/subs/unitsub.c | 10 +++++----- src/lib/subs/whatitem.c | 4 ++-- src/lib/update/nxtitemp.c | 18 +++++++++--------- src/lib/update/plague.c | 2 +- src/lib/update/populace.c | 2 +- src/lib/update/revolt.c | 2 +- src/lib/update/sail.c | 2 +- src/lib/update/sect.c | 2 +- src/server/main.c | 4 ++-- src/server/update.c | 2 +- 51 files changed, 107 insertions(+), 100 deletions(-) diff --git a/doc/coding b/doc/coding index e3d8c6945..184e1b5cf 100644 --- a/doc/coding +++ b/doc/coding @@ -288,6 +288,10 @@ Do not use increment operators to set a variable to logical true! It obfuscates the purpose, and narrow variables could even overflow. Just assign 1. A lot of cleanup remains to be done there. +Null pointer constant + +Please use NULL for clarity, not just 0. + Type casts Casting pointers to and from `void *' clutters the code and serves no diff --git a/src/client/termlib.c b/src/client/termlib.c index 7a3efe1b7..ad664908c 100644 --- a/src/client/termlib.c +++ b/src/client/termlib.c @@ -42,8 +42,8 @@ #include #include "misc.h" -static char *smso = 0; -static char *rmso = 0; +static char *smso; +static char *rmso; void getsose(void) diff --git a/src/lib/commands/assa.c b/src/lib/commands/assa.c index 97b138c4a..f8531bde5 100644 --- a/src/lib/commands/assa.c +++ b/src/lib/commands/assa.c @@ -74,7 +74,7 @@ assa(void) return RET_SYN; if (!sarg_xy(p, &def->x, &def->y)) return RET_SYN; - if (att_abort(A_ASSAULT, 0, def)) + if (att_abort(A_ASSAULT, NULL, def)) return RET_FAIL; /* @@ -110,7 +110,7 @@ assa(void) if (att_abort(A_ASSAULT, off, def)) { pr("Assault aborted\n"); att_empty_attack(A_ASSAULT, 0, def); - return att_free_lists(&olist, 0); + return att_free_lists(&olist, NULL); } /* If we're assaulting our own sector, end here */ @@ -127,7 +127,7 @@ assa(void) if (att_abort(A_ASSAULT, off, def)) { pr("Assault aborted\n"); att_empty_attack(A_ASSAULT, 0, def); - return att_free_lists(&olist, 0); + return att_free_lists(&olist, NULL); } /* diff --git a/src/lib/commands/atta.c b/src/lib/commands/atta.c index 9cfca76e8..99e87e186 100644 --- a/src/lib/commands/atta.c +++ b/src/lib/commands/atta.c @@ -73,7 +73,7 @@ atta(void) return RET_SYN; if (!sarg_xy(p, &def->x, &def->y)) return RET_SYN; - if (att_abort(A_ATTACK, 0, def)) + if (att_abort(A_ATTACK, NULL, def)) return RET_FAIL; /* Show what we're attacking, and check treaties */ @@ -84,7 +84,7 @@ atta(void) /* Ask about offensive support */ att_ask_support(2, &fort_sup, &ship_sup, &land_sup, &plane_sup); - if (att_abort(A_ATTACK, 0, def)) { + if (att_abort(A_ATTACK, NULL, def)) { att_empty_attack(A_ATTACK, 0, def); return RET_OK; } @@ -110,14 +110,14 @@ atta(void) if (att_abort(A_ATTACK, off, def)) { pr("Attack aborted\n"); att_empty_attack(A_ATTACK, 0, def); - return att_free_lists(&olist, 0); + return att_free_lists(&olist, NULL); } ototal = att_get_offense(A_ATTACK, off, &olist, def); if (att_abort(A_ATTACK, off, def)) { pr("Attack aborted\n"); att_empty_attack(A_ATTACK, 0, def); - return att_free_lists(&olist, 0); + return att_free_lists(&olist, NULL); } /* diff --git a/src/lib/commands/boar.c b/src/lib/commands/boar.c index 48245d3d6..f357a728d 100644 --- a/src/lib/commands/boar.c +++ b/src/lib/commands/boar.c @@ -136,14 +136,14 @@ boar(void) if (att_abort(A_BOARD, off, def)) { pr("Board aborted\n"); att_empty_attack(A_BOARD, 0, def); - return att_free_lists(&olist, 0); + return att_free_lists(&olist, NULL); } ototal = att_get_offense(A_BOARD, off, &olist, def); if (att_abort(A_BOARD, off, def)) { pr("Board aborted\n"); att_empty_attack(A_BOARD, 0, def); - return att_free_lists(&olist, 0); + return att_free_lists(&olist, NULL); } /* diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index f959e06d7..19de35bbc 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -122,7 +122,7 @@ bomb(void) (void)pathtoxy(flightpath, &tx, &ty, fcost); pr("target sector is %s\n", xyas(tx, ty, player->cnum)); getsect(tx, ty, &target); - ip = 0; + ip = NULL; ap_to_target = strlen(flightpath); if (flightpath[ap_to_target - 1] == 'h') ap_to_target--; diff --git a/src/lib/commands/buil.c b/src/lib/commands/buil.c index a7a1cee23..4cd38f1d5 100644 --- a/src/lib/commands/buil.c +++ b/src/lib/commands/buil.c @@ -540,7 +540,7 @@ build_bridge(struct sctstr *sp, short *vec) if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) { pr("'%c' is not a valid direction...\n", *p); - direrr(0, 0, 0); + direrr(NULL, NULL, NULL); return 0; } newx = sp->sct_x + diroff[val][0]; @@ -816,7 +816,7 @@ build_tower(struct sctstr *sp, short *vec) if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) { pr("'%c' is not a valid direction...\n", *p); - direrr(0, 0, 0); + direrr(NULL, NULL, NULL); return 0; } newx = sp->sct_x + diroff[val][0]; diff --git a/src/lib/commands/coas.c b/src/lib/commands/coas.c index 174b5406f..0ba06e2e2 100644 --- a/src/lib/commands/coas.c +++ b/src/lib/commands/coas.c @@ -70,7 +70,7 @@ coas(void) if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; for (i = 0; i < TSIZE; i++) - list[i] = 0; + list[i] = NULL; cp = malloc(sizeof(*cp)); snxtitem_all(&ni, EF_SHIP); while (nxtitem(&ni, &cp->c_shp)) { @@ -139,18 +139,18 @@ static int showship(struct coast **cpp, int x, int y) { struct coast *cp; - struct coast *todelete = 0; + struct coast *todelete = NULL; struct coast **prev; int nship = 0; - prev = 0; + prev = NULL; cp = *cpp; prev = cpp; do { /* we delete it, we free it. */ if (todelete) { free(todelete); - todelete = 0; + todelete = NULL; } if (cp->c_shp.shp_x != x || cp->c_shp.shp_y != y) { prev = &(*prev)->c_next; diff --git a/src/lib/commands/expl.c b/src/lib/commands/expl.c index ce5d5beaf..c34a39c6b 100644 --- a/src/lib/commands/expl.c +++ b/src/lib/commands/expl.c @@ -119,7 +119,7 @@ explore(void) pr("Only exploring with %d.\n", amount); } - if (!want_to_abandon(§, vtype, amount, 0)) { + if (!want_to_abandon(§, vtype, amount, NULL)) { pr("Explore cancelled.\n"); return RET_FAIL; } diff --git a/src/lib/commands/flash.c b/src/lib/commands/flash.c index a5cd1edc8..10655161d 100644 --- a/src/lib/commands/flash.c +++ b/src/lib/commands/flash.c @@ -124,7 +124,7 @@ sendmessage(struct natstr *us, struct natstr *to, char *message, int verbose) time(&now); tm = localtime(&now); - for (other = player_next(0); other != 0; other = player_next(other)) { + for (other = player_next(NULL); other; other = player_next(other)) { if (other->state != PS_PLAYING) continue; if (to && other->cnum != to->nat_cnum) diff --git a/src/lib/commands/lboard.c b/src/lib/commands/lboard.c index d35e3ec03..6602e43ce 100644 --- a/src/lib/commands/lboard.c +++ b/src/lib/commands/lboard.c @@ -107,14 +107,14 @@ lboa(void) if (att_abort(A_LBOARD, off, def)) { pr("Land unit boarding aborted\n"); att_empty_attack(A_LBOARD, 0, def); - return att_free_lists(&olist, 0); + return att_free_lists(&olist, NULL); } ototal = att_get_offense(A_LBOARD, off, &olist, def); if (att_abort(A_LBOARD, off, def)) { pr("Land unit boarding aborted\n"); att_empty_attack(A_LBOARD, 0, def); - return att_free_lists(&olist, 0); + return att_free_lists(&olist, NULL); } /* diff --git a/src/lib/commands/load.c b/src/lib/commands/load.c index 5637c40b5..e96d14847 100644 --- a/src/lib/commands/load.c +++ b/src/lib/commands/load.c @@ -706,7 +706,7 @@ load_comm_ship(struct sctstr *sectp, struct shpstr *sp, load_unload, atoi(p)); if (!load_comm_ok(sectp, sp->shp_own, item, move_amt)) return RET_OK; - if (!want_to_abandon(sectp, item, move_amt, 0)) + if (!want_to_abandon(sectp, item, move_amt, NULL)) return RET_FAIL; if (!still_ok_ship(sectp, sp)) return RET_SYN; diff --git a/src/lib/commands/move.c b/src/lib/commands/move.c index 7c915b8ff..005a10cf2 100644 --- a/src/lib/commands/move.c +++ b/src/lib/commands/move.c @@ -140,7 +140,7 @@ move(void) } } - if (!istest && !want_to_abandon(§, vtype, amount, 0)) { + if (!istest && !want_to_abandon(§, vtype, amount, NULL)) { pr("Move cancelled.\n"); return RET_FAIL; } diff --git a/src/lib/commands/para.c b/src/lib/commands/para.c index ef41218ee..fec94553e 100644 --- a/src/lib/commands/para.c +++ b/src/lib/commands/para.c @@ -128,7 +128,7 @@ paradrop(struct emp_qelem *list, coord x, coord y) att_combat_init(def, EF_SECTOR); def->x = x; def->y = y; - if (att_abort(A_PARA, 0, def)) + if (att_abort(A_PARA, NULL, def)) return RET_FAIL; /* Show what we're air-assaulting, and check treaties */ diff --git a/src/lib/commands/play.c b/src/lib/commands/play.c index c548b653c..84f68f999 100644 --- a/src/lib/commands/play.c +++ b/src/lib/commands/play.c @@ -47,7 +47,7 @@ play(void) int saw = 0; play_header(); - for (joe = player_prev(0); joe; joe = player_prev(joe)) { + for (joe = player_prev(NULL); joe; joe = player_prev(joe)) { saw += play_list(joe); } if (player->god || opt_BLITZ) diff --git a/src/lib/commands/reco.c b/src/lib/commands/reco.c index 920f2abde..b0fb44583 100644 --- a/src/lib/commands/reco.c +++ b/src/lib/commands/reco.c @@ -97,12 +97,12 @@ reco(void) /* * now arm and equip the bombers, transports, whatever. */ - pln_arm(&bomb_list, ap_to_target, 'r', 0, P_S | P_I); + pln_arm(&bomb_list, ap_to_target, 'r', NULL, P_S | P_I); if (QEMPTY(&bomb_list)) { pr("No planes could be equipped for the mission.\n"); return RET_FAIL; } - pln_arm(&esc_list, ap_to_target, 'r', 0, P_F | P_ESC); + pln_arm(&esc_list, ap_to_target, 'r', NULL, P_F | P_ESC); ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, *player->argp[0] == 's' ? PM_R | PM_S : PM_R); if (QEMPTY(&bomb_list)) { diff --git a/src/lib/commands/skyw.c b/src/lib/commands/skyw.c index 4e659bcc0..95003e87a 100644 --- a/src/lib/commands/skyw.c +++ b/src/lib/commands/skyw.c @@ -68,7 +68,7 @@ skyw(void) if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; for (i = 0; i < TSIZE; i++) - list[i] = 0; + list[i] = NULL; skyp = malloc(sizeof(*skyp)); snxtitem_all(&ni, EF_PLANE); while (nxtitem(&ni, &skyp->s_sat)) { @@ -131,20 +131,20 @@ static int showsat(struct sky **skypp, int x, int y) { struct sky *skyp; - struct sky *todelete = 0; + struct sky *todelete = NULL; struct sky **prev; struct plchrstr *pcp; char *name; int nsat = 0; - prev = 0; + prev = NULL; skyp = *skypp; prev = skypp; do { /* we delete it, we free it. */ if (todelete) { free(todelete); - todelete = 0; + todelete = NULL; } if (skyp->s_sat.pln_x != x || skyp->s_sat.pln_y != y) { prev = &(*prev)->s_next; diff --git a/src/lib/commands/stre.c b/src/lib/commands/stre.c index 20a96083f..f65525221 100644 --- a/src/lib/commands/stre.c +++ b/src/lib/commands/stre.c @@ -82,7 +82,7 @@ stre(void) pr("%7s", ""); if (def->sct_type != SCT_MOUNT) - r_total = att_reacting_units(def, 0, 0, &dummy, 9999999); + r_total = att_reacting_units(def, NULL, 0, &dummy, 9999999); else r_total = 0.0; def->own = 0; diff --git a/src/lib/common/emp_config.c b/src/lib/common/emp_config.c index 6431797e5..93d65cde5 100644 --- a/src/lib/common/emp_config.c +++ b/src/lib/common/emp_config.c @@ -154,7 +154,7 @@ keylookup(char *command, struct keymatch *tbl) struct keymatch *kp; if (command == 0 || *command == 0) - return 0; + return NULL; for (kp = tbl; kp->km_key != 0; kp++) { if (strcmp(kp->km_key, command) == 0) return kp; diff --git a/src/lib/common/nat.c b/src/lib/common/nat.c index ab0613f1c..a4fec30fb 100644 --- a/src/lib/common/nat.c +++ b/src/lib/common/nat.c @@ -50,7 +50,7 @@ cname(natid n) struct natstr *np; if ((np = getnatp(n)) == 0) - return 0; + return NULL; return np->nat_cnam; } diff --git a/src/lib/common/path.c b/src/lib/common/path.c index 8dd74b945..40abdfbb1 100644 --- a/src/lib/common/path.c +++ b/src/lib/common/path.c @@ -185,7 +185,7 @@ bp_neighbors(struct as_coord c, struct as_coord *cp, void *pp) int n = 0, q; struct sctstr *sp, *from, **ssp; /* Six pointers, just in case our cache isn't there */ - struct sctstr *tsp[] = { 0, 0, 0, 0, 0, 0 }; + struct sctstr *tsp[] = { NULL, NULL, NULL, NULL, NULL, NULL }; int sx, sy, offset; x = c.x; diff --git a/src/lib/empthread/io.c b/src/lib/empthread/io.c index 5bbce8d97..3a48eae4b 100644 --- a/src/lib/empthread/io.c +++ b/src/lib/empthread/io.c @@ -82,8 +82,8 @@ io_open(int fd, int flags, int bufsize, struct timeval timeout) if (!iop) return NULL; iop->fd = fd; - iop->input = 0; - iop->output = 0; + iop->input = NULL; + iop->output = NULL; iop->flags = 0; iop->input_timeout = timeout; iop->bufsize = bufsize; diff --git a/src/lib/empthread/lwp.c b/src/lib/empthread/lwp.c index 03bf4a64d..71f3fc365 100644 --- a/src/lib/empthread/lwp.c +++ b/src/lib/empthread/lwp.c @@ -65,7 +65,7 @@ empth_create(void (*entry)(void *), int size, int flags, { if (!flags) flags = empth_flags; - return lwpCreate(1, entry, size, flags, name, 0, 0, ud); + return lwpCreate(1, entry, size, flags, name, 0, NULL, ud); } empth_t * diff --git a/src/lib/gen/ioqueue.c b/src/lib/gen/ioqueue.c index 96e2da13f..655a364dc 100644 --- a/src/lib/gen/ioqueue.c +++ b/src/lib/gen/ioqueue.c @@ -62,7 +62,7 @@ ioq_create(int size) ioq->list.nbytes = 0; ioq->list.offset = 0; ioq->list.size = 0; - ioq->list.data = 0; + ioq->list.data = NULL; ioq->bufsize = size; ioq->cc = 0; return ioq; diff --git a/src/lib/lwp/lwp.c b/src/lib/lwp/lwp.c index 748b6c6ad..6a47ac612 100644 --- a/src/lib/lwp/lwp.c +++ b/src/lib/lwp/lwp.c @@ -98,7 +98,7 @@ lwpReschedule(void) } else { lwpDestroy(nextp); } - nextp = 0; + nextp = NULL; } if (nextp) break; @@ -315,18 +315,19 @@ lwpInitSystem(int pri, void **ctxptr, int flags, sigset_t *waitset) pri = LWP_MAX_PRIO - 1; if (LwpMaxpri < pri) LwpMaxpri = pri; - LwpCurrent->next = 0; + LwpCurrent->next = NULL; LwpCurrent->sbtm = stack; /* dummy stack for "main" */ LwpCurrent->pri = pri; LwpCurrent->dead = 0; LwpCurrent->flags = flags & ~LWP_STACKCHECK; LwpCurrent->name = "Main"; for (i = LWP_MAX_PRIO, q = LwpSchedQ; i--; q++) - q->head = q->tail = 0; - LwpDeadQ.head = LwpDeadQ.tail = 0; + q->head = q->tail = NULL; + LwpDeadQ.head = LwpDeadQ.tail = NULL; lwpInitSigWait(waitset); /* must be lower in priority than us for this to work right */ - sel = lwpCreate(0, lwpSelect, 16384, flags, "EventHandler", 0, 0, 0); + sel = lwpCreate(0, lwpSelect, 16384, flags, "EventHandler", 0, + NULL, NULL); lwpInitSelect(sel); return LwpCurrent; } diff --git a/src/lib/lwp/queue.c b/src/lib/lwp/queue.c index f9f86173d..10df182ac 100644 --- a/src/lib/lwp/queue.c +++ b/src/lib/lwp/queue.c @@ -34,6 +34,7 @@ #include +#include #include "lwp.h" #include "lwpint.h" @@ -43,7 +44,7 @@ lwpGetFirst(struct lwpQueue *q) struct lwpProc *head; if ((head = q->head) && !(q->head = head->next)) - q->tail = 0; + q->tail = NULL; return head; } @@ -55,5 +56,5 @@ lwpAddTail(struct lwpQueue *q, struct lwpProc *p) else q->tail->next = p; q->tail = p; - p->next = 0; + p->next = NULL; } diff --git a/src/lib/lwp/sel.c b/src/lib/lwp/sel.c index 5c89df5d4..0f7268147 100644 --- a/src/lib/lwp/sel.c +++ b/src/lib/lwp/sel.c @@ -73,8 +73,8 @@ lwpInitSelect(struct lwpProc *proc) FD_ZERO(&LwpReadfds); FD_ZERO(&LwpWritefds); LwpFdwait = calloc(FD_SETSIZE, sizeof(struct lwpProc *)); - LwpDelayq.head = 0; - LwpDelayq.tail = 0; + LwpDelayq.head = NULL; + LwpDelayq.tail = NULL; LwpSelProc = proc; } @@ -141,7 +141,7 @@ lwpWakeupFd(struct lwpProc *proc) FD_CLR(proc->fd, &LwpReadfds); FD_CLR(proc->fd, &LwpWritefds); LwpNfds--; - LwpFdwait[proc->fd] = 0; + LwpFdwait[proc->fd] = NULL; proc->fd = -1; lwpReady(proc); } @@ -158,7 +158,7 @@ lwpWakeupSleep(void) if (LwpDelayq.head) { now = time(NULL); - save.tail = save.head = 0; + save.tail = save.head = NULL; while (NULL != (proc = lwpGetFirst(&LwpDelayq))) { if (now >= proc->runtime) { lwpStatus(proc, "sleep done"); diff --git a/src/lib/lwp/status.c b/src/lib/lwp/status.c index 72056bf7d..23d64a50a 100644 --- a/src/lib/lwp/status.c +++ b/src/lib/lwp/status.c @@ -51,8 +51,8 @@ lwpStatus(struct lwpProc *proc, char *format, ...) va_start(ap, format); if (proc->flags & LWP_PRINT) { if (startTime.tv_sec == 0) - gettimeofday(&startTime, 0); - gettimeofday(&tv, 0); + gettimeofday(&startTime, NULL); + gettimeofday(&tv, NULL); sec = tv.tv_sec - startTime.tv_sec; msec = (tv.tv_usec - startTime.tv_usec) / 1000; if (msec < 0) { diff --git a/src/lib/player/accept.c b/src/lib/player/accept.c index f2a798d67..474a51afe 100644 --- a/src/lib/player/accept.c +++ b/src/lib/player/accept.c @@ -107,7 +107,7 @@ player_delete(struct player *lp) if (lp->iop) { /* it's a real player */ io_close(lp->iop); - lp->iop = 0; + lp->iop = NULL; } free(lp); /* XXX may need to free bigmap here */ @@ -122,7 +122,7 @@ player_next(struct player *lp) else lp = (struct player *)lp->queue.q_forw; if (&lp->queue == &Players) - return 0; + return NULL; return lp; } @@ -134,7 +134,7 @@ player_prev(struct player *lp) else lp = (struct player *)lp->queue.q_back; if (&lp->queue == &Players) - return 0; + return NULL; return lp; } diff --git a/src/lib/player/empmod.c b/src/lib/player/empmod.c index 8013871d4..379ea61a5 100644 --- a/src/lib/player/empmod.c +++ b/src/lib/player/empmod.c @@ -279,5 +279,5 @@ struct cmndstr player_coms[] = { {"work ", 1, work, C_MOD, NORM + MONEY + CAP}, {"xdump [\"meta\"] []", 0, xdump, 0, VIS}, {"zdone ", 0, zdon, C_MOD, NORM}, - {0, 0, 0, 0, 0} + {NULL, 0, NULL, 0, 0} }; diff --git a/src/lib/player/login.c b/src/lib/player/login.c index 28b5311c0..58cc96ce3 100644 --- a/src/lib/player/login.c +++ b/src/lib/player/login.c @@ -69,7 +69,7 @@ static struct cmndstr login_coms[] = { {"quit", 0, quit_cmd, 0, 0}, {"sanc", 0, sanc_cmd, 0, 0}, {"user name", 0, user_cmd, 0, 0}, - {0, 0, 0, 0, 0} + {NULL, 0, NULL, 0, 0} }; /*ARGSUSED*/ diff --git a/src/lib/subs/aircombat.c b/src/lib/subs/aircombat.c index 9a91173af..46161828a 100644 --- a/src/lib/subs/aircombat.c +++ b/src/lib/subs/aircombat.c @@ -295,7 +295,7 @@ sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list, && pp->pln_radius < mapdist(x, y, pp->pln_opx, pp->pln_opy)) continue; if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED) - || mission_pln_equip(dplp, 0, P_F, 0) < 0) { + || mission_pln_equip(dplp, NULL, P_F, 0) < 0) { emp_remque(dqp); free(dqp); continue; @@ -369,7 +369,7 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, && pp->pln_radius < mapdist(x, y, pp->pln_opx, pp->pln_opy)) continue; if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED) - || mission_pln_equip(plp, 0, P_F, 0) < 0) { + || mission_pln_equip(plp, NULL, P_F, 0) < 0) { emp_remque(qp); free(qp); continue; diff --git a/src/lib/subs/attsub.c b/src/lib/subs/attsub.c index 2abacbdee..95349c517 100644 --- a/src/lib/subs/attsub.c +++ b/src/lib/subs/attsub.c @@ -912,7 +912,7 @@ ask_off(int combat_mode, struct combat *off, struct combat *def) sprintf(prompt, "Number of mil from %s (max %d) : ", prcom(0, off), mob_support); } - if ((attacking_mil = onearg(0, prompt)) < 0) + if ((attacking_mil = onearg(NULL, prompt)) < 0) abort_attack(); if (att_abort(combat_mode, off, def)) return 0; @@ -1271,7 +1271,8 @@ get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist, for (qp = olist->q_forw; qp != olist; qp = next) { next = qp->q_forw; llp = (struct ulist *)qp; - if (check && !get_land(combat_mode, 0, llp->unit.land.lnd_uid, llp, 0)) + if (check && + !get_land(combat_mode, NULL, llp->unit.land.lnd_uid, llp, 0)) continue; if (combat_mode == A_ATTACK) { w = -1; @@ -1448,7 +1449,7 @@ put_land(struct emp_qelem *list) emp_remque((struct emp_qelem *)llp); free(llp); } else - get_land(A_ATTACK, 0, llp->unit.land.lnd_uid, llp, 0); + get_land(A_ATTACK, NULL, llp->unit.land.lnd_uid, llp, 0); } } @@ -2181,7 +2182,7 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off, { int n; int occuppied = 0; - struct ulist *llp, *delete_me = 0; + struct ulist *llp, *delete_me = NULL; char buf[1024]; struct sctstr sect; struct shpstr ship; diff --git a/src/lib/subs/getstarg.c b/src/lib/subs/getstarg.c index 1e7a4a2e2..20a0df843 100644 --- a/src/lib/subs/getstarg.c +++ b/src/lib/subs/getstarg.c @@ -48,7 +48,7 @@ getstarg(char *input, char *prompt, char *buf) *buf = '\0'; if (input == 0 || *input == 0) { if (getstring(prompt, buf) == 0) - return 0; + return NULL; } else { strcpy(buf, input); } diff --git a/src/lib/subs/list.c b/src/lib/subs/list.c index 81e6b28f1..897cc09b5 100644 --- a/src/lib/subs/list.c +++ b/src/lib/subs/list.c @@ -254,7 +254,7 @@ adj_units(coord x, coord y, natid own) for (i = DIR_FIRST; i <= DIR_LAST; i++) { getsect(x + diroff[i][0], y + diroff[i][1], §); - if (has_units(sect.sct_x, sect.sct_y, own, 0)) + if (has_units(sect.sct_x, sect.sct_y, own, NULL)) return 1; } return 0; diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index 985a4db40..bfda69e53 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -989,7 +989,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor, pr("%s was shot and killed.\n", prland(&llp->unit.land)); llp->unit.land.lnd_effic = 0; putland(llp->unit.land.lnd_uid, &llp->unit.land); - lnd_delete(llp, 0); + lnd_delete(llp, NULL); } } } diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index 586300a0a..2c6cba992 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -610,12 +610,12 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list, /* Split off the escorts at this base into e */ divide(&escorts, &e, air->x, air->y); - mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', 0, 0); + mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', NULL, 0); if (QEMPTY(&b)) continue; - mission_pln_arm(&e, air->x, air->y, 2 * md, 'p', 0, P_F | P_ESC); + mission_pln_arm(&e, air->x, air->y, 2 * md, 'p', NULL, P_F | P_ESC); pp = BestAirPath(buf, air->x, air->y, x, y); if (CANT_HAPPEN(!pp)) diff --git a/src/lib/subs/mslsub.c b/src/lib/subs/mslsub.c index f5decdd09..657ed03ab 100644 --- a/src/lib/subs/mslsub.c +++ b/src/lib/subs/mslsub.c @@ -61,7 +61,7 @@ msl_equip(struct plnstr *pp, char mission) memset(&pl, 0, sizeof(struct plist)); pl.pcp = plchr + pp->pln_type; pl.plane = *pp; - return mission_pln_equip(&pl, 0, 0, mission); + return mission_pln_equip(&pl, NULL, 0, mission); } int @@ -271,7 +271,7 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget, if (pp->pln_own != sect.sct_own) continue; pcp = ip->pcp; - if (mission_pln_equip(ip, 0, 0, 'i') < 0) { + if (mission_pln_equip(ip, NULL, 0, 'i') < 0) { emp_remque(qp); free(qp); continue; @@ -290,7 +290,7 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget, ip = (struct plist *)qp; pp = &ip->plane; pcp = ip->pcp; - if (mission_pln_equip(ip, 0, 0, 'i') < 0) { + if (mission_pln_equip(ip, NULL, 0, 'i') < 0) { emp_remque(qp); free(qp); continue; @@ -401,7 +401,7 @@ msl_launch_mindam(struct emp_qelem *list, coord x, coord y, int hardtarget, next = qp->q_back; plp = (struct plist *)qp; - if (mission_pln_equip(plp, 0, 0, 'p') >= 0) { + if (mission_pln_equip(plp, NULL, 0, 'p') >= 0) { if (msl_hit(&plp->plane, hardtarget, type, news_item, snews_item, whatp, x, y, victim)) { diff --git a/src/lib/subs/pr.c b/src/lib/subs/pr.c index 3ba199ee9..79fbd1d7b 100644 --- a/src/lib/subs/pr.c +++ b/src/lib/subs/pr.c @@ -201,7 +201,7 @@ pr_wall(char *format, ...) va_start(ap, format); (void)vsprintf(buf + n, format, ap); va_end(ap); - for (p = player_next(0); p; p = player_next(p)) { + for (p = player_next(NULL); p; p = player_next(p)) { if (p->state != PS_PLAYING) continue; pr_player(p, C_FLASH, buf); diff --git a/src/lib/subs/rej.c b/src/lib/subs/rej.c index 1adb7ab68..799630da4 100644 --- a/src/lib/subs/rej.c +++ b/src/lib/subs/rej.c @@ -52,7 +52,7 @@ setrel(natid us, natid them, int rel) char *whichway; int n_up = 0; int n_down = 0; - char *addendum = 0; + char *addendum = NULL; int theirrel; if (rel < AT_WAR) diff --git a/src/lib/subs/shpsub.c b/src/lib/subs/shpsub.c index 8f372477c..70003f9c6 100644 --- a/src/lib/subs/shpsub.c +++ b/src/lib/subs/shpsub.c @@ -423,7 +423,7 @@ most_valuable_ship(struct emp_qelem *list) struct emp_qelem *qp; struct emp_qelem *next; struct ulist *mlp; - struct ulist *mvs = 0; + struct ulist *mvs = NULL; for (qp = list->q_back; qp != list; qp = next) { next = qp->q_back; diff --git a/src/lib/subs/unitsub.c b/src/lib/subs/unitsub.c index e65c8e093..c836c5fb2 100644 --- a/src/lib/subs/unitsub.c +++ b/src/lib/subs/unitsub.c @@ -147,14 +147,14 @@ unit_path(int together, struct empobj *unit, char *buf) return NULL; if (!sarg_xy(buf, &destx, &desty)) - return 0; + return NULL; if (!together) { pr("Cannot go to a destination sector if not all starting in the same sector\n"); - return 0; + return NULL; } if (!getsect(destx, desty, &d_sect)) { pr("%d,%d is not a sector\n", destx, desty); - return 0; + return NULL; } if (unit->ef_type == EF_SHIP) { cp = BestShipPath(buf, unit->x, unit->y, @@ -162,7 +162,7 @@ unit_path(int together, struct empobj *unit, char *buf) if (!cp || unit->mobil <= 0) { pr("Can't get to '%s' right now.\n", xyas(d_sect.sct_x, d_sect.sct_y, player->cnum)); - return 0; + return NULL; } } else { getsect(unit->x, unit->y, §); @@ -173,7 +173,7 @@ unit_path(int together, struct empobj *unit, char *buf) mtype == MOB_RAIL ? "railway" : "path", xyas(unit->x, unit->y, player->cnum), xyas(d_sect.sct_x, d_sect.sct_y, player->cnum)); - return 0; + return NULL; } pr("Using path '%s'\n", cp); } diff --git a/src/lib/subs/whatitem.c b/src/lib/subs/whatitem.c index 2b7cfb49e..0d925189a 100644 --- a/src/lib/subs/whatitem.c +++ b/src/lib/subs/whatitem.c @@ -49,7 +49,7 @@ whatitem(char *input, char *prompt) p = getstarg(input, prompt, buf); if (p == 0 || *p == 0) - return 0; + return NULL; ip = item_by_name(p); if (!ip) pr("Unrecognized item \"%c\"\n", *p); @@ -69,5 +69,5 @@ item_by_name(char *str) if (*str == ip->i_mnem) return ip; } - return 0; + return NULL; } diff --git a/src/lib/update/nxtitemp.c b/src/lib/update/nxtitemp.c index 2853e5d5b..60ca0e997 100644 --- a/src/lib/update/nxtitemp.c +++ b/src/lib/update/nxtitemp.c @@ -47,16 +47,16 @@ nxtitemp(struct nstr_item *np) int selected; if (np->sel == NS_UNDEF) - return 0; + return NULL; do { if (np->sel == NS_LIST) { np->index++; if (np->index >= np->size) - return 0; + return NULL; np->cur = np->list[np->index]; } else if (np->sel == NS_CARGO) { if (np->next < 0) - return 0; + return NULL; np->cur = np->next; np->next = unit_cargo_next(np->type, np->next); } else { @@ -64,7 +64,7 @@ nxtitemp(struct nstr_item *np) } gp = ef_ptr(np->type, np->cur); if (!gp) - return 0; + return NULL; selected = 1; switch (np->sel) { @@ -74,7 +74,7 @@ nxtitemp(struct nstr_item *np) break; case NS_DIST: if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY))) - return 0; + return NULL; if (!xyinrange(gp->x, gp->y, &np->range)) { selected = 0; break; @@ -85,25 +85,25 @@ nxtitemp(struct nstr_item *np) break; case NS_AREA: if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY))) - return 0; + return NULL; if (!xyinrange(gp->x, gp->y, &np->range)) selected = 0; break; case NS_XY: if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY))) - return 0; + return NULL; if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy) selected = 0; break; case NS_GROUP: if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_GROUP))) - return 0; + return NULL; if (np->group != gp->group) selected = 0; break; default: CANT_REACH(); - return 0; + return NULL; } if (selected && np->ncond) { /* nstr_exec is expensive, so we do it last */ diff --git a/src/lib/update/plague.c b/src/lib/update/plague.c index cc3ecb1d9..9102a885e 100644 --- a/src/lib/update/plague.c +++ b/src/lib/update/plague.c @@ -99,7 +99,7 @@ do_plague(struct sctstr *sp, struct natstr *np, int etu) } } if (sp->sct_item[I_CIVIL] == 0 && sp->sct_item[I_MILIT] == 0 - && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) { + && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, NULL)) { makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); sp->sct_own = 0; sp->sct_oldown = 0; diff --git a/src/lib/update/populace.c b/src/lib/update/populace.c index 5a1d35937..a02fa2d04 100644 --- a/src/lib/update/populace.c +++ b/src/lib/update/populace.c @@ -52,7 +52,7 @@ populace(struct natstr *np, struct sctstr *sp, int etu) sp->sct_oldown = sp->sct_own; } if (!civ && !mil && !sp->sct_item[I_UW] - && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) { + && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, NULL)) { makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); sp->sct_own = 0; sp->sct_oldown = 0; diff --git a/src/lib/update/revolt.c b/src/lib/update/revolt.c index 267e5f097..10f866bf4 100644 --- a/src/lib/update/revolt.c +++ b/src/lib/update/revolt.c @@ -352,7 +352,7 @@ guerrilla(struct sctstr *sp) } domove: if (move && che > 0) { - struct sctstr *nicest_sp = 0; + struct sctstr *nicest_sp = NULL; if (convert) min_mil = 999; else diff --git a/src/lib/update/sail.c b/src/lib/update/sail.c index a1588759e..ba1376de3 100644 --- a/src/lib/update/sail.c +++ b/src/lib/update/sail.c @@ -299,7 +299,7 @@ void sail_ship(natid cn) { struct shpstr *sp; - struct fltheadstr *head = 0; + struct fltheadstr *head = NULL; struct fltheadstr *fltp; int n; diff --git a/src/lib/update/sect.c b/src/lib/update/sect.c index 7e569a029..5f72fc85c 100644 --- a/src/lib/update/sect.c +++ b/src/lib/update/sect.c @@ -297,7 +297,7 @@ produce_sect(int natnum, int etu, struct bp *bp, long p_sect[][2]) * they all starved or were plagued off. */ if (vec[I_CIVIL] == 0 && vec[I_MILIT] == 0 && - !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) { + !has_units(sp->sct_x, sp->sct_y, sp->sct_own, NULL)) { if (!player->simulation) { makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); sp->sct_own = 0; diff --git a/src/server/main.c b/src/server/main.c index b619fb208..e04884ce7 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -382,7 +382,7 @@ start_server(int flags) if (journal_startup() < 0) exit(1); - empth_create(player_accept, 50 * 1024, flags, "AcceptPlayers", 0); + empth_create(player_accept, 50 * 1024, flags, "AcceptPlayers", NULL); market_init(); update_init(); @@ -422,7 +422,7 @@ shutdwn(int sig) logerror("Shutdown commencing (cleaning up threads.)"); play_wrlock_wanted = 1; - for (p = player_next(0); p != 0; p = player_next(p)) { + for (p = player_next(NULL); p != 0; p = player_next(p)) { if (p->state != PS_PLAYING) continue; pr_flash(p, "Server shutting down...\n"); diff --git a/src/server/update.c b/src/server/update.c index 75573b8df..cb73724f1 100644 --- a/src/server/update.c +++ b/src/server/update.c @@ -194,7 +194,7 @@ update_run(void) struct player *p; play_wrlock_wanted = 1; - for (p = player_next(0); p != 0; p = player_next(p)) { + for (p = player_next(NULL); p != 0; p = player_next(p)) { if (p->state != PS_PLAYING) continue; if (p->command) { -- 2.43.0