From 89751336d289308136df90587fdbb8c74f10cb27 Mon Sep 17 00:00:00 2001 From: Lorenzo Cogotti Date: Mon, 12 Dec 2022 19:46:30 +0100 Subject: [PATCH] [osx] Properly handle 0 length on Windows implementation of flocking(). --- osx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osx.c b/osx.c index 40035f6..9b1e16d 100644 --- a/osx.c +++ b/osx.c @@ -93,6 +93,10 @@ static int flocking(FILE *fh, int mode, __int64 ofs, __int64 len) len = _filelengthi64(_fileno(fh)); if (len < 0) goto fail; + + len -= ofs; + if (len < 0) + len = 0; if (len > LONG_MAX) { errno = ERANGE; goto fail;