mingw: do not set errno to 0 on success
PATCH 1/1 mingw: do not set errno to 0 on success
Currently do_lstat always sets errno to 0 on success. This incorrectly overwrites previous errors.
Fetch the error-code into a temporary variable instead, and assign that to errno on failure.
---
A bug I found while hunting down another regression. maint-worthy, perhaps?
compat/mingw.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
compat/mingw.c +3 -1
@@ -195,9 +195,10 @@ static inline time_t filetime_to_time_t(const FILETIME *ft)*/ static int do_lstat (const char *file_name,struct stat *buf) { +int err;WIN32_FILE_ATTRIBUTE_DATA fdata; -if (!(errno =get_file_attr (file_name, &fdata))) { +if (!(err =get_file_attr (file_name, &fdata))) { buf->st_ino =0 ; buf->st_gid =0 ; buf->st_uid =0 ;
@@ -211,6 +212,7 @@ static int do_lstat(const char *file_name, struct stat *buf) buf->st_ctime =filetime_to_time_t (&(fdata.ftCreationTime));return 0 ; } + errno = err;return -1 ; }
Signature · 1 line
1.7.3.2
Quoted 10 lines · Erik Faye-Lund
Currently
do_lstatalways sets errno to 0 on success. This incorrectly overwrites previous errors.Fetch the error-code into a temporary variable instead, and assign that to errno on failure.
Signed-off-by Erik Faye-Lund <[email protected]>---
A bug I found while hunting down another regression. maint-worthy, perhaps?
I would say so, as long as the error return from get_file_attr() is trustworthy.
Quoted 30 lines
compat/mingw.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)compat/mingw.c +3
-1@@ -195,9 +195,10 @@ static inline time_t filetime_to_time_t(const FILETIME *ft)*/ static int do_lstat (const char *file_name,struct stat *buf) { +int err;WIN32_FILE_ATTRIBUTE_DATA fdata; -if (!(errno =get_file_attr (file_name, &fdata))) { +if (!(err =get_file_attr (file_name, &fdata))) { buf->st_ino =0 ; buf->st_gid =0 ; buf->st_uid =0 ;@@ -211,6 +212,7 @@ static int do_lstat(const char *file_name, struct stat *buf) buf->st_ctime =filetime_to_time_t (&(fdata.ftCreationTime));return 0 ; } + errno = err;return -1 ; }Signature · 1 line
1.7.3.2
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Erik Faye-Lund
Currently
do_lstatalways sets errno to 0 on success. This incorrectly overwrites previous errors.Fetch the error-code into a temporary variable instead, and assign that to errno on failure.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Erik Faye-Lund <[email protected]>---
A bug I found while hunting down another regression. maint-worthy, perhaps?
I would say so, as long as the error return from
get_file_attr()is trustworthy.
It looks trustworthy to me; it returns 0 if GetFileAttributesExA succeeds, and either EACCES, ENAMETOOLONG, ENOMEM or ENOENT based on the result of GetLastError().