Fix readlink() return value on Windows.
authorThomas Munro <[email protected]>
Tue, 25 Oct 2022 02:13:52 +0000 (15:13 +1300)
committerThomas Munro <[email protected]>
Tue, 25 Oct 2022 02:13:52 +0000 (15:13 +1300)
Ancient bug noticed while working on a test suite for these functions.

Discussion: https://postgr.es/m/CA%2BhUKG%2BajSQ_8eu2AogTncOnZ5me2D-Cn66iN_-wZnRjLN%2Bicg%40mail.gmail.com

src/port/dirmod.c

index 51c9bded8fb2a749c2ff41da3d6f75524731dcf7..398787360a2b642a4d8dc1f2a60b0b1af317022d 100644 (file)
@@ -359,6 +359,9 @@ pgreadlink(const char *path, char *buf, size_t size)
        return -1;
    }
 
+   /* r includes the null terminator */
+   r -= 1;
+
    /*
     * If the path starts with "\??\", which it will do in most (all?) cases,
     * strip those out.