checker: add checks for byte casting (#5917)
parent
4b8652755d
commit
d56d622a43
|
@ -252,7 +252,7 @@ pub fn (mut ws Client) write(payload byteptr, payload_len int, code OPCode) int
|
||||||
fbdata := byteptr(frame_buf.data)
|
fbdata := byteptr(frame_buf.data)
|
||||||
masking_key := create_masking_key()
|
masking_key := create_masking_key()
|
||||||
mut header := [`0`].repeat(header_len)
|
mut header := [`0`].repeat(header_len)
|
||||||
header[0] = byte(code) | 0x80
|
header[0] = byte(int(code)) | 0x80
|
||||||
if payload_len <= 125 {
|
if payload_len <= 125 {
|
||||||
header[1] = byte(payload_len | 0x80)
|
header[1] = byte(payload_len | 0x80)
|
||||||
header[2] = masking_key[0]
|
header[2] = masking_key[0]
|
||||||
|
@ -608,7 +608,7 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b
|
||||||
frame_len := header_len + payload.len
|
frame_len := header_len + payload.len
|
||||||
mut control_frame := [`0`].repeat(frame_len)
|
mut control_frame := [`0`].repeat(frame_len)
|
||||||
masking_key := create_masking_key()
|
masking_key := create_masking_key()
|
||||||
control_frame[0] = byte(code | 0x80)
|
control_frame[0] = byte(int(code) | 0x80)
|
||||||
control_frame[1] = byte(payload.len | 0x80)
|
control_frame[1] = byte(payload.len | 0x80)
|
||||||
control_frame[2] = masking_key[0]
|
control_frame[2] = masking_key[0]
|
||||||
control_frame[3] = masking_key[1]
|
control_frame[3] = masking_key[1]
|
||||||
|
|
|
@ -789,7 +789,7 @@ pub:
|
||||||
|
|
||||||
pub struct CastExpr {
|
pub struct CastExpr {
|
||||||
pub:
|
pub:
|
||||||
expr Expr // `buf`
|
expr Expr // `buf` in `string(buf, n)`
|
||||||
arg Expr // `n` in `string(buf, n)`
|
arg Expr // `n` in `string(buf, n)`
|
||||||
typ table.Type // `string` TODO rename to `type_to_cast_to`
|
typ table.Type // `string` TODO rename to `type_to_cast_to`
|
||||||
pos token.Position
|
pos token.Position
|
||||||
|
|
|
@ -2286,6 +2286,11 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
|
||||||
}
|
}
|
||||||
c.error(error_msg, node.pos)
|
c.error(error_msg, node.pos)
|
||||||
}
|
}
|
||||||
|
} else if !node.expr_type.is_int() && node.expr_type != table.voidptr_type &&
|
||||||
|
!node.expr_type.is_ptr() &&
|
||||||
|
to_type_sym.kind == .byte {
|
||||||
|
type_name := c.table.type_to_str(node.expr_type)
|
||||||
|
c.error('cannot cast type `$type_name` to `byte`', node.pos)
|
||||||
}
|
}
|
||||||
if node.has_arg {
|
if node.has_arg {
|
||||||
c.expr(node.arg)
|
c.expr(node.arg)
|
||||||
|
|
Loading…
Reference in New Issue