Skip to content

Commit 71988d6

Browse files
committed
Io.net: set receive{,Timeout} message to init
If we use `undefined`, then `netReceive` can `@intCast` the control slice len to msghdr controllen, which is sometimes `u32`, even on 64-bit platforms. `init` just avoids this entirely by setting `control` to an empty slice rather than undefined.
1 parent 654a5b2 commit 71988d6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/std/Io/net.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ pub const Socket = struct {
11181118
/// See also:
11191119
/// * `receiveTimeout`
11201120
pub fn receive(s: *const Socket, io: Io, buffer: []u8) ReceiveError!IncomingMessage {
1121-
var message: IncomingMessage = undefined;
1121+
var message: IncomingMessage = .init;
11221122
const maybe_err, const count = io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, .none);
11231123
if (maybe_err) |err| switch (err) {
11241124
// No timeout is passed to `netReceieve`, so it must not return timeout related errors.
@@ -1144,7 +1144,7 @@ pub const Socket = struct {
11441144
buffer: []u8,
11451145
timeout: Io.Timeout,
11461146
) ReceiveTimeoutError!IncomingMessage {
1147-
var message: IncomingMessage = undefined;
1147+
var message: IncomingMessage = .init;
11481148
const maybe_err, const count = io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, timeout);
11491149
if (maybe_err) |err| return err;
11501150
assert(1 == count);

0 commit comments

Comments
 (0)