1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: restrict numeric promotions to cases where no data is lost

This commit is contained in:
Uwe Krüger
2020-05-27 05:42:48 +02:00
committed by GitHub
parent fc67046bac
commit 013fdb8a4b
81 changed files with 510 additions and 247 deletions

View File

@ -191,8 +191,8 @@ pub fn (mut ws Client) close(code int, message string) {
code_ := C.htons(code)
message_len := message.len + 2
mut close_frame := [`0`].repeat(message_len)
close_frame[0] = code_ & 0xFF
close_frame[1] = (code_ >> 8)
close_frame[0] = byte(code_ & 0xFF)
close_frame[1] = byte(code_ >> 8)
code32 = (close_frame[0] << 8) + close_frame[1]
for i in 0 .. message.len {
close_frame[i + 2] = message[i]
@ -248,9 +248,9 @@ pub fn (mut ws Client) write(payload byteptr, payload_len int, code OPCode) int
fbdata := byteptr( frame_buf.data )
masking_key := create_masking_key()
mut header := [`0`].repeat(header_len)
header[0] = (int(code) | 0x80)
header[0] = byte(code) | 0x80
if payload_len <= 125 {
header[1] = (payload_len | 0x80)
header[1] = byte(payload_len | 0x80)
header[2] = masking_key[0]
header[3] = masking_key[1]
header[4] = masking_key[2]
@ -417,7 +417,7 @@ pub fn (mut ws Client) read() int {
} else if frame.opcode in [.text_frame, .binary_frame] {
data_node:
l.d('read: recieved text_frame or binary_frame')
mut payload := malloc(sizeof(byte) * int(payload_len) + 1)
mut payload := malloc(sizeof(byte) * u32(payload_len) + 1)
if payload == 0 {
l.f('out of memory')
}
@ -437,7 +437,7 @@ pub fn (mut ws Client) read() int {
size += f.len
}
}
mut pl := malloc(sizeof(byte) * int(size))
mut pl := malloc(sizeof(byte) * u32(size))
if pl == 0 {
l.f('out of memory')
}
@ -581,8 +581,8 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b
frame_len := header_len + payload.len
mut control_frame := [`0`].repeat(frame_len)
masking_key := create_masking_key()
control_frame[0] = (int(code) | 0x80)
control_frame[1] = (payload.len | 0x80)
control_frame[0] = byte(code | 0x80)
control_frame[1] = byte(payload.len | 0x80)
control_frame[2] = masking_key[0]
control_frame[3] = masking_key[1]
control_frame[4] = masking_key[2]