[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
renameatu: fix test failure on MSVC
From: |
Bruno Haible |
Subject: |
renameatu: fix test failure on MSVC |
Date: |
Wed, 03 Jul 2019 02:49:19 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-151-generic; KDE/5.18.0; x86_64; ; ) |
Hi Paul, Eric,
On MSVC I'm seeing these two test failures:
FAIL: test-renameat
===================
c:\testdir-posix-msvc\gltests\test-rename.h:115: assertion 'errno == ENOENT'
failed
FAIL test-renameat.exe (exit status: 127)
FAIL: test-renameatu
====================
c:\testdir-posix-msvc\gltests\test-rename.h:115: assertion 'errno == ENOENT'
failed
FAIL test-renameatu.exe (exit status: 127)
What happens is that renameatu fails with error EISDIR instead of ENOENT.
It happens inside at-func.c. There, the code execute the case 13. Since
file2 = '', it sets file2_alt = 'c:\testdir-posix-msvc\gltests\', which
indeed has the syntax of a directory.
There are two ways to fix this:
(a) In line 229 (case 13), test for file2[0] == '\0'.
(b) Test for file2[0] == '\0' a bit earlier, before the savecwd.
I would prefer (b), because
- The test suite found this bug in case 13, but it is well possible
that similar bugs are also lurking in one of the other cases.
- It is pointless to save the current directory, make a trivial syntactic
check, and restore the current directory afterwards. Syntactic checks
can be done without changing the current directory.
So, here's the proposed fix.
at-func2.c is also used by linkat(), but since both renameat() and linkat()
require the error ENOENT if file1 is empty or file2 is empty:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html
https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
the change will not cause a bug.
2019-07-02 Bruno Haible <address@hidden>
renameatu: Fix test failure on MSVC.
* lib/at-func2.c (at_func2): Fail with ENOENT if file1 or file2 is the
empty string.
diff --git a/lib/at-func2.c b/lib/at-func2.c
index eaa256c..bb8792f 100644
--- a/lib/at-func2.c
+++ b/lib/at-func2.c
@@ -176,6 +176,13 @@ at_func2 (int fd1, char const *file1,
return func (file1, file2); /* Reduced to case 5. */
}
+ /* Catch invalid arguments before changing directories. */
+ if (file1[0] == '\0' || file2[0] == '\0')
+ {
+ errno = ENOENT;
+ return -1;
+ }
+
/* Cases 3, 7, 12, 13, 15a, 15b remain. With all reductions in
place, it is time to start changing directories. */
- renameatu: fix test failure on MSVC,
Bruno Haible <=