public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: raw disk I/O: Fix return value in error case
Date: Fri, 24 Apr 2020 14:23:35 +0000 (GMT)	[thread overview]
Message-ID: <20200424142335.7CD1238930F7@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b8349218955ffbb2b573a2de8efac61a800f4eb0

commit b8349218955ffbb2b573a2de8efac61a800f4eb0
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Apr 24 16:19:09 2020 +0200

    Cygwin: raw disk I/O: Fix return value in error case
    
    The cast to generate the return value uses a DWORD variable
    as test and set value.  The error case is the constant -1.
    Given the type of the other half of the conditioal expression,
    -1 is cast to DWORD as well.
    
    On 64 bit, this results in the error case returning a 32 bit
    -1 value which is equivalent to (ssize_t) 4294967295 rather
    than (ssize_t) -1.
    
    Add a fixing cast.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler_floppy.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler_floppy.cc b/winsup/cygwin/fhandler_floppy.cc
index f2e15d703..778d6ef98 100644
--- a/winsup/cygwin/fhandler_floppy.cc
+++ b/winsup/cygwin/fhandler_floppy.cc
@@ -619,12 +619,12 @@ fhandler_dev_floppy::raw_write (const void *ptr, size_t len)
 	      devbufend = bytes_per_sector;
 	    }
 	}
-      return bytes_written;
+      return (ssize_t) bytes_written;
     }
 
   /* In O_DIRECT case, just write. */
   if (write_file (p, len, &bytes_written, &ret))
-    return bytes_written;
+    return (ssize_t) bytes_written;
 
 err:
   if (IS_EOM (ret))
@@ -635,7 +635,8 @@ err:
     }
   else if (!bytes_written)
     __seterrno ();
-  return bytes_written ?: -1;
+  /* Cast is required, otherwise the error return value is (DWORD)-1. */
+  return (ssize_t) bytes_written ?: -1;
 }
 
 off_t


                 reply	other threads:[~2020-04-24 14:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200424142335.7CD1238930F7@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).