v2-0004-Fix-readlink-return-value-on-Windows.patch

text/x-patch

Filename: v2-0004-Fix-readlink-return-value-on-Windows.patch
Type: text/x-patch
Part: 3
Message: Re: Understanding, testing and improving our Windows filesystem code

Patch

Format: format-patch
Series: patch v2-0004
Subject: Fix readlink() return value on Windows.
File+
src/port/dirmod.c 3 0
From 3919ab16b5630498d88f5a16d152c1b3ba235377 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Wed, 12 Oct 2022 17:22:53 +1300
Subject: [PATCH v2 04/10] Fix readlink() return value on Windows.

It accidentally returned a value that counted the trailing nul
terminator.

This is an ancient bug, but it's benign.
---
 src/port/dirmod.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/port/dirmod.c b/src/port/dirmod.c
index 51c9bded8f..5881024929 100644
--- a/src/port/dirmod.c
+++ b/src/port/dirmod.c
@@ -359,6 +359,9 @@ pgreadlink(const char *path, char *buf, size_t size)
 		return -1;
 	}
 
+	/* r includes the nul terminator */
+	r -= 1;
+
 	/*
 	 * If the path starts with "\??\", which it will do in most (all?) cases,
 	 * strip those out.
-- 
2.35.1