Fix comparisons of pointers with zero to compare with NULL instead.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 29 Oct 2010 19:51:52 +0000 (15:51 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 29 Oct 2010 19:51:52 +0000 (15:51 -0400)
Per C standard, these are semantically the same thing; but saying NULL
when you mean NULL is good for readability.

Marti Raudsepp, per results of INRIA's Coccinelle.

src/backend/regex/regc_lex.c
src/backend/utils/adt/tsrank.c
src/backend/utils/fmgr/dfmgr.c
src/bin/pg_dump/pg_backup_tar.c
src/port/dirmod.c
src/timezone/zic.c

index da3ff0bf384673aaf1ad74e009256428893406ae..3360cfb0e9fe20f7d5e3e3d016483c8bd6b60e6f 100644 (file)
@@ -846,7 +846,7 @@ lexescape(struct vars * v)
            if (ISERR())
                FAILW(REG_EESCAPE);
            /* ugly heuristic (first test is "exactly 1 digit?") */
-           if (v->now - save == 0 || ((int) c > 0 && (int) c <= v->nsubexp))
+           if (v->now == save || ((int) c > 0 && (int) c <= v->nsubexp))
            {
                NOTE(REG_UBACKREF);
                RETV(BACKREF, (chr) c);
index d61bcdd42661e0aafd79bbce875f4a4a7a08d15b..b0417de1262577ff284a4932b8e114a018206552 100644 (file)
@@ -395,7 +395,7 @@ getWeights(ArrayType *win)
    int         i;
    float4     *arrdata;
 
-   if (win == 0)
+   if (win == NULL)
        return weights;
 
    if (ARR_NDIM(win) != 1)
index 566ac46bd7aa0b6417aabef363bdaff305655995..d08fdddde2f498b9f1352862e65fa3725de0b29a 100644 (file)
@@ -616,7 +616,7 @@ find_in_dynamic_libpath(const char *basename)
                    (errcode(ERRCODE_INVALID_NAME),
                     errmsg("zero-length component in parameter \"dynamic_library_path\"")));
 
-       if (piece == 0)
+       if (piece == NULL)
            len = strlen(p);
        else
            len = piece - p;
index d7e4c463dd89c211fd22b3c865d88bbac2020692..006f7dab72e44af49386bca3fa05de1a1ab655eb 100644 (file)
@@ -576,7 +576,7 @@ tarWrite(const void *buf, size_t len, TAR_MEMBER *th)
 {
    size_t      res;
 
-   if (th->zFH != 0)
+   if (th->zFH != NULL)
        res = GZWRITE((void *) buf, 1, len, th->zFH);
    else
        res = fwrite(buf, 1, len, th->nFH);
index a8b8a904df9e32026c872e3907a21380700b9b0e..7ab3c9a027173ef5788a20f4f06dde136c55b12c 100644 (file)
@@ -246,7 +246,7 @@ pgsymlink(const char *oldpath, const char *newpath)
    else
        strcpy(nativeTarget, oldpath);
 
-   while ((p = strchr(p, '/')) != 0)
+   while ((p = strchr(p, '/')) != NULL)
        *p++ = '\\';
 
    len = strlen(nativeTarget) * sizeof(WCHAR);
index 00ca6faab416ea3b6fb67d5c3ba81cdce263e4e3..8a95d6ac3f7803237bb7f6c2941af574716a1576 100644 (file)
@@ -810,7 +810,7 @@ associate(void)
             * Note, though, that if there's no rule, a '%s' in the format is
             * a bad thing.
             */
-           if (strchr(zp->z_format, '%') != 0)
+           if (strchr(zp->z_format, '%') != NULL)
                error(_("%s in ruleless zone"));
        }
    }
@@ -1111,9 +1111,9 @@ inzsub(char **fields, int nfields, int iscont)
    z.z_filename = filename;
    z.z_linenum = linenum;
    z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid UTC offset"), TRUE);
-   if ((cp = strchr(fields[i_format], '%')) != 0)
+   if ((cp = strchr(fields[i_format], '%')) != NULL)
    {
-       if (*++cp != 's' || strchr(cp, '%') != 0)
+       if (*++cp != 's' || strchr(cp, '%') != NULL)
        {
            error(_("invalid abbreviation format"));
            return FALSE;
@@ -1438,9 +1438,9 @@ rulesub(struct rule * rp, const char *loyearp, const char *hiyearp,
    }
    else
    {
-       if ((ep = strchr(dp, '<')) != 0)
+       if ((ep = strchr(dp, '<')) != NULL)
            rp->r_dycode = DC_DOWLEQ;
-       else if ((ep = strchr(dp, '>')) != 0)
+       else if ((ep = strchr(dp, '>')) != NULL)
            rp->r_dycode = DC_DOWGEQ;
        else
        {
@@ -2826,7 +2826,7 @@ mkdirs(char *argname)
    if (argname == NULL || *argname == '\0')
        return 0;
    cp = name = ecpyalloc(argname);
-   while ((cp = strchr(cp + 1, '/')) != 0)
+   while ((cp = strchr(cp + 1, '/')) != NULL)
    {
        *cp = '\0';
 #ifdef WIN32