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

cgen: fix infix expr with number overflow (fix #18905) (#18936)

This commit is contained in:
yuyi
2023-07-23 18:18:22 +08:00
committed by GitHub
parent 15fdfd7bcf
commit e1758bc0c5
7 changed files with 38 additions and 14 deletions

View File

@@ -72,7 +72,7 @@ fn (mut bmp BitMap) format_texture() {
x[i + 1] = g
x[i + 2] = b
// alpha
x[i + 3] = u8(u16(a * data) >> 8)
x[i + 3] = u8(u16(u16(a) * data) >> 8)
} else {
x[i + 0] = b_r
x[i + 1] = b_g

View File

@@ -42,13 +42,13 @@ pub fn (mut tf_skl TTF_render_Sokol) create_text(in_txt string, in_font_size f32
// Formula: (font_size * device dpi) / (72dpi * em_unit)
// scale := ((1.0 * devide_dpi )/ f32(72 * tf_skl.bmp.tf.units_per_em))* font_size
scale := f32(font_size * device_dpi) / f32(72 * tf_skl.bmp.tf.units_per_em)
scale := f32(font_size * device_dpi) / f32(72 * int(tf_skl.bmp.tf.units_per_em))
// dprintln("Scale: $scale")
tf_skl.bmp.scale = scale * scale_reduct
w, h := tf_skl.bmp.get_bbox(in_txt)
tf_skl.bmp.width = int(w)
tf_skl.bmp.height = int((h + 8))
tf_skl.bmp.height = int(h + 8)
sz := tf_skl.bmp.width * tf_skl.bmp.height * tf_skl.bmp.bp
// RAM buffer
@@ -77,7 +77,7 @@ pub fn (mut tf_skl TTF_render_Sokol) create_text_block(in_txt string, in_w int,
font_size := in_font_size //* scale_reduct
// Formula: (font_size * device dpi) / (72dpi * em_unit)
// scale := ((1.0 * devide_dpi )/ f32(72 * tf_skl.bmp.tf.units_per_em))* font_size
scale := f32(font_size * device_dpi) / f32(72 * tf_skl.bmp.tf.units_per_em)
scale := f32(font_size * device_dpi) / f32(72 * int(tf_skl.bmp.tf.units_per_em))
// dprintln("Scale: $scale")
tf_skl.bmp.scale = scale * scale_reduct

View File

@@ -162,17 +162,17 @@ pub fn (mut tf TTF_File) get_horizontal_metrics(glyph_index u16) (int, int) {
mut advance_width := 0
mut left_side_bearing := 0
if glyph_index < tf.num_of_long_hor_metrics {
offset += glyph_index * 4
offset += u32(glyph_index) * 4
tf.pos = offset
advance_width = tf.get_u16()
left_side_bearing = tf.get_i16()
// dprintln("${glyph_index} aw:${advance_width} lsb:${left_side_bearing}")
} else {
// read the last entry of the hMetrics array
tf.pos = offset + (tf.num_of_long_hor_metrics - 1) * 4
tf.pos = offset + u32(tf.num_of_long_hor_metrics - 1) * 4
advance_width = tf.get_u16()
tf.pos = offset + tf.num_of_long_hor_metrics * 4 +
2 * (glyph_index - tf.num_of_long_hor_metrics)
tf.pos = offset + u32(tf.num_of_long_hor_metrics) * 4 +
2 * u32(glyph_index - tf.num_of_long_hor_metrics)
left_side_bearing = tf.get_fword()
}
tf.pos = old_pos
@@ -757,7 +757,7 @@ fn (mut tf TTF_File) read_name_table() {
offset := tf.get_u16()
old_pos := tf.pos
tf.pos = table_offset + string_offset + offset
tf.pos = u32(table_offset) + u32(string_offset) + u32(offset)
mut name := ''
if platform_id == 0 || platform_id == 3 {
@@ -929,7 +929,7 @@ fn (mut tm TrueTypeCmap) map_4(char_code int, mut tf TTF_File) int {
if segment.start_code <= char_code && segment.end_code >= char_code {
mut index := (segment.id_delta + char_code) & 0xffff
if segment.id_range_offset > 0 {
glyph_index_address := segment.id_range_offset +
glyph_index_address := u32(segment.id_range_offset) +
2 * u32(char_code - segment.start_code)
tf.pos = glyph_index_address
index = tf.get_u16()

View File

@@ -179,7 +179,7 @@ fn test_main() {
font_size := 20
device_dpi := 72
scale := f32(font_size * device_dpi) / f32(72 * tf.units_per_em)
scale := f32(font_size * device_dpi) / f32(72 * int(tf.units_per_em))
mut bmp := ttf.BitMap{
tf: &tf