Windows std.c incorrect function prototypes #10934
Labels
bug
Observed behavior contradicts documented or intended behavior
contributor friendly
This issue is limited in scope and/or knowledge of Zig internals.
os-windows
standard library
This issue involves writing Zig code for the standard library.
Milestone
Zig Version
0.10.0-dev.856+e86a89d3f
Steps to Reproduce
When using
std.c
on Windows, there are functions externed using Unix prototypes such asrecvfrom
which causes unexpected behavior because the Windows function prototypes are different. Also, functions likegetdirentries
are present when compiling on Windows even though they are not present on Windows which causes an undefined reference when attempting to use them.For example, the Unix prototype of
recvfrom
is the following:However, on Windows the prototype is this instead:
For reference, this is how it is declared in
std.c
.Because the return types are not the same and the functions are
extern
'd, the below behavior is observed.Expected Behavior
I would expect the above program to output the following error
And I would expect the below code to receive data from the socket and not return an error. As far as I know there shouldn't be anything wrong this example.I would expect the following example to return an error from the function due to the length parameter being larger than the
sockaddr
.Actual Behavior
The first example from above has the following compiler error
and the second example yields the following output
Due to the difference in the return types of
recvfrom
on Windows and Unix platforms, and due to #9971 meaning thatstd.os.recvfrom
callsstd.c.recvfrom
, the return value ofstd.c.recvfrom
is interpreted as anisize
when it is actually ac_int
and causes4294967295
to be returned from the function instead of-1
.Also, callingstd.os.windows.ws2_32.WSAGetLastError()
afterwards indicates that the error that occurred wasWSAEFAULT
which indicates the following:> Bad address.The system detected an invalid pointer address in attempting to use a pointer argument of a call. This error occurs if an application passes an invalid pointer value, or if the length of the buffer is too small. For instance, if the length of an argument, which is a sockaddr structure, is smaller than the sizeof(sockaddr).
I believe this means that there is also an issue with how the socket types are defined on Windows as well.Edit: There actually is a bug in this example,
len
should be@sizeOf(@TypeOf(sockaddr))
, but the above symptoms will show any time a function likestd.c.recvfrom
return-1
to indicate an error.The text was updated successfully, but these errors were encountered: