read() truncates size_t to 32 bits on 64-bit Cygwin

Brian Inglis Brian.Inglis@SystematicSW.ab.ca
Sat Nov 21 23:45:56 GMT 2026


On 2026-11-20 09:51, Sam Edge via Cygwin wrote:
> On 20/11/2026 08:37, Takashi Yano via Cygwin wrote:
>  > The main cause of this issue is the code around here:
>  > void
>  > fhandler_base::raw_read (void *ptr, size_t& len)
>  > {
>  >   NTSTATUS status;
>  >   IO_STATUS_BLOCK io;
>  >   int try_noreserve = 1;
>  >
>  > retry:
>  >   status = NtReadFile (get_handle (), NULL, NULL, NULL, &io, ptr, len,
>  >                        NULL, NULL);      ^^^
>  >   if (NT_SUCCESS (status))
>  >     len = io.Information;
>  >
>  > The type of the 7th arg. of NtReadFile() is ULONG, which is 32bit.
>  > Perhaps similar issues exist elsewhere as well.
> 
> And here's me thinking WJM applied to Cygwin, not Windows 64-bit APIs! ;-)
> 
> As usual, fast & precise diagnostic folks. Kudos.
> 
> However, I'm surprised this wasn't picked up by static analysis spotting the 
> narrowing.

It may have been and was ignored, as it was unchanged, at least recently.
Now I think we should take this low level discussion to -developers?

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                 -- Antoine de Saint-Exupéry


More information about the Cygwin-developers mailing list