Dubious code in pg_rewind's process_target_file() - Mailing list pgsql-hackers

From Tom Lane
Subject Dubious code in pg_rewind's process_target_file()
Date
Msg-id 1221796.1599329320@sss.pgh.pa.us
Whole thread Raw
Responses Re: Dubious code in pg_rewind's process_target_file()
List pgsql-hackers
scan-build complains that "exists = false" is a dead store,
which it is:

process_target_file(const char *path, file_type_t type, size_t oldsize,
                    const char *link_target)
{
    bool        exists;
    ...

    if (lstat(localpath, &statbuf) < 0)
    {
        if (errno != ENOENT)
            pg_fatal("could not stat file \"%s\": %s\n",
                     localpath, strerror(errno));

        exists = false;
    }

    ...
    exists = (bsearch(&key_ptr, map->array, map->narray, sizeof(file_entry_t *),
                      path_cmp) != NULL);

It looks to me like we could replace "exists = false" with "return",
rather than uselessly constructing a FILE_ACTION_REMOVE entry for
a file we've already proven is not there.  This seems to have been
copy-and-pasted from process_source_file, without much thought for
the fact that the situations are quite different.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Ranier Vilela
Date:
Subject: Re: [PATCH] Redudant initilization
Next
From: Tom Lane
Date:
Subject: Re: Dubious code in pg_rewind's process_target_file()