mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
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.
This commit is contained in:
parent
654a5b20d7
commit
71988d6719
1 changed files with 2 additions and 2 deletions
|
|
@ -1118,7 +1118,7 @@ pub const Socket = struct {
|
|||
/// See also:
|
||||
/// * `receiveTimeout`
|
||||
pub fn receive(s: *const Socket, io: Io, buffer: []u8) ReceiveError!IncomingMessage {
|
||||
var message: IncomingMessage = undefined;
|
||||
var message: IncomingMessage = .init;
|
||||
const maybe_err, const count = io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, .none);
|
||||
if (maybe_err) |err| switch (err) {
|
||||
// No timeout is passed to `netReceieve`, so it must not return timeout related errors.
|
||||
|
|
@ -1144,7 +1144,7 @@ pub const Socket = struct {
|
|||
buffer: []u8,
|
||||
timeout: Io.Timeout,
|
||||
) ReceiveTimeoutError!IncomingMessage {
|
||||
var message: IncomingMessage = undefined;
|
||||
var message: IncomingMessage = .init;
|
||||
const maybe_err, const count = io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, timeout);
|
||||
if (maybe_err) |err| return err;
|
||||
assert(1 == count);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue