From 13d2d20efa6d7eb1b1e49faadf57f9a65f359bfc Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Wed, 11 Aug 2010 20:35:26 +0000 Subject: [PATCH] Remove comparisons to NULL Rather than using "== NULL" or "!= NULL", use expression or !expression where possible. Patch automatically generated by coccinelle from badnull.cocci and badnull2.cocci SVN revision: 51023 --- legacy/embryo/src/bin/embryo_cc_sc1.c | 147 +++++++++++------------ legacy/embryo/src/bin/embryo_cc_sc2.c | 88 +++++++------- legacy/embryo/src/bin/embryo_cc_sc3.c | 88 +++++++------- legacy/embryo/src/bin/embryo_cc_sc5.c | 2 +- legacy/embryo/src/bin/embryo_cc_sc6.c | 54 ++++----- legacy/embryo/src/bin/embryo_cc_sc7.c | 32 ++--- legacy/embryo/src/bin/embryo_cc_sclist.c | 42 +++---- legacy/embryo/src/lib/embryo_amx.c | 2 +- legacy/embryo/src/lib/embryo_str.c | 6 +- 9 files changed, 229 insertions(+), 232 deletions(-) diff --git a/legacy/embryo/src/bin/embryo_cc_sc1.c b/legacy/embryo/src/bin/embryo_cc_sc1.c index 0249795eaa..2beeb38c2e 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc1.c +++ b/legacy/embryo/src/bin/embryo_cc_sc1.c @@ -128,7 +128,7 @@ main(int argc, char *argv[], char *env[] __UNUSED__) * so, I try to get the current path with getcwd(), and if that fails * I search for the PWD= setting in the environment. */ - if (NULL != getcwd(argv0, PATH_MAX)) + if (getcwd(argv0, PATH_MAX)) { i = strlen(argv0); snprintf(argv0 + i, sizeof(argv0) - i, "/%s", argv[0]); @@ -137,7 +137,7 @@ main(int argc, char *argv[], char *env[] __UNUSED__) { char *pwd = getenv("PWD"); - if (pwd != NULL) + if (pwd) snprintf(argv0, sizeof(argv0), "%s/%s", pwd, argv[0]); } /* if */ argv[0] = argv0; /* set location to new first parameter */ @@ -221,7 +221,7 @@ sc_openasm(int fd) void sc_closeasm(void *handle) { - if (handle != NULL) + if (handle) fclose((FILE *) handle); } @@ -307,7 +307,7 @@ sc_compile(int argc, char *argv[]) /* allocate memory for fixed tables */ inpfname = (char *)malloc(PATH_MAX); litq = (cell *) malloc(litmax * sizeof(cell)); - if (litq == NULL) + if (!litq) error(103); /* insufficient memory */ if (!phopt_init()) error(103); /* insufficient memory */ @@ -336,20 +336,20 @@ sc_compile(int argc, char *argv[]) lcl_needsemicolon = sc_needsemicolon; lcl_tabsize = sc_tabsize; inpf = inpf_org = (FILE *) sc_opensrc(inpfname); - if (inpf == NULL) + if (!inpf) error(100, inpfname); freading = TRUE; outf = (FILE *) sc_openasm(fd_out); /* first write to assembler * file (may be temporary) */ - if (outf == NULL) + if (!outf) error(101, outfname); /* immediately open the binary file, for other programs to check */ binf = (FILE *) sc_openbin(binfname); - if (binf == NULL) + if (!binf) error(101, binfname); setconstants(); /* set predefined constants and tagnames */ for (i = 0; i < skipinput; i++) /* skip lines in the input file */ - if (sc_readsrc(inpf, pline, sLINEMAX) != NULL) + if (sc_readsrc(inpf, pline, sLINEMAX)) fline++; /* keep line number up to date */ skipinput = fline; sc_status = statFIRST; @@ -422,7 +422,7 @@ sc_compile(int argc, char *argv[]) error(13); /* no entry point (no public functions) */ cleanup: - if (inpf != NULL) /* main source file is not closed, do it now */ + if (inpf) /* main source file is not closed, do it now */ sc_closesrc(inpf); /* write the binary file (the file is already open) */ if (errnum == 0 && jmpcode == 0) @@ -431,14 +431,14 @@ sc_compile(int argc, char *argv[]) sc_resetasm(outf); /* flush and loop back, for reading */ assemble(binf, outf); /* assembler file is now input */ } /* if */ - if (outf != NULL) + if (outf) sc_closeasm(outf); - if (binf != NULL) + if (binf) sc_closebin(binf, errnum != 0); - if (inpfname != NULL) + if (inpfname) free(inpfname); - if (litq != NULL) + if (litq) free(litq); phopt_cleanup(); stgbuffer_cleanup(); @@ -489,7 +489,7 @@ sc_addtag(char *name) constvalue *ptr; int last, tag; - if (name == NULL) + if (!name) { /* no tagname was given, check for one */ if (lex(&val, &name) != tLABEL) @@ -501,7 +501,7 @@ sc_addtag(char *name) last = 0; ptr = tagname_tab.next; - while (ptr != NULL) + while (ptr) { tag = (int)(ptr->value & TAGMASK); if (strcmp(name, ptr->name) == 0) @@ -679,15 +679,15 @@ setconfig(char *root) int len; /* add the default "include" directory */ - if (root != NULL) + if (root) { /* path + filename (hopefully) */ strncpy(path, root, sizeof(path) - 1); path[sizeof(path) - 1] = 0; } /* terminate just behind last \ or : */ - if ((ptr = strrchr(path, DIRSEP_CHAR)) != NULL - || (ptr = strchr(path, ':')) != NULL) + if ((ptr = strrchr(path, DIRSEP_CHAR)) + || (ptr = strchr(path, ':'))) { /* If there was no terminating "\" or ":", * the filename probably does not @@ -1042,7 +1042,7 @@ declglb(char *firstname, int firsttag, int fpublic, int fstatic, size = 1; /* single size (no array) */ numdim = 0; /* no dimensions */ ident = iVARIABLE; - if (firstname != NULL) + if (firstname) { assert(strlen(firstname) <= sNAMEMAX); strcpy(name, firstname); /* save symbol name */ @@ -1058,9 +1058,9 @@ declglb(char *firstname, int firsttag, int fpublic, int fstatic, strcpy(name, str); /* save symbol name */ } /* if */ sym = findglb(name); - if (sym == NULL) + if (!sym) sym = findconst(name); - if (sym != NULL && (sym->usage & uDEFINE) != 0) + if (sym && (sym->usage & uDEFINE) != 0) error(21, name); /* symbol already defined */ ispublic = fpublic; if (name[0] == PUBLIC_CHAR) @@ -1094,7 +1094,7 @@ declglb(char *firstname, int firsttag, int fpublic, int fstatic, * for public variables */ cidx = 0; /* only to avoid a compiler warning */ - if (sc_status == statWRITE && sym != NULL + if (sc_status == statWRITE && sym && (sym->usage & (uREAD | uWRITTEN | uPUBLIC)) == 0) { sc_status = statSKIP; @@ -1121,7 +1121,7 @@ declglb(char *firstname, int firsttag, int fpublic, int fstatic, dumplits(); /* dump the literal queue */ dumpzero((int)size - litidx); litidx = 0; - if (sym == NULL) + if (!sym) { /* define only if not yet defined */ sym = addvariable(name, sizeof(cell) * glb_declared, ident, sGLOBAL, @@ -1201,14 +1201,14 @@ declloc(int fstatic) * the "nesting level" of local variables to verify the * multi-definition of symbols. */ - if ((sym = findloc(name)) != NULL && sym->compound == nestlevel) + if ((sym = findloc(name)) && sym->compound == nestlevel) error(21, name); /* symbol already defined */ /* Although valid, a local variable whose name is equal to that * of a global variable or to that of a local variable at a lower * level might indicate a bug. */ - if (((sym = findloc(name)) != NULL && sym->compound != nestlevel) - || findglb(name) != NULL) + if (((sym = findloc(name)) && sym->compound != nestlevel) + || findglb(name)) error(219, name); /* variable shadows another symbol */ while (matchtoken('[')) { @@ -1710,7 +1710,7 @@ fetchfunc(char *name, int tag) * symbol instruction. */ } /* if */ - if ((sym = findglb(name)) != NULL) + if ((sym = findglb(name))) { /* already in symbol table? */ if (sym->ident != iFUNCTN) { @@ -1758,7 +1758,7 @@ define_args(void) * local symbols are function arguments. */ sym = loctab.next; - while (sym != NULL) + while (sym) { assert(sym->ident != iLABEL); assert(sym->vclass == sLOCAL); @@ -1767,7 +1767,7 @@ define_args(void) { symbol *sub = sym; - while (sub != NULL) + while (sub) { symbolrange(sub->dim.array.level, sub->dim.array.length); sub = finddepend(sub); @@ -1904,7 +1904,7 @@ operatoradjust(int opertok, symbol * sym, char *opername, int resulttag) /* change the operator name */ assert(opername[0] != '\0'); operator_symname(tmpname, opername, tags[0], tags[1], count, resulttag); - if ((oldsym = findglb(tmpname)) != NULL) + if ((oldsym = findglb(tmpname))) { int i; @@ -1918,7 +1918,7 @@ operatoradjust(int opertok, symbol * sym, char *opername, int resulttag) sym->usage |= oldsym->usage; /* copy flags from the previous * definition */ for (i = 0; i < oldsym->numrefers; i++) - if (oldsym->refer[i] != NULL) + if (oldsym->refer[i]) refer_symbol(sym, oldsym->refer[i]); delete_symbol(&glbtab, oldsym); } /* if */ @@ -2110,7 +2110,7 @@ funcstub(int native) sym = fetchfunc(symbolname, tag); /* get a pointer to the * function entry */ - if (sym == NULL) + if (!sym) return; if (native) { @@ -2199,7 +2199,7 @@ newfunc(char *firstname, int firsttag, int fpublic, int fstatic, int stock) glbdecl = 0; filenum = fcurrent; /* save file number at start of declaration */ - if (firstname != NULL) + if (firstname) { assert(strlen(firstname) <= sNAMEMAX); strcpy(symbolname, firstname); /* save symbol name */ @@ -2243,7 +2243,7 @@ newfunc(char *firstname, int firsttag, int fpublic, int fstatic, int stock) } /* if */ sym = fetchfunc(symbolname, tag); /* get a pointer to the * function entry */ - if (sym == NULL) + if (!sym) return TRUE; if (fpublic) sym->usage |= uPUBLIC; @@ -2517,7 +2517,7 @@ declargs(symbol * sym) sym->dim.arglist = (arginfo *) realloc(sym->dim.arglist, (argcnt + 2) * sizeof(arginfo)); - if (sym->dim.arglist == NULL) + if (!sym->dim.arglist) error(103); /* insufficient memory */ sym->dim.arglist[argcnt] = arg; sym->dim.arglist[argcnt + 1].ident = 0; /* keep the list @@ -2554,7 +2554,7 @@ declargs(symbol * sym) sym->dim.arglist = (arginfo *) realloc(sym->dim.arglist, (argcnt + 2) * sizeof(arginfo)); - if (sym->dim.arglist == NULL) + if (!sym->dim.arglist) error(103); /* insufficient memory */ sym->dim.arglist[argcnt + 1].ident = 0; /* keep the list * terminated */ @@ -2565,7 +2565,7 @@ declargs(symbol * sym) sym->dim.arglist[argcnt].numtags = numtags; sym->dim.arglist[argcnt].tags = (int *)malloc(numtags * sizeof tags[0]); - if (sym->dim.arglist[argcnt].tags == NULL) + if (!sym->dim.arglist[argcnt].tags) error(103); /* insufficient memory */ memcpy(sym->dim.arglist[argcnt].tags, tags, numtags * sizeof tags[0]); @@ -2697,7 +2697,7 @@ doarg(char *name, int ident, int offset, int tags[], int numtags, assert(size >= litidx); /* allocate memory to hold the initial values */ arg->defvalue.array.data = (cell *) malloc(litidx * sizeof(cell)); - if (arg->defvalue.array.data != NULL) + if (arg->defvalue.array.data) { int i; @@ -2744,8 +2744,7 @@ doarg(char *name, int ident, int offset, int tags[], int numtags, cell val; tokeninfo(&val, &name); - if ((arg->defvalue.size.symname = - strdup(name)) == NULL) + if (!(arg->defvalue.size.symname = strdup(name))) error(103); /* insufficient memory */ arg->defvalue.size.level = 0; if (size_tag_token == uSIZEOF) @@ -2776,17 +2775,17 @@ doarg(char *name, int ident, int offset, int tags[], int numtags, arg->usage = (char)(fconst ? uCONST : 0); arg->numtags = numtags; arg->tags = (int *)malloc(numtags * sizeof tags[0]); - if (arg->tags == NULL) + if (!arg->tags) error(103); /* insufficient memory */ memcpy(arg->tags, tags, numtags * sizeof tags[0]); argsym = findloc(name); - if (argsym != NULL) + if (argsym) { error(21, name); /* symbol already defined */ } else { - if ((argsym = findglb(name)) != NULL && argsym->ident != iFUNCTN) + if ((argsym = findglb(name)) && argsym->ident != iFUNCTN) error(219, name); /* variable shadows another symbol */ /* add details of type and address */ assert(numtags > 0); @@ -2810,7 +2809,7 @@ count_referrers(symbol * entry) count = 0; for (i = 0; i < entry->numrefers; i++) - if (entry->refer[i] != NULL) + if (entry->refer[i]) count++; return count; } @@ -2829,9 +2828,9 @@ reduce_referrers(symbol * root) do { restart = 0; - for (sym = root->next; sym != NULL; sym = sym->next) + for (sym = root->next; sym; sym = sym->next) { - if (sym->parent != NULL) + if (sym->parent) continue; /* hierarchical data type */ if (sym->ident == iFUNCTN && (sym->usage & uNATIVE) == 0 @@ -2842,9 +2841,9 @@ reduce_referrers(symbol * root) sym->usage &= ~(uREAD | uWRITTEN); /* erase usage bits if * there is no referrer */ /* find all symbols that are referred by this symbol */ - for (ref = root->next; ref != NULL; ref = ref->next) + for (ref = root->next; ref; ref = ref->next) { - if (ref->parent != NULL) + if (ref->parent) continue; /* hierarchical data type */ assert(ref->refer != NULL); for (i = 0; i < ref->numrefers && ref->refer[i] != sym; @@ -2860,7 +2859,7 @@ reduce_referrers(symbol * root) } else if ((sym->ident == iVARIABLE || sym->ident == iARRAY) && (sym->usage & uPUBLIC) == 0 - && sym->parent == NULL && count_referrers(sym) == 0) + && !sym->parent && count_referrers(sym) == 0) { sym->usage &= ~(uREAD | uWRITTEN); /* erase usage bits if * there is no referrer */ @@ -2892,7 +2891,7 @@ testsymbols(symbol * root, int level, int testlabs, int testconst) symbol *sym = root->next; - while (sym != NULL && sym->compound >= level) + while (sym && sym->compound >= level) { switch (sym->ident) { @@ -2923,7 +2922,7 @@ testsymbols(symbol * root, int level, int testlabs, int testconst) break; default: /* a variable */ - if (sym->parent != NULL) + if (sym->parent) break; /* hierarchical data type */ if ((sym->usage & (uWRITTEN | uREAD | uSTOCK | uPUBLIC)) == 0) error(203, sym->name); /* symbol isn't used (and not stock @@ -2956,7 +2955,7 @@ calc_array_datasize(symbol * sym, cell * offset) { cell sublength = calc_array_datasize(finddepend(sym), offset); - if (offset != NULL) + if (offset) *offset = length * (*offset + sizeof(cell)); if (sublength > 0) length *= length * sublength; @@ -2965,7 +2964,7 @@ calc_array_datasize(symbol * sym, cell * offset) } else { - if (offset != NULL) + if (offset) *offset = 0; } /* if */ return length; @@ -2978,7 +2977,7 @@ destructsymbols(symbol * root, int level) int savepri = FALSE; symbol *sym = root->next; - while (sym != NULL && sym->compound >= level) + while (sym && sym->compound >= level) { if (sym->ident == iVARIABLE || sym->ident == iARRAY) { @@ -2988,7 +2987,7 @@ destructsymbols(symbol * root, int level) /* check that the '~' operator is defined for this tag */ operator_symname(symbolname, "~", sym->tag, 0, 1, 0); - if ((opsym = findglb(symbolname)) != NULL) + if ((opsym = findglb(symbolname))) { /* save PRI, in case of a return statment */ if (!savepri) @@ -3022,7 +3021,7 @@ destructsymbols(symbol * root, int level) if (sc_status != statSKIP) markusage(opsym, uREAD); /* do not mark as "used" when this * call itself is skipped */ - if (opsym->x.lib != NULL) + if (opsym->x.lib) opsym->x.lib->value += 1; /* increment "usage count" * of the library */ } /* if */ @@ -3040,7 +3039,7 @@ insert_constval(constvalue * prev, constvalue * next, char *name, { constvalue *cur; - if ((cur = (constvalue *) malloc(sizeof(constvalue))) == NULL) + if (!(cur = (constvalue *)malloc(sizeof(constvalue)))) error(103); /* insufficient memory (fatal error) */ memset(cur, 0, sizeof(constvalue)); strcpy(cur->name, name); @@ -3057,7 +3056,7 @@ append_constval(constvalue * table, char *name, cell val, short index) constvalue *cur, *prev; /* find the end of the constant table */ - for (prev = table, cur = table->next; cur != NULL; + for (prev = table, cur = table->next; cur; prev = cur, cur = cur->next) /* nothing */ ; return insert_constval(prev, NULL, name, val, index); @@ -3068,7 +3067,7 @@ find_constval(constvalue * table, char *name, short index) { constvalue *ptr = table->next; - while (ptr != NULL) + while (ptr) { if (strcmp(name, ptr->name) == 0 && ptr->index == index) return ptr; @@ -3082,7 +3081,7 @@ find_constval_byval(constvalue * table, cell val) { constvalue *ptr = table->next; - while (ptr != NULL) + while (ptr) { if (ptr->value == val) return ptr; @@ -3118,7 +3117,7 @@ delete_consttable(constvalue * table) { constvalue *cur = table->next, *next; - while (cur != NULL) + while (cur) { next = cur->next; free(cur); @@ -3187,7 +3186,7 @@ statement(int *lastindent, int allow_decl) if (tok != '{') setline(fline, fcurrent); /* lex() has set stmtindent */ - if (lastindent != NULL && tok != tLABEL) + if (lastindent && tok != tLABEL) { #if 0 if (*lastindent >= 0 && *lastindent != stmtindent && @@ -3457,7 +3456,7 @@ test(int label, int parens, int invert) if (lval.ident == iARRAY || lval.ident == iREFARRAY) { char *ptr = - (lval.sym->name != NULL) ? lval.sym->name : "-unknown-"; + (lval.sym->name) ? lval.sym->name : "-unknown-"; error(33, ptr); /* array must be indexed */ } /* if */ if (lval.ident == iCONSTEXPR) @@ -3730,10 +3729,10 @@ doswitch(void) * case values at the same time. */ for (csp = &caselist, cse = caselist.next; - cse != NULL && cse->value < val; + cse && cse->value < val; csp = cse, cse = cse->next) /* nothing */ ; - if (cse != NULL && cse->value == val) + if (cse && cse->value == val) error(40, val); /* duplicate "case" label */ /* Since the label is stored as a string in the * "constvalue", the size of an identifier must @@ -3756,10 +3755,10 @@ doswitch(void) casecount++; /* find the new insertion point */ for (csp = &caselist, cse = caselist.next; - cse != NULL && cse->value < val; + cse && cse->value < val; csp = cse, cse = cse->next) /* nothing */ ; - if (cse != NULL && cse->value == val) + if (cse && cse->value == val) error(40, val); /* duplicate "case" label */ insert_constval(csp, cse, itoh(lbl_case), val, 0); } /* if */ @@ -3801,7 +3800,7 @@ doswitch(void) /* verify that the case table is sorted (unfortunatly, duplicates can * occur; there really shouldn't be duplicate cases, but the compiler * may not crash or drop into an assertion for a user error). */ - for (cse = caselist.next; cse != NULL && cse->next != NULL; cse = cse->next) + for (cse = caselist.next; cse && cse->next; cse = cse->next) ; /* empty. no idea whether this is correct, but we MUST NOT do * the setlabel(lbl_table) call in the loop body. doing so breaks * switch statements that only have one case statement following. @@ -3823,7 +3822,7 @@ doswitch(void) } /* if */ ffcase(casecount, labelname, TRUE); /* generate the rest of the table */ - for (cse = caselist.next; cse != NULL; cse = cse->next) + for (cse = caselist.next; cse; cse = cse->next) ffcase(cse->value, cse->name, FALSE); setlabel(lbl_exit); @@ -3896,7 +3895,7 @@ dolabel(void) symbol *sym; tokeninfo(&val, &st); /* retrieve label name again */ - if (find_constval(&tagname_tab, st, 0) != NULL) + if (find_constval(&tagname_tab, st, 0)) error(221, st); /* label name shadows tagname */ sym = fetchlab(st); setlabel((int)sym->addr); @@ -3983,7 +3982,7 @@ dobreak(void) ptr = readwhile(); /* readwhile() gives an error if not in loop */ needtoken(tTERM); - if (ptr == NULL) + if (!ptr) return; destructsymbols(&loctab, nestlevel); modstk(((int)declared - ptr[wqBRK]) * sizeof(cell)); @@ -3997,7 +3996,7 @@ docont(void) ptr = readwhile(); /* readwhile() gives an error if not in loop */ needtoken(tTERM); - if (ptr == NULL) + if (!ptr) return; destructsymbols(&loctab, nestlevel); modstk(((int)declared - ptr[wqCONT]) * sizeof(cell)); @@ -4016,9 +4015,9 @@ exporttag(int tag) assert((tag & PUBLICTAG) == 0); for (ptr = tagname_tab.next; - ptr != NULL && tag != (int)(ptr->value & TAGMASK); ptr = ptr->next) + ptr && tag != (int)(ptr->value & TAGMASK); ptr = ptr->next) /* nothing */ ; - if (ptr != NULL) + if (ptr) ptr->value |= PUBLICTAG; } /* if */ } diff --git a/legacy/embryo/src/bin/embryo_cc_sc2.c b/legacy/embryo/src/bin/embryo_cc_sc2.c index b29dc7f2e8..67845f8e94 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc2.c +++ b/legacy/embryo/src/bin/embryo_cc_sc2.c @@ -91,18 +91,18 @@ plungequalifiedfile(char *name) { fp = (FILE *) sc_opensrc(name); ext = strchr(name, '\0'); /* save position */ - if (fp == NULL) + if (!fp) { /* try to append an extension */ strcpy(ext, extensions[ext_idx]); fp = (FILE *) sc_opensrc(name); - if (fp == NULL) + if (!fp) *ext = '\0'; /* on failure, restore filename */ } /* if */ ext_idx++; } - while (fp == NULL && ext_idx < (sizeof extensions / sizeof extensions[0])); - if (fp == NULL) + while (!fp && ext_idx < (sizeof extensions / sizeof extensions[0])); + if (!fp) { *ext = '\0'; /* restore filename */ return FALSE; @@ -116,7 +116,7 @@ plungequalifiedfile(char *name) pushstk((stkitem) fcurrent); pushstk((stkitem) fline); inpfname = strdup(name); /* set name of include file */ - if (inpfname == NULL) + if (!inpfname) error(103); /* insufficient memory */ inpf = fp; /* set input file pointer to include file */ fnumber++; @@ -141,7 +141,7 @@ plungefile(char *name, int try_currentpath, int try_includepaths) if (try_includepaths && name[0] != DIRSEP_CHAR) { - for (i = 0; !result && (ptr = get_path(i)) != NULL; i++) + for (i = 0; !result && (ptr = get_path(i)); i++) { char path[PATH_MAX]; @@ -242,11 +242,11 @@ readline(char *line) cont = FALSE; do { - if (inpf == NULL || sc_eofsrc(inpf)) + if (!inpf || sc_eofsrc(inpf)) { if (cont) error(49); /* invalid line continuation */ - if (inpf != NULL && inpf != inpf_org) + if (inpf && inpf != inpf_org) sc_closesrc(inpf); i = (int)(long)popstk(); if (i == -1) @@ -277,7 +277,7 @@ readline(char *line) elsedone = 0; } /* if */ - if (sc_readsrc(inpf, line, num) == NULL) + if (!sc_readsrc(inpf, line, num)) { *line = '\0'; /* delete line */ cont = FALSE; @@ -296,10 +296,10 @@ readline(char *line) } /* if */ cont = FALSE; /* check whether a full line was read */ - if (strchr(line, '\n') == NULL && !sc_eofsrc(inpf)) + if (!strchr(line, '\n') && !sc_eofsrc(inpf)) error(75); /* line too long */ /* check if the next line must be concatenated to this line */ - if ((ptr = strchr(line, '\n')) != NULL && ptr > line) + if ((ptr = strchr(line, '\n')) && ptr > line) { assert(*(ptr + 1) == '\0'); /* '\n' should be last in the string */ while (ptr > line @@ -368,7 +368,7 @@ stripcom(char *line) } else if (*line == '/' && *(line + 1) == '/') { /* comment to end of line */ - if (strchr(line, '\a') != NULL) + if (strchr(line, '\a')) error(49); /* invalid line continuation */ *line++ = '\n'; /* put "newline" at first slash */ *line = '\0'; /* put "zero-terminator" at second slash */ @@ -929,7 +929,7 @@ command(void) { free(inpfname); inpfname = strdup(pathname); - if (inpfname == NULL) + if (!inpfname) error(103); /* insufficient memory */ } /* if */ } /* if */ @@ -1003,7 +1003,7 @@ command(void) if (strlen(name) > sEXPMAX) error(220, name, sEXPMAX); /* exported symbol is truncated */ /* add the name if it does not yet exist in the table */ - if (find_constval(&libname_tab, name, 0) == NULL) + if (!find_constval(&libname_tab, name, 0)) curlibrary = append_constval(&libname_tab, name, 0, 0); } /* if */ @@ -1092,9 +1092,9 @@ command(void) name[i] = '\0'; /* get the symbol */ sym = findloc(name); - if (sym == NULL) + if (!sym) sym = findglb(name); - if (sym != NULL) + if (sym) { sym->usage |= uREAD; if (sym->ident == iVARIABLE @@ -1172,9 +1172,9 @@ command(void) break; case tSYMBOL: sym = findloc(str); - if (sym == NULL) + if (!sym) sym = findglb(str); - if (sym == NULL || (sym->ident != iFUNCTN + if (!sym || (sym->ident != iFUNCTN && sym->ident != iREFFUNC && (sym->usage & uDEFINE) == 0)) { @@ -1237,7 +1237,7 @@ command(void) } /* if */ /* store matched pattern */ pattern = malloc(count + 1); - if (pattern == NULL) + if (!pattern) error(103); /* insufficient memory */ lptr = start; count = 0; @@ -1263,7 +1263,7 @@ command(void) /* keep position of the start of trailing whitespace */ if (*lptr <= ' ') { - if (end == NULL) + if (!end) end = lptr; } else @@ -1273,11 +1273,11 @@ command(void) count++; lptr++; } /* while */ - if (end == NULL) + if (!end) end = lptr; /* store matched substitution */ substitution = malloc(count + 1); /* +1 for '\0' */ - if (substitution == NULL) + if (!substitution) error(103); /* insufficient memory */ lptr = start; count = 0; @@ -1294,7 +1294,7 @@ command(void) prefixlen++, start++) /* nothing */ ; assert(prefixlen > 0); - if ((def = find_subst(pattern, prefixlen)) != NULL) + if ((def = find_subst(pattern, prefixlen))) { if (strcmp(def->first, pattern) != 0 || strcmp(def->second, substitution) != 0) @@ -1492,18 +1492,18 @@ substpattern(char *line, size_t buffersize, char *pattern, char *substitution) { if (is_startstring(e)) /* skip strings */ e = skipstring(e); - else if (strchr("({[", *e) != NULL) /* skip parenthized groups */ + else if (strchr("({[", *e)) /* skip parenthized groups */ e = skippgroup(e); if (*e != '\0') e++; /* skip non-alphapetic character (or closing quote of * a string, or the closing paranthese of a group) */ } /* while */ /* store the parameter (overrule any earlier) */ - if (args[arg] != NULL) + if (args[arg]) free(args[arg]); len = (int)(e - s); args[arg] = malloc(len + 1); - if (args[arg] == NULL) + if (!args[arg]) error(103); /* insufficient memory */ strncpy(args[arg], s, len); args[arg][len] = '\0'; @@ -1577,7 +1577,7 @@ substpattern(char *line, size_t buffersize, char *pattern, char *substitution) { arg = *(e + 1) - '0'; assert(arg >= 0 && arg <= 9); - if (args[arg] != NULL) + if (args[arg]) len += strlen(args[arg]); e++; /* skip %, digit is skipped later */ } @@ -1601,7 +1601,7 @@ substpattern(char *line, size_t buffersize, char *pattern, char *substitution) { arg = *(e + 1) - '0'; assert(arg >= 0 && arg <= 9); - if (args[arg] != NULL) + if (args[arg]) { strins(s, args[arg], strlen(args[arg])); s += strlen(args[arg]); @@ -1618,7 +1618,7 @@ substpattern(char *line, size_t buffersize, char *pattern, char *substitution) } /* if */ for (arg = 0; arg < 10; arg++) - if (args[arg] != NULL) + if (args[arg]) free(args[arg]); return match; @@ -1660,7 +1660,7 @@ substallpatterns(char *line, int buffersize) } /* while */ assert(prefixlen > 0); subst = find_subst(start, prefixlen); - if (subst != NULL) + if (subst) { /* properly match the pattern and substitute */ if (!substpattern @@ -2215,7 +2215,7 @@ stowlit(cell value) litmax += sDEF_LITMAX; p = (cell *) realloc(litq, litmax * sizeof(cell)); - if (p == NULL) + if (!p) error(102, "literal table"); /* literal table overflow (fatal error) */ litq = p; } /* if */ @@ -2348,10 +2348,10 @@ add_symbol(symbol * root, symbol * entry, int sort) symbol *newsym; if (sort) - while (root->next != NULL && strcmp(entry->name, root->next->name) > 0) + while (root->next && strcmp(entry->name, root->next->name) > 0) root = root->next; - if ((newsym = (symbol *) malloc(sizeof(symbol))) == NULL) + if (!(newsym = (symbol *)malloc(sizeof(symbol)))) { error(103); return NULL; @@ -2421,7 +2421,7 @@ delete_symbols(symbol * root, int level, int delete_labels, /* erase only the symbols with a deeper nesting level than the * specified nesting level */ - while (root->next != NULL) + while (root->next) { sym = root->next; if (sym->compound < level) @@ -2484,10 +2484,10 @@ find_symbol(symbol * root, char *name, int fnumber) symbol *ptr = root->next; unsigned long hash = namehash(name); - while (ptr != NULL) + while (ptr) { if (hash == ptr->hash && strcmp(name, ptr->name) == 0 - && ptr->parent == NULL && (ptr->fnumber < 0 + && !ptr->parent && (ptr->fnumber < 0 || ptr->fnumber == fnumber)) return ptr; ptr = ptr->next; @@ -2500,7 +2500,7 @@ find_symbol_child(symbol * root, symbol * sym) { symbol *ptr = root->next; - while (ptr != NULL) + while (ptr) { if (ptr->parent == sym) return ptr; @@ -2533,7 +2533,7 @@ refer_symbol(symbol * entry, symbol * bywhom) } /* if */ /* see if there is an empty spot in the referrer list */ - for (count = 0; count < entry->numrefers && entry->refer[count] != NULL; + for (count = 0; count < entry->numrefers && entry->refer[count]; count++) /* nothing */ ; assert(count <= entry->numrefers); @@ -2545,7 +2545,7 @@ refer_symbol(symbol * entry, symbol * bywhom) assert(newsize > 0); /* grow the referrer list */ refer = (symbol **) realloc(entry->refer, newsize * sizeof(symbol *)); - if (refer == NULL) + if (!refer) return FALSE; /* insufficient memory */ /* initialize the new entries */ entry->refer = refer; @@ -2575,7 +2575,7 @@ markusage(symbol * sym, int usage) * outside functions; in the case of syntax errors, however, the * compiler may arrive through this function */ - if (curfunc != NULL) + if (curfunc) refer_symbol(sym, curfunc); } /* if */ } /* if */ @@ -2608,9 +2608,9 @@ findconst(char *name) symbol *sym; sym = find_symbol(&loctab, name, -1); /* try local symbols first */ - if (sym == NULL || sym->ident != iCONSTEXPR) /* not found, or not a constant */ + if (!sym || sym->ident != iCONSTEXPR) /* not found, or not a constant */ sym = find_symbol(&glbtab, name, fcurrent); - if (sym == NULL || sym->ident != iCONSTEXPR) + if (!sym || sym->ident != iCONSTEXPR) return NULL; assert(sym->parent == NULL); /* constants have no hierarchy */ return sym; @@ -2622,7 +2622,7 @@ finddepend(symbol * parent) symbol *sym; sym = find_symbol_child(&loctab, parent); /* try local symbols first */ - if (sym == NULL) /* not found */ + if (!sym) /* not found */ sym = find_symbol_child(&glbtab, parent); return sym; } @@ -2644,7 +2644,7 @@ addsym(char *name, cell addr, int ident, int vclass, int tag, int usage) assert(ident != iLABEL || findloc(name) == NULL); /* create an empty referrer list */ - if ((refer = (symbol **) malloc(sizeof(symbol *))) == NULL) + if (!(refer = (symbol **)malloc(sizeof(symbol *)))) { error(103); /* insufficient memory */ return NULL; diff --git a/legacy/embryo/src/bin/embryo_cc_sc3.c b/legacy/embryo/src/bin/embryo_cc_sc3.c index b4fe044484..69bb34fe92 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc3.c +++ b/legacy/embryo/src/bin/embryo_cc_sc3.c @@ -154,11 +154,11 @@ check_userop(void (*oper) (void), int tag1, int tag2, int numparam, /* find the name with the operator */ if (numparam == 2) { - if (oper == NULL) + if (!oper) { /* assignment operator: a special case */ strcpy(opername, "="); - if (lval != NULL + if (lval && (lval->ident == iARRAYCELL || lval->ident == iARRAYCHAR)) savealt = TRUE; } @@ -205,10 +205,10 @@ check_userop(void (*oper) (void), int tag1, int tag2, int numparam, operator_symname(symbolname, opername, tag1, tag2, numparam, tag2); swapparams = FALSE; sym = findglb(symbolname); - if (sym == NULL /*|| (sym->usage & uDEFINE)==0 */ ) + if (!sym /*|| (sym->usage & uDEFINE)==0 */ ) { /* ??? should not check uDEFINE; first pass clears these bits */ /* check for commutative operators */ - if (tag1 == tag2 || oper == NULL || !commutative(oper)) + if (tag1 == tag2 || !oper || !commutative(oper)) return FALSE; /* not commutative, cannot swap operands */ /* if arrived here, the operator is commutative and the tags are different, * swap tags and try again @@ -217,7 +217,7 @@ check_userop(void (*oper) (void), int tag1, int tag2, int numparam, operator_symname(symbolname, opername, tag2, tag1, numparam, tag1); swapparams = TRUE; sym = findglb(symbolname); - if (sym == NULL /*|| (sym->usage & uDEFINE)==0 */ ) + if (!sym /*|| (sym->usage & uDEFINE)==0 */ ) return FALSE; } /* if */ @@ -275,7 +275,7 @@ check_userop(void (*oper) (void), int tag1, int tag2, int numparam, } /* if */ /* push parameters, call the function */ - paramspassed = (oper == NULL) ? 1 : numparam; + paramspassed = (!oper) ? 1 : numparam; switch (paramspassed) { case 1: @@ -305,7 +305,7 @@ check_userop(void (*oper) (void), int tag1, int tag2, int numparam, ffcall(sym, paramspassed); if (sc_status != statSKIP) markusage(sym, uREAD); /* do not mark as "used" when this call itself is skipped */ - if (sym->x.lib != NULL) + if (sym->x.lib) sym->x.lib->value += 1; /* increment "usage count" of the library */ sideeffect = TRUE; /* assume functions carry out a side-effect */ assert(resulttag != NULL); @@ -483,7 +483,7 @@ checkfunction(value * lval) { symbol *sym = lval->sym; - if (sym == NULL || (sym->ident != iFUNCTN && sym->ident != iREFFUNC)) + if (!sym || (sym->ident != iFUNCTN && sym->ident != iREFFUNC)) return; /* no known symbol, or not a function result */ if ((sym->usage & uDEFINE) != 0) @@ -532,7 +532,7 @@ plnge(int *opstr, int opoff, int (*hier) (value * lval), value * lval, plnge2(op1[opidx], hier, lval, &lval2); if (op1[opidx] == ob_and || op1[opidx] == ob_or) bitwise_opercount++; - if (forcetag != NULL) + if (forcetag) lval->tag = sc_addtag(forcetag); } while (nextop(&opidx, opstr)); /* do */ @@ -671,13 +671,13 @@ plnge2(void (*oper) (void), if (lval1->ident == iARRAY || lval1->ident == iREFARRAY) { char *ptr = - (lval1->sym != NULL) ? lval1->sym->name : "-unknown-"; + (lval1->sym) ? lval1->sym->name : "-unknown-"; error(33, ptr); /* array must be indexed */ } else if (lval2->ident == iARRAY || lval2->ident == iREFARRAY) { char *ptr = - (lval2->sym != NULL) ? lval2->sym->name : "-unknown-"; + (lval2->sym) ? lval2->sym->name : "-unknown-"; error(33, ptr); /* array must be indexed */ } /* if */ /* ??? ^^^ should do same kind of error checking with functions */ @@ -775,7 +775,7 @@ expression(int *constant, cell * val, int *tag, int chkfuncresult) *constant = FALSE; *val = 0; } /* if */ - if (tag != NULL) + if (tag) *tag = lval.tag; if (chkfuncresult) checkfunction(&lval); @@ -841,7 +841,7 @@ hier14(value * lval1) for (i = 0; i < sDIMEN_MAX; i++) arrayidx1[i] = arrayidx2[i] = 0; org_arrayidx = lval1->arrayidx; /* save current pointer, to reset later */ - if (lval1->arrayidx == NULL) + if (!lval1->arrayidx) lval1->arrayidx = arrayidx1; lvalue = plnge1(hier13, lval1); if (lval1->ident != iARRAYCELL && lval1->ident != iARRAYCHAR) @@ -938,7 +938,7 @@ hier14(value * lval1) lval2.arrayidx = NULL; if (oper) pop2(); - if (!oper && lval3.arrayidx != NULL && lval2.arrayidx != NULL + if (!oper && lval3.arrayidx && lval2.arrayidx && lval3.ident == lval2.ident && lval3.sym == lval2.sym) { int same = TRUE; @@ -984,7 +984,7 @@ hier14(value * lval1) if (lval2.ident != iARRAY && lval2.ident != iREFARRAY) error(33, lval3.sym->name); /* array must be indexed */ - if (lval2.sym != NULL) + if (lval2.sym) { val = lval2.sym->dim.array.length; /* array variable */ level = lval2.sym->dim.array.level; @@ -1095,13 +1095,13 @@ hier13(value * lval) if (array1 && !array2) { char *ptr = - (lval->sym->name != NULL) ? lval->sym->name : "-unknown-"; + (lval->sym->name) ? lval->sym->name : "-unknown-"; error(33, ptr); /* array must be indexed */ } else if (!array1 && array2) { char *ptr = - (lval2.sym->name != NULL) ? lval2.sym->name : "-unknown-"; + (lval2.sym->name) ? lval2.sym->name : "-unknown-"; error(33, ptr); /* array must be indexed */ } /* if */ /* ??? if both are arrays, should check dimensions */ @@ -1295,13 +1295,13 @@ hier2(value * lval) if (tok != tSYMBOL) return error(20, st); /* illegal symbol name */ sym = findloc(st); - if (sym == NULL) + if (!sym) sym = findglb(st); - if (sym != NULL && sym->ident != iFUNCTN && sym->ident != iREFFUNC + if (sym && sym->ident != iFUNCTN && sym->ident != iREFFUNC && (sym->usage & uDEFINE) == 0) sym = NULL; /* symbol is not a function, it is in the table, but not "defined" */ val = (sym != NULL); - if (!val && find_subst(st, strlen(st)) != NULL) + if (!val && find_subst(st, strlen(st))) val = 1; clear_value(lval); lval->ident = iCONSTEXPR; @@ -1318,9 +1318,9 @@ hier2(value * lval) if (tok != tSYMBOL) return error(20, st); /* illegal symbol name */ sym = findloc(st); - if (sym == NULL) + if (!sym) sym = findglb(st); - if (sym == NULL) + if (!sym) return error(17, st); /* undefined symbol */ if (sym->ident == iCONSTEXPR) error(39); /* constant symbol has no size */ @@ -1341,7 +1341,7 @@ hier2(value * lval) error(28); /* invalid subscript */ else lval->constval = array_levelsize(sym, level); - if (lval->constval == 0 && strchr(lptr, PREPROC_TERM) == NULL) + if (lval->constval == 0 && !strchr(lptr, PREPROC_TERM)) error(224, st); /* indeterminate array size in "sizeof" expression */ } /* if */ const1(lval->constval); @@ -1362,9 +1362,9 @@ hier2(value * lval) else { sym = findloc(st); - if (sym == NULL) + if (!sym) sym = findglb(st); - if (sym == NULL) + if (!sym) return error(17, st); /* undefined symbol */ if ((sym->usage & uDEFINE) == 0) return error(17, st); /* undefined symbol (symbol is in the table, but it is "used" only) */ @@ -1497,7 +1497,7 @@ hier1(value * lval1) if (matchtoken('[') || matchtoken('{') || matchtoken('(')) { tok = tokeninfo(&val, &st); /* get token read by matchtoken() */ - if (sym == NULL && symtok != tSYMBOL) + if (!sym && symtok != tSYMBOL) { /* we do not have a valid symbol and we appear not to have read a valid * symbol name (so it is unlikely that we would have read a name of an @@ -1509,7 +1509,7 @@ hier1(value * lval1) if (tok == '[' || tok == '{') { /* subscript */ close = (char)((tok == '[') ? ']' : '}'); - if (sym == NULL) + if (!sym) { /* sym==NULL if lval is a constant or a literal */ error(28); /* cannot subscript */ needtoken(close); @@ -1539,7 +1539,7 @@ hier1(value * lval1) if (lval2.ident == iCONSTEXPR) { /* constant expression */ stgdel(index, cidx); /* scratch generated code */ - if (lval1->arrayidx != NULL) + if (lval1->arrayidx) { /* keep constant index, for checking */ assert(sym->dim.array.level >= 0 && sym->dim.array.level < sDIMEN_MAX); @@ -1634,16 +1634,16 @@ hier1(value * lval1) } else { /* tok=='(' -> function(...) */ - if (sym == NULL + if (!sym || (sym->ident != iFUNCTN && sym->ident != iREFFUNC)) { - if (sym == NULL && sc_status == statFIRST) + if (!sym && sc_status == statFIRST) { /* could be a "use before declaration"; in that case, create a stub * function so that the usage can be marked. */ sym = fetchfunc(lastsymbol, 0); - if (sym != NULL) + if (sym) markusage(sym, uREAD); } /* if */ return error(12); /* invalid function call */ @@ -1662,7 +1662,7 @@ hier1(value * lval1) return FALSE; /* result of function call is no lvalue */ } /* if */ } /* if */ - if (sym != NULL && lval1->ident == iFUNCTN) + if (sym && lval1->ident == iFUNCTN) { assert(sym->ident == iFUNCTN); address(sym); @@ -1723,7 +1723,7 @@ primary(value * lval) if (tok == tSYMBOL && !findconst(st)) { /* first look for a local variable */ - if ((sym = findloc(st)) != NULL) + if ((sym = findloc(st))) { if (sym->ident == iLABEL) { @@ -1745,7 +1745,7 @@ primary(value * lval) } /* if */ } /* if */ /* now try a global variable */ - if ((sym = findglb(st)) != NULL) + if ((sym = findglb(st))) { if (sym->ident == iFUNCTN || sym->ident == iREFFUNC) { @@ -2009,7 +2009,7 @@ callfunction(symbol * sym) } /* if */ /* ??? handle const array passed by reference */ /* otherwise, the address is already in PRI */ - if (lval.sym != NULL) + if (lval.sym) markusage(lval.sym, uWRITTEN); /* * Dont need this warning - its varargs. there is no way of knowing the @@ -2038,7 +2038,7 @@ callfunction(symbol * sym) case iREFERENCE: if (!lvalue || lval.ident == iARRAYCHAR) error(35, argidx + 1); /* argument type mismatch */ - if (lval.sym != NULL && (lval.sym->usage & uCONST) != 0 + if (lval.sym && (lval.sym->usage & uCONST) != 0 && (arg[argidx].usage & uCONST) == 0) error(35, argidx + 1); /* argument type mismatch */ if (lval.ident == iVARIABLE || lval.ident == iREFERENCE) @@ -2059,7 +2059,7 @@ callfunction(symbol * sym) (arg[argidx].tags, arg[argidx].numtags, lval.tag)) error(213); argidx++; /* argument done */ - if (lval.sym != NULL) + if (lval.sym) markusage(lval.sym, uWRITTEN); break; case iREFARRAY: @@ -2069,14 +2069,14 @@ callfunction(symbol * sym) error(35, argidx + 1); /* argument type mismatch */ break; } /* if */ - if (lval.sym != NULL && (lval.sym->usage & uCONST) != 0 + if (lval.sym && (lval.sym->usage & uCONST) != 0 && (arg[argidx].usage & uCONST) == 0) error(35, argidx + 1); /* argument type mismatch */ /* Verify that the dimensions match with those in arg[argidx]. * A literal array always has a single dimension. * An iARRAYCELL parameter is also assumed to have a single dimension. */ - if (lval.sym == NULL || lval.ident == iARRAYCELL) + if (!lval.sym || lval.ident == iARRAYCELL) { if (arg[argidx].numdim != 1) { @@ -2267,7 +2267,7 @@ callfunction(symbol * sym) */ asz = find_constval(&arrayszlst, arg[argidx].defvalue.size.symname, arg[argidx].defvalue.size.level); - if (asz != NULL) + if (asz) { array_sz = asz->value; if (array_sz == 0) @@ -2284,9 +2284,9 @@ callfunction(symbol * sym) assert((arg[argidx].hasdefault & uTAGOF) != 0); sym = findloc(arg[argidx].defvalue.size.symname); - if (sym == NULL) + if (!sym) sym = findglb(arg[argidx].defvalue.size.symname); - array_sz = (sym != NULL) ? sym->tag : 0; + array_sz = (sym) ? sym->tag : 0; exporttag(array_sz); } /* if */ const1(array_sz); @@ -2301,7 +2301,7 @@ callfunction(symbol * sym) ffcall(sym, nargs); if (sc_status != statSKIP) markusage(sym, uREAD); /* do not mark as "used" when this call itself is skipped */ - if (sym->x.lib != NULL) + if (sym->x.lib) sym->x.lib->value += 1; /* increment "usage count" of the library */ modheap(-heapalloc * sizeof(cell)); sideeffect = TRUE; /* assume functions carry out a side-effect */ @@ -2371,7 +2371,7 @@ constant(value * lval) symbol *sym; tok = lex(&val, &st); - if (tok == tSYMBOL && (sym = findconst(st)) != NULL) + if (tok == tSYMBOL && (sym = findconst(st))) { lval->constval = sym->addr; const1(lval->constval); diff --git a/legacy/embryo/src/bin/embryo_cc_sc5.c b/legacy/embryo/src/bin/embryo_cc_sc5.c index 39b61f7b31..86ef2afa35 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc5.c +++ b/legacy/embryo/src/bin/embryo_cc_sc5.c @@ -110,7 +110,7 @@ error(int number, ...) sc_error(0, "\nCompilation aborted.", NULL, 0, 0, argptr); va_end(argptr); - if (outf != NULL) + if (outf) { sc_closeasm(outf); outf = NULL; diff --git a/legacy/embryo/src/bin/embryo_cc_sc6.c b/legacy/embryo/src/bin/embryo_cc_sc6.c index bf40e16a21..61e182874f 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc6.c +++ b/legacy/embryo/src/bin/embryo_cc_sc6.c @@ -83,7 +83,7 @@ hex2long(char *s, char **n) result = (result << 4) | digit; s++; } /* for */ - if (n != NULL) + if (n) *n = s; if (negate) result = (~result) + 1; /* take two's complement of the result */ @@ -144,7 +144,7 @@ stripcomment(char *str) { char *ptr = strchr(str, ';'); - if (ptr != NULL) + if (ptr) { *ptr++ = '\n'; /* terminate the line, but leave the '\n' */ *ptr = '\0'; @@ -223,7 +223,7 @@ noop(FILE * fbin __UNUSED__, char *params __UNUSED__, cell opcode __UNUSED__) static cell parm0(FILE * fbin, char *params __UNUSED__, cell opcode) { - if (fbin != NULL) + if (fbin) write_encoded(fbin, (ucell *) & opcode, 1); return opcodes(1); } @@ -233,7 +233,7 @@ parm1(FILE * fbin, char *params, cell opcode) { ucell p = hex2long(params, NULL); - if (fbin != NULL) + if (fbin) { write_encoded(fbin, (ucell *) & opcode, 1); write_encoded(fbin, &p, 1); @@ -248,7 +248,7 @@ parm2(FILE * fbin, char *params, cell opcode) p[0] = hex2long(params, ¶ms); p[1] = hex2long(params, NULL); - if (fbin != NULL) + if (fbin) { write_encoded(fbin, (ucell *) & opcode, 1); write_encoded(fbin, p, 2); @@ -269,7 +269,7 @@ do_dump(FILE * fbin, char *params, cell opcode __UNUSED__) while (*params != '\0') { p = hex2long(params, ¶ms); - if (fbin != NULL) + if (fbin) write_encoded(fbin, &p, 1); num++; while (isspace(*params)) @@ -303,7 +303,7 @@ do_call(FILE * fbin, char *params, cell opcode) assert(sym->vclass == sGLOBAL); p = sym->addr; - if (fbin != NULL) + if (fbin) { write_encoded(fbin, (ucell *) & opcode, 1); write_encoded(fbin, &p, 1); @@ -320,7 +320,7 @@ do_jump(FILE * fbin, char *params, cell opcode) i = (int)hex2long(params, NULL); assert(i >= 0 && i < labnum); - if (fbin != NULL) + if (fbin) { assert(lbltab != NULL); p = lbltab[i]; @@ -350,7 +350,7 @@ do_file(FILE * fbin, char *params, cell opcode) assert(len > 0 && len < 256); clen = len + sizeof(cell); /* add size of file ordinal */ - if (fbin != NULL) + if (fbin) { write_encoded(fbin, (ucell *) & opcode, 1); write_encoded(fbin, &clen, 1); @@ -385,7 +385,7 @@ do_symbol(FILE * fbin, char *params, cell opcode) params[len++] = '\0'; /* pad with zeros up to full cell */ clen = len + 2 * sizeof(cell); /* add size of symbol address and flags */ - if (fbin != NULL) + if (fbin) { write_encoded(fbin, (ucell *) & opcode, 1); write_encoded(fbin, &clen, 1); @@ -396,7 +396,7 @@ do_symbol(FILE * fbin, char *params, cell opcode) #if !defined NDEBUG /* function should start right after the symbolic information */ - if (fbin == NULL && mclass == 0 && type == iFUNCTN) + if (!fbin && mclass == 0 && type == iFUNCTN) assert(offset == codeindex + opcodes(1) + opargs(1) + clen); #endif @@ -412,7 +412,7 @@ do_switch(FILE * fbin, char *params, cell opcode) i = (int)hex2long(params, NULL); assert(i >= 0 && i < labnum); - if (fbin != NULL) + if (fbin) { assert(lbltab != NULL); p = lbltab[i]; @@ -436,7 +436,7 @@ do_case(FILE * fbin, char *params, cell opcode __UNUSED__) i = (int)hex2long(params, NULL); assert(i >= 0 && i < labnum); - if (fbin != NULL) + if (fbin) { assert(lbltab != NULL); p = lbltab[i]; @@ -679,7 +679,7 @@ assemble(FILE * fout, FILE * fin) numpubvars = 0; mainaddr = -1; /* count number of public and native functions and public variables */ - for (sym = glbtab.next; sym != NULL; sym = sym->next) + for (sym = glbtab.next; sym; sym = sym->next) { char alias[sNAMEMAX + 1] = ""; int match = 0; @@ -723,7 +723,7 @@ assemble(FILE * fout, FILE * fin) /* count number of libraries */ numlibraries = 0; - for (constptr = libname_tab.next; constptr != NULL; + for (constptr = libname_tab.next; constptr; constptr = constptr->next) { if (constptr->value > 0) @@ -736,7 +736,7 @@ assemble(FILE * fout, FILE * fin) /* count number of public tags */ numtags = 0; - for (constptr = tagname_tab.next; constptr != NULL; + for (constptr = tagname_tab.next; constptr; constptr = constptr->next) { if ((constptr->value & PUBLICTAG) != 0) @@ -812,7 +812,7 @@ assemble(FILE * fout, FILE * fin) /* write the public functions table */ count = 0; - for (sym = glbtab.next; sym != NULL; sym = sym->next) + for (sym = glbtab.next; sym; sym = sym->next) { if (sym->ident == iFUNCTN && (sym->usage & uPUBLIC) != 0 && (sym->usage & uDEFINE) != 0) @@ -847,12 +847,12 @@ assemble(FILE * fout, FILE * fin) if (numnatives > 0) { nativelist = (symbol **) malloc(numnatives * sizeof(symbol *)); - if (nativelist == NULL) + if (!nativelist) error(103); /* insufficient memory */ #if !defined NDEBUG memset(nativelist, 0, numnatives * sizeof(symbol *)); /* for NULL checking */ #endif - for (sym = glbtab.next; sym != NULL; sym = sym->next) + for (sym = glbtab.next; sym; sym = sym->next) { if (sym->ident == iFUNCTN && (sym->usage & uNATIVE) != 0 && (sym->usage & uREAD) != 0 && sym->addr >= 0) @@ -892,7 +892,7 @@ assemble(FILE * fout, FILE * fin) /* write the libraries table */ count = 0; - for (constptr = libname_tab.next; constptr != NULL; + for (constptr = libname_tab.next; constptr; constptr = constptr->next) { if (constptr->value > 0) @@ -915,7 +915,7 @@ assemble(FILE * fout, FILE * fin) /* write the public variables table */ count = 0; - for (sym = glbtab.next; sym != NULL; sym = sym->next) + for (sym = glbtab.next; sym; sym = sym->next) { if (sym->ident == iVARIABLE && (sym->usage & uPUBLIC) != 0) { @@ -938,7 +938,7 @@ assemble(FILE * fout, FILE * fin) /* write the public tagnames table */ count = 0; - for (constptr = tagname_tab.next; constptr != NULL; + for (constptr = tagname_tab.next; constptr; constptr = constptr->next) { if ((constptr->value & PUBLICTAG) != 0) @@ -980,11 +980,11 @@ assemble(FILE * fout, FILE * fin) /* only very short programs have zero labels; no first pass is needed * if there are no labels */ lbltab = (cell *) malloc(labnum * sizeof(cell)); - if (lbltab == NULL) + if (!lbltab) error(103); /* insufficient memory */ codeindex = 0; sc_resetasm(fin); - while (sc_readasm(fin, line, sizeof line) != NULL) + while (sc_readasm(fin, line, sizeof line)) { stripcomment(line); instr = skipwhitespace(line); @@ -1008,7 +1008,7 @@ assemble(FILE * fout, FILE * fin) /* nothing */ ; assert(params > instr); i = findopcode(instr, (int)(params - instr)); - if (opcodelist[i].name == NULL) + if (!opcodelist[i].name) { *params = '\0'; error(104, instr); /* invalid assembler instruction */ @@ -1027,7 +1027,7 @@ assemble(FILE * fout, FILE * fin) for (pass = sIN_CSEG; pass <= sIN_DSEG; pass++) { sc_resetasm(fin); - while (sc_readasm(fin, line, sizeof line) != NULL) + while (sc_readasm(fin, line, sizeof line)) { stripcomment(line); instr = skipwhitespace(line); @@ -1053,7 +1053,7 @@ assemble(FILE * fout, FILE * fin) if (bytes_out - bytes_in > 0) error(106); /* compression buffer overflow */ - if (lbltab != NULL) + if (lbltab) { free(lbltab); #if !defined NDEBUG diff --git a/legacy/embryo/src/bin/embryo_cc_sc7.c b/legacy/embryo/src/bin/embryo_cc_sc7.c index 8068f0e2b0..c8a977e696 100644 --- a/legacy/embryo/src/bin/embryo_cc_sc7.c +++ b/legacy/embryo/src/bin/embryo_cc_sc7.c @@ -77,7 +77,7 @@ static void grow_stgbuffer(int requiredsize) { char *p; - int clear = stgbuf == NULL; /* if previously none, empty buffer explicitly */ + int clear = !stgbuf; /* if previously none, empty buffer explicitly */ assert(stgmax < requiredsize); /* if the staging buffer (holding intermediate code for one line) grows @@ -86,11 +86,11 @@ grow_stgbuffer(int requiredsize) if (requiredsize > sSTG_MAX) error(102, "staging buffer"); /* staging buffer overflow (fatal error) */ stgmax = requiredsize + sSTG_GROW; - if (stgbuf != NULL) + if (stgbuf) p = (char *)realloc(stgbuf, stgmax * sizeof(char)); else p = (char *)malloc(stgmax * sizeof(char)); - if (p == NULL) + if (!p) error(102, "staging buffer"); /* staging buffer overflow (fatal error) */ stgbuf = p; if (clear) @@ -100,7 +100,7 @@ grow_stgbuffer(int requiredsize) void stgbuffer_cleanup(void) { - if (stgbuf != NULL) + if (stgbuf) { free(stgbuf); stgbuf = NULL; @@ -253,7 +253,7 @@ stgstring(char *start, char *end) start += 1; /* skip token */ /* allocate a argstack with sMAXARGS items */ stack = (argstack *) malloc(sMAXARGS * sizeof(argstack)); - if (stack == NULL) + if (!stack) error(103); /* insufficient memory */ nest = 1; /* nesting counter */ argc = 0; /* argument counter */ @@ -381,11 +381,11 @@ phopt_init(void) char str[160]; /* count number of sequences */ - for (number = 0; sequences_cmp[number].find != NULL; number++) + for (number = 0; sequences_cmp[number].find; number++) /* nothing */ ; number++; /* include an item for the NULL terminator */ - if ((sequences = (SEQUENCE *) malloc(number * sizeof(SEQUENCE))) == NULL) + if (!(sequences = (SEQUENCE *)malloc(number * sizeof(SEQUENCE)))) return FALSE; /* pre-initialize all to NULL (in case of failure) */ @@ -405,7 +405,7 @@ phopt_init(void) assert(len <= sizeof str); assert(len == (int)strlen(str) + 1); sequences[i].find = (char *)malloc(len); - if (sequences[i].find != NULL) + if (sequences[i].find) strcpy(sequences[i].find, str); len = strexpand(str, (unsigned char *)sequences_cmp[i].replace, sizeof str, @@ -413,10 +413,10 @@ phopt_init(void) assert(len <= sizeof str); assert(len == (int)strlen(str) + 1); sequences[i].replace = (char *)malloc(len); - if (sequences[i].replace != NULL) + if (sequences[i].replace) strcpy(sequences[i].replace, str); sequences[i].savesize = sequences_cmp[i].savesize; - if (sequences[i].find == NULL || sequences[i].replace == NULL) + if (!sequences[i].find || !sequences[i].replace) return phopt_cleanup(); } /* for */ @@ -428,14 +428,14 @@ phopt_cleanup(void) { int i; - if (sequences != NULL) + if (sequences) { i = 0; - while (sequences[i].find != NULL || sequences[i].replace != NULL) + while (sequences[i].find || sequences[i].replace) { - if (sequences[i].find != NULL) + if (sequences[i].find) free(sequences[i].find); - if (sequences[i].replace != NULL) + if (sequences[i].replace) free(sequences[i].replace); i++; } /* while */ @@ -558,7 +558,7 @@ replacesequence(char *pattern, char symbols[_maxoptvars][_aliasmax + 1], } /* while */ /* allocate a buffer to replace the sequence in */ - if ((buffer = malloc(*repl_length)) == NULL) + if (!(buffer = malloc(*repl_length))) { error(103); return NULL; @@ -638,7 +638,7 @@ stgopt(char *start, char *end) else { seq = 0; - while (sequences[seq].find != NULL) + while (sequences[seq].find) { assert(seq >= 0); if (matchsequence diff --git a/legacy/embryo/src/bin/embryo_cc_sclist.c b/legacy/embryo/src/bin/embryo_cc_sclist.c index b5612118ac..099c6b28bb 100644 --- a/legacy/embryo/src/bin/embryo_cc_sclist.c +++ b/legacy/embryo/src/bin/embryo_cc_sclist.c @@ -43,22 +43,22 @@ insert_stringpair(stringpair * root, char *first, char *second, int matchlength) assert(first != NULL); assert(second != NULL); /* create a new node, and check whether all is okay */ - if ((cur = (stringpair *) malloc(sizeof(stringpair))) == NULL) + if (!(cur = (stringpair *)malloc(sizeof(stringpair)))) return NULL; cur->first = strdup(first); cur->second = strdup(second); cur->matchlength = matchlength; - if (cur->first == NULL || cur->second == NULL) + if (!cur->first || !cur->second) { - if (cur->first != NULL) + if (cur->first) free(cur->first); - if (cur->second != NULL) + if (cur->second) free(cur->second); free(cur); return NULL; } /* if */ /* link the node to the tree, find the position */ - for (pred = root; pred->next != NULL && strcmp(pred->next->first, first) < 0; + for (pred = root; pred->next && strcmp(pred->next->first, first) < 0; pred = pred->next) /* nothing */ ; cur->next = pred->next; @@ -73,7 +73,7 @@ delete_stringpairtable(stringpair * root) assert(root != NULL); cur = root->next; - while (cur != NULL) + while (cur) { next = cur->next; assert(cur->first != NULL); @@ -93,7 +93,7 @@ find_stringpair(stringpair * cur, char *first, int matchlength) assert(matchlength > 0); /* the function cannot handle zero-length comparison */ assert(first != NULL); - while (cur != NULL && result <= 0) + while (cur && result <= 0) { result = (int)*cur->first - (int)*first; if (result == 0 && matchlength == cur->matchlength) @@ -114,7 +114,7 @@ delete_stringpair(stringpair * root, stringpair * item) assert(root != NULL); cur = root; - while (cur->next != NULL) + while (cur->next) { if (cur->next == item) { @@ -143,7 +143,7 @@ insert_alias(char *name, char *alias) assert(strlen(name) <= sNAMEMAX); assert(alias != NULL); assert(strlen(alias) <= sEXPMAX); - if ((cur = insert_stringpair(&alias_tab, name, alias, strlen(name))) == NULL) + if (!(cur = insert_stringpair(&alias_tab, name, alias, strlen(name)))) error(103); /* insufficient memory (fatal error) */ return cur; } @@ -153,7 +153,7 @@ lookup_alias(char *target, char *name) { stringpair *cur = find_stringpair(alias_tab.next, name, strlen(name)); - if (cur != NULL) + if (cur) { assert(strlen(cur->second) <= sEXPMAX); strcpy(target, cur->second); @@ -176,9 +176,9 @@ insert_path(char *path) stringlist *cur; assert(path != NULL); - if ((cur = (stringlist *) malloc(sizeof(stringlist))) == NULL) + if (!(cur = (stringlist *)malloc(sizeof(stringlist)))) error(103); /* insufficient memory (fatal error) */ - if ((cur->line = strdup(path)) == NULL) + if (!(cur->line = strdup(path))) error(103); /* insufficient memory (fatal error) */ cur->next = includepaths.next; includepaths.next = cur; @@ -190,9 +190,9 @@ get_path(int index) { stringlist *cur = includepaths.next; - while (cur != NULL && index-- > 0) + while (cur && index-- > 0) cur = cur->next; - if (cur != NULL) + if (cur) { assert(cur->line != NULL); return cur->line; @@ -205,7 +205,7 @@ delete_pathtable(void) { stringlist *cur = includepaths.next, *next; - while (cur != NULL) + while (cur) { next = cur->next; assert(cur->line != NULL); @@ -229,7 +229,7 @@ adjustindex(char c) assert((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_'); assert('A' < '_' && '_' < 'z'); - for (cur = substpair.next; cur != NULL && cur->first[0] != c; + for (cur = substpair.next; cur && cur->first[0] != c; cur = cur->next) /* nothing */ ; substindex[(int)c - 'A'] = cur; @@ -242,9 +242,7 @@ insert_subst(char *pattern, char *substitution, int prefixlen) assert(pattern != NULL); assert(substitution != NULL); - if ((cur = - insert_stringpair(&substpair, pattern, substitution, - prefixlen)) == NULL) + if (!(cur = insert_stringpair(&substpair, pattern, substitution, prefixlen))) error(103); /* insufficient memory (fatal error) */ adjustindex(*pattern); return cur; @@ -260,7 +258,7 @@ find_subst(char *name, int length) assert((*name >= 'A' && *name <= 'Z') || (*name >= 'a' && *name <= 'z') || *name == '_'); item = substindex[(int)*name - 'A']; - if (item != NULL) + if (item) item = find_stringpair(item, name, length); return item; } @@ -275,9 +273,9 @@ delete_subst(char *name, int length) assert((*name >= 'A' && *name <= 'Z') || (*name >= 'a' && *name <= 'z') || *name == '_'); item = substindex[(int)*name - 'A']; - if (item != NULL) + if (item) item = find_stringpair(item, name, length); - if (item == NULL) + if (!item) return FALSE; delete_stringpair(&substpair, item); adjustindex(*name); diff --git a/legacy/embryo/src/lib/embryo_amx.c b/legacy/embryo/src/lib/embryo_amx.c index e03083a154..9b21da0be2 100644 --- a/legacy/embryo/src/lib/embryo_amx.c +++ b/legacy/embryo/src/lib/embryo_amx.c @@ -393,7 +393,7 @@ embryo_program_native_call_add(Embryo_Program *ep, const char *name, Embryo_Cell Embryo_Header *hdr; int i, num; - if ((ep == NULL ) || (name == NULL) || (func == NULL)) return; + if ((!ep ) || (!name) || (!func)) return; if (strlen(name) > sNAMEMAX) return; hdr = (Embryo_Header *)ep->code; diff --git a/legacy/embryo/src/lib/embryo_str.c b/legacy/embryo/src/lib/embryo_str.c index f02202194d..cd3b942010 100644 --- a/legacy/embryo/src/lib/embryo_str.c +++ b/legacy/embryo/src/lib/embryo_str.c @@ -425,7 +425,7 @@ _embryo_str_strstr(Embryo_Program *ep, Embryo_Cell *params) STRGET(ep, s2, params[2]); if ((!s1) || (!s2)) return -1; p = strstr(s1, s2); - if (p == NULL) return -1; + if (!p) return -1; return (Embryo_Cell)(p - s1); } @@ -440,7 +440,7 @@ _embryo_str_strchr(Embryo_Program *ep, Embryo_Cell *params) STRGET(ep, s1, params[1]); STRGET(ep, s2, params[2]); p = strchr(s1, s2[0]); - if (p == NULL) return -1; + if (!p) return -1; return (Embryo_Cell)(p - s1); } @@ -455,7 +455,7 @@ _embryo_str_strrchr(Embryo_Program *ep, Embryo_Cell *params) STRGET(ep, s1, params[1]); STRGET(ep, s2, params[2]); p = strrchr(s1, s2[0]); - if (p == NULL) return -1; + if (!p) return -1; return (Embryo_Cell)(p - s1); }