Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix set_version "The left operand of '&' is a garbage value" #1

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions utp_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ struct PACKED_ATTRIBUTE PacketFormatV1 {
byte ver_type;
byte version() const { return ver_type & 0xf; }
byte type() const { return ver_type >> 4; }
void set_version_and_type(byte v, byte t) { ver_type = (v & 0xf) | (t << 4); }
void set_version(byte v) { ver_type = (ver_type & 0xf0) | (v & 0xf); }
void set_type(byte t) { ver_type = (ver_type & 0xf) | (t << 4); }

Expand Down Expand Up @@ -765,8 +766,7 @@ void UTPSocket::send_ack(bool synack)

size_t len;
last_rcv_win = get_rcv_window();
pfa.pf.set_version(1);
pfa.pf.set_type(ST_STATE);
pfa.pf.set_version_and_type(1, ST_STATE);
pfa.pf.ext = 0;
pfa.pf.connid = conn_id_send;
pfa.pf.ack_nr = ack_nr;
Expand Down Expand Up @@ -840,8 +840,7 @@ void UTPSocket::send_rst(utp_context *ctx,
zeromem(&pf1);

size_t len;
pf1.set_version(1);
pf1.set_type(ST_RESET);
pf1.set_version_and_type(1, ST_RESET);
pf1.ext = 0;
pf1.connid = conn_id_send;
pf1.ack_nr = ack_nr;
Expand Down Expand Up @@ -1065,8 +1064,7 @@ void UTPSocket::write_outgoing_packet(size_t payload, uint flags, struct utp_iov
last_rcv_win = get_rcv_window();

PacketFormatV1* p1 = (PacketFormatV1*)pkt->data;
p1->set_version(1);
p1->set_type(flags);
p1->set_version_and_type(1, flags);
p1->ext = 0;
p1->connid = conn_id_send;
p1->windowsize = (uint32)last_rcv_win;
Expand Down Expand Up @@ -2774,8 +2772,7 @@ int utp_connect(utp_socket *conn, const struct sockaddr *to, socklen_t tolen)
memset(p1, 0, header_size);
// SYN packets are special, and have the receive ID in the connid field,
// instead of conn_id_send.
p1->set_version(1);
p1->set_type(ST_SYN);
p1->set_version_and_type(1, ST_SYN);
p1->ext = 0;
p1->connid = conn->conn_id_recv;
p1->windowsize = (uint32)conn->last_rcv_win;
Expand Down