Skip to content

Commit

Permalink
Merge pull request #1 from Coeur/coeur/set_version_and_type
Browse files Browse the repository at this point in the history
Fix set_version "The left operand of '&' is a garbage value"
  • Loading branch information
mikedld committed Oct 12, 2022
2 parents 1c68290 + b89d7a8 commit bf695bd
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions utp_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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 @@ -773,8 +774,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 @@ -848,8 +848,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 @@ -1073,8 +1072,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 @@ -2783,8 +2781,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

0 comments on commit bf695bd

Please sign in to comment.