Skip to content

Fix ENet Buffer data/length ordering issue - #7070

Open
raymcveety wants to merge 1 commit into
odin-lang:masterfrom
raymcveety:enet_win32_buffer_order_fix
Open

Fix ENet Buffer data/length ordering issue#7070
raymcveety wants to merge 1 commit into
odin-lang:masterfrom
raymcveety:enet_win32_buffer_order_fix

Conversation

@raymcveety

@raymcveety raymcveety commented Jul 17, 2026

Copy link
Copy Markdown

Our team discovered this issue when we were trying to send a UDP broadcast packet using enet_socket_send().

On Linux, the broadcast works as expected, but on Windows the function returns -1.
Calling WSAGetLastError() returns a code of WSAEFAULT indicating an error with the pointer parameters.

This lead us to inspect the parameters accepted by enet.socket_send and how they were subsequently transformed/translated into the parameters for WSASendTo where we noticed the ENetBuffer passed in "buffers" as LPWSABUF

Here's essentially what we were passing to socket_send for the buffer:

b := enet.Buffer {
    data = raw_data(bytes),
    dataLength = len(bytes)
}

bytes_sent := enet.socket_send(network.broadcast_sender, &addr, &b, 1)
// below we report error 

Currently enet.Buffer is defined in win32.odin with the order (data first):

Buffer :: struct {
	data:       rawptr,
	dataLength: uint,
}

But LPWSABUF (which is a long pointer to WSABUF) expects the opposite ordering of the data and length (length first):

typedef struct _WSABUF {
  ULONG len;
  CHAR  *buf;
} WSABUF, *LPWSABUF;

So the crash was due to the length being interpreted as the data/data being interpreted as length.

The fix is simple (and we verified locally it eliminates the WSAEFAULT) which is to reverse the order of the members of the Buffer struct in win32.odin

Buffer :: struct {
	dataLength: uint,
	data:       rawptr,
}

We verified the forked compiler builds with these changes, our project builds on the forked compiler, and the WSAEFAULT no longer occurs when we call enet.socket_send using the enet.Buffer struct.

Comment thread vendor/ENet/win32.odin
Comment on lines 62 to +64
Buffer :: struct {
data: rawptr,
dataLength: uint,
data: rawptr,

@raymcveety raymcveety Jul 17, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ultimately passed in as LPWSABUF which is expected to be length first

@raymcveety
raymcveety marked this pull request as ready for review July 17, 2026 05:46
@odin-lang odin-lang deleted a comment Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant