{"thread":{"id":"25825","subject":"[PATCH] mingw: do not set errno to 0 on success","startedAt":"2010-11-23T19:53:08Z","lastAt":"2010-11-24T09:54:03Z","messageCount":3,"participants":["Erik Faye-Lund","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"156439","messageId":"1290541988-4608-1-git-send-email-kusmabite@gmail.com","threadId":"25825","inReplyTo":null,"subject":"[PATCH] mingw: do not set errno to 0 on success","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T19:53:08Z","receivedAt":"2010-11-23T19:53:08Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Currently do_lstat always sets errno to 0 on success. This incorrectly\noverwrites previous errors.\n\nFetch the error-code into a temporary variable instead, and assign that\nto errno on failure.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n\nA bug I found while hunting down another regression. maint-worthy, perhaps?\n\n compat/mingw.c |    4 +++-\n 1 files changed, 3 insertions(+), 1 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex f2d9e1f..b98e600 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -195,9 +195,10 @@ static inline time_t filetime_to_time_t(const FILETIME *ft)\n  */\n static int do_lstat(const char *file_name, struct stat *buf)\n {\n+\tint err;\n \tWIN32_FILE_ATTRIBUTE_DATA fdata;\n \n-\tif (!(errno = get_file_attr(file_name, &fdata))) {\n+\tif (!(err = get_file_attr(file_name, &fdata))) {\n \t\tbuf->st_ino = 0;\n \t\tbuf->st_gid = 0;\n \t\tbuf->st_uid = 0;\n@@ -211,6 +212,7 @@ static int do_lstat(const char *file_name, struct stat *buf)\n \t\tbuf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));\n \t\treturn 0;\n \t}\n+\terrno = err;\n \treturn -1;\n }\n \n-- \n1.7.3.2\n"},{"id":"156458","messageId":"7v4ob7vb1m.fsf@alter.siamese.dyndns.org","threadId":"25825","inReplyTo":"1290541988-4608-1-git-send-email-kusmabite@gmail.com","subject":"Re: [PATCH] mingw: do not set errno to 0 on success","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-24T00:07:49Z","receivedAt":"2010-11-24T00:07:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Erik Faye-Lund <kusmabite@gmail.com> writes:\n\n> Currently do_lstat always sets errno to 0 on success. This incorrectly\n> overwrites previous errors.\n>\n> Fetch the error-code into a temporary variable instead, and assign that\n> to errno on failure.\n>\n> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n> ---\n>\n> A bug I found while hunting down another regression. maint-worthy, perhaps?\n\nI would say so, as long as the error return from get_file_attr() is\ntrustworthy.\n\n>\n>  compat/mingw.c |    4 +++-\n>  1 files changed, 3 insertions(+), 1 deletions(-)\n>\n> diff --git a/compat/mingw.c b/compat/mingw.c\n> index f2d9e1f..b98e600 100644\n> --- a/compat/mingw.c\n> +++ b/compat/mingw.c\n> @@ -195,9 +195,10 @@ static inline time_t filetime_to_time_t(const FILETIME *ft)\n>   */\n>  static int do_lstat(const char *file_name, struct stat *buf)\n>  {\n> +\tint err;\n>  \tWIN32_FILE_ATTRIBUTE_DATA fdata;\n>  \n> -\tif (!(errno = get_file_attr(file_name, &fdata))) {\n> +\tif (!(err = get_file_attr(file_name, &fdata))) {\n>  \t\tbuf->st_ino = 0;\n>  \t\tbuf->st_gid = 0;\n>  \t\tbuf->st_uid = 0;\n> @@ -211,6 +212,7 @@ static int do_lstat(const char *file_name, struct stat *buf)\n>  \t\tbuf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));\n>  \t\treturn 0;\n>  \t}\n> +\terrno = err;\n>  \treturn -1;\n>  }\n>  \n> -- \n> 1.7.3.2\n"},{"id":"156476","messageId":"AANLkTi=8OnTJHgX3-g9uqLX2B3+eUQf0uykynrwW3L4E@mail.gmail.com","threadId":"25825","inReplyTo":"7v4ob7vb1m.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] mingw: do not set errno to 0 on success","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-24T09:54:03Z","receivedAt":"2010-11-24T09:54:03Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Wed, Nov 24, 2010 at 1:07 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Erik Faye-Lund <kusmabite@gmail.com> writes:\n>\n>> Currently do_lstat always sets errno to 0 on success. This incorrectly\n>> overwrites previous errors.\n>>\n>> Fetch the error-code into a temporary variable instead, and assign that\n>> to errno on failure.\n>>\n>> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n>> ---\n>>\n>> A bug I found while hunting down another regression. maint-worthy, perhaps?\n>\n> I would say so, as long as the error return from get_file_attr() is\n> trustworthy.\n\nIt looks trustworthy to me; it returns 0 if GetFileAttributesExA\nsucceeds, and either EACCES, ENAMETOOLONG, ENOMEM or ENOENT based on\nthe result of GetLastError().\n"}]}