diff --git a/kitty/decorations.c b/kitty/decorations.c index d48c43009..3efda1ef5 100644 --- a/kitty/decorations.c +++ b/kitty/decorations.c @@ -235,7 +235,7 @@ typedef struct Canvas { } Canvas; static void -fill_canvas(Canvas *self, int byte) { memset(self->mask, byte, self->width * self->height * sizeof(self->mask[0])); } +fill_canvas(Canvas *self, int byte) { memset(self->mask, byte, sizeof(self->mask[0]) * self->width * self->height); } static void append_hole(Canvas *self, Range hole) { @@ -1581,7 +1581,7 @@ START_ALLOW_CASE_RANGE SH(L'🮖', .xnum=4, .ynum=4, .invert=true); SH(L'🮗', .xnum=1, .ynum=4, .invert=true); #define M(ch, corner) SB(ch, corner_triangle(c, corner)); \ - memcpy(ss.mask, canvas.mask, canvas.width * canvas.height * sizeof(canvas.mask[0])); \ + memcpy(ss.mask, canvas.mask, sizeof(canvas.mask[0]) * canvas.width * canvas.height); \ fill_canvas(&canvas, 0); shade(&canvas, (Shade){.xnum=12}); \ apply_mask(&canvas, ss.mask); break; M(L'🮜', TOP_LEFT); diff --git a/kitty/fonts.c b/kitty/fonts.c index 094594abd..e2e5a420f 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -135,7 +135,7 @@ static void display_rgba_data(const pixel *b, unsigned width, unsigned height) { RAII_PyObject(m, PyImport_ImportModule("kitty.fonts.render")); RAII_PyObject(f, PyObject_GetAttrString(m, "show")); - RAII_PyObject(data, PyMemoryView_FromMemory((char*)b, width * height * sizeof(b[0]), PyBUF_READ)); + RAII_PyObject(data, PyMemoryView_FromMemory((char*)b, (Py_ssize_t)width * height * sizeof(b[0]), PyBUF_READ)); RAII_PyObject(ret, PyObject_CallFunction(f, "OII", data, width, height)); if (ret == NULL) PyErr_Print(); } @@ -154,7 +154,7 @@ python_send_to_gpu(FontGroup *fg, sprite_index idx, pixel *buf) { if (0) dump_sprite(buf, fg->fcm.cell_width, fg->fcm.cell_height); unsigned int x, y, z; sprite_index_to_pos(idx, fg->sprite_tracker.xnum, fg->sprite_tracker.ynum, &x, &y, &z); - const size_t sprite_size = fg->fcm.cell_width * fg->fcm.cell_height; + const size_t sprite_size = (size_t)fg->fcm.cell_width * fg->fcm.cell_height; PyObject *ret = PyObject_CallFunction(python_send_to_gpu_impl, "IIIy#", x, y, z, buf, sprite_size * sizeof(buf[0])); if (ret == NULL) PyErr_Print(); else Py_DECREF(ret); @@ -834,8 +834,8 @@ effective_scale(RunFont rf) { static float scaled_cell_dimensions(RunFont rf, unsigned *width, unsigned *height) { float frac = effective_scale(rf); - *width = (unsigned)ceil(frac * *width); - *height = (unsigned)ceil(frac * *height); + *width = (unsigned)ceilf(frac * *width); + *height = (unsigned)ceilf(frac * *height); return frac; } @@ -956,7 +956,7 @@ map_scaled_decoration_geometry(DecorationGeometry sdg, Region src, Region dest) static void render_scaled_decoration(FontCellMetrics unscaled_metrics, FontCellMetrics scaled_metrics, uint8_t *alpha_mask, pixel *output, Region src, Region dest) { - memset(output, 0, unscaled_metrics.cell_width * (unscaled_metrics.cell_height + 1) * sizeof(output[0])); + memset(output, 0, sizeof(output[0]) * unscaled_metrics.cell_width * (unscaled_metrics.cell_height + 1)); unsigned src_limit = MIN(scaled_metrics.cell_height, src.bottom), dest_limit = MIN(unscaled_metrics.cell_height, dest.bottom); unsigned cell_width = MIN(scaled_metrics.cell_width, unscaled_metrics.cell_width); for (unsigned srcy = src.top, desty=dest.top; srcy < src_limit && desty < dest_limit; srcy++, desty++) { @@ -972,13 +972,13 @@ render_decorations(FontGroup *fg, Region src, Region dest, FontCellMetrics scale if ((src.bottom == src.top) || (dest.bottom == dest.top)) return 0; // no overlap const FontCellMetrics unscaled_metrics = fg->fcm; scaled_metrics.cell_width = unscaled_metrics.cell_width; - RAII_ALLOC(uint8_t, alpha_mask, malloc(scaled_metrics.cell_height * scaled_metrics.cell_width)); - RAII_ALLOC(pixel, buf, malloc(unscaled_metrics.cell_width * (unscaled_metrics.cell_height + 1) * sizeof(pixel))); + RAII_ALLOC(uint8_t, alpha_mask, malloc((size_t)scaled_metrics.cell_height * scaled_metrics.cell_width)); + RAII_ALLOC(pixel, buf, malloc(sizeof(pixel) * unscaled_metrics.cell_width * (unscaled_metrics.cell_height + 1))); if (!alpha_mask || !buf) fatal("Out of memory"); sprite_index ans = 0; bool is_underline = false; uint32_t underline_top = unscaled_metrics.cell_height, underline_bottom = 0; #define do_one(call) { \ - memset(alpha_mask, 0, scaled_metrics.cell_width * scaled_metrics.cell_height * sizeof(alpha_mask[0])); \ + memset(alpha_mask, 0, sizeof(alpha_mask[0]) * scaled_metrics.cell_width * scaled_metrics.cell_height); \ DecorationGeometry sdg = call; \ render_scaled_decoration(unscaled_metrics, scaled_metrics, alpha_mask, buf, src, dest); \ sprite_index q = current_send_sprite_to_gpu(fg, buf, (DecorationMetadata){0}, scaled_metrics); \ @@ -1119,11 +1119,11 @@ load_hb_buffer(CPUCell *first_cpu_cell, GPUCell *first_gpu_cell, index_type num_ static void render_filled_sprite(pixel *buf, unsigned num_glyphs, FontCellMetrics scaled_metrics, unsigned num_scaled_cells) { if (num_scaled_cells > num_glyphs) { - memset(buf, 0xff, num_glyphs * scaled_metrics.cell_width * sizeof(buf[0])); - memset(buf + num_glyphs * scaled_metrics.cell_width, 0, (num_scaled_cells - num_glyphs) * scaled_metrics.cell_width * sizeof(buf[0])); + memset(buf, 0xff, sizeof(buf[0]) * num_glyphs * scaled_metrics.cell_width); + memset(buf + num_glyphs * scaled_metrics.cell_width, 0, sizeof(buf[0]) * (num_scaled_cells - num_glyphs) * scaled_metrics.cell_width); for (unsigned y = 1; y < scaled_metrics.cell_height; y++) memcpy( - buf + scaled_metrics.cell_width * num_scaled_cells * y, buf, scaled_metrics.cell_width * num_scaled_cells * sizeof(buf[0])); - } else memset(buf, 0xff, num_glyphs * scaled_metrics.cell_height * scaled_metrics.cell_width * sizeof(buf[0])); + buf + scaled_metrics.cell_width * num_scaled_cells * y, buf, sizeof(buf[0]) * scaled_metrics.cell_width * num_scaled_cells ); + } else memset(buf, 0xff, sizeof(buf[0]) * num_glyphs * scaled_metrics.cell_height * scaled_metrics.cell_width ); } static void diff --git a/kitty/freetype.c b/kitty/freetype.c index 5d8c62b22..3dd9ca5e1 100644 --- a/kitty/freetype.c +++ b/kitty/freetype.c @@ -718,15 +718,17 @@ get_variation_as_string(Face *self) { if ((err = FT_Get_Var_Design_Coordinates(self->face, mm->num_axis, coords))) return NULL; RAII_ALLOC(char, buf, NULL); uint8_t tag[5]; - size_t pos = 0, sz = 0; + size_t pos = 0, sz = 0, n, bufsz; for (FT_UInt i = 0; i < mm->num_axis; i++) { double val = coords[i] / 65536.0; tag_to_string(mm->axis[i].tag, tag); if (sz - pos < 32) { sz += 4096; buf = realloc(buf, sz); if (!buf) return NULL; } - if ((long)val == val) pos += snprintf(buf + pos, sz - pos - 1, "%s=%ld,", tag, (long)val); - else pos += snprintf(buf + pos, sz - pos - 1, "%s=%.4f,", tag, val); + bufsz = sz - pos - 1; + if ((long)val == val) n = snprintf(buf + pos, bufsz, "%s=%ld,", tag, (long)val); + else n = snprintf(buf + pos, bufsz, "%s=%.4f,", tag, val); + if (n < bufsz) pos += n; } char *ans = NULL; if (buf) { diff --git a/kitty/screen.c b/kitty/screen.c index f45b02b1f..216b67e53 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -5285,7 +5285,7 @@ line_edge_colors(Screen *self, PyObject *a UNUSED) { static PyObject* current_selections(Screen *self, PyObject *a UNUSED) { - PyObject *ans = PyBytes_FromStringAndSize(NULL, self->lines * self->columns); + PyObject *ans = PyBytes_FromStringAndSize(NULL, (Py_ssize_t)self->lines * self->columns); if (!ans) return NULL; screen_apply_selection(self, PyBytes_AS_STRING(ans), PyBytes_GET_SIZE(ans)); return ans; diff --git a/kitty/shaders.c b/kitty/shaders.c index 40ba8e9eb..f6c58b567 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -119,7 +119,7 @@ copy_32bit_texture(GLuint old_texture, GLuint new_texture, GLenum texture_type) break; } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - RAII_ALLOC(uint8_t, pixels, malloc(width * height * layers * 4)); + RAII_ALLOC(uint8_t, pixels, malloc((size_t)width * height * layers * 4u)); if (!pixels) fatal("Out of memory"); glGetTexImage(texture_type, 0, format, type, pixels); glBindTexture(texture_type, new_texture); @@ -146,7 +146,7 @@ static void realloc_sprite_decorations_texture_if_needed(FONTS_DATA_HANDLE fg) { #define dm (sm->decorations_map) SpriteMap *sm = (SpriteMap*)fg->sprite_map; - size_t current_capacity = dm.width * dm.height; + size_t current_capacity = (size_t)dm.width * dm.height; if (dm.count < current_capacity && dm.texture_id) return; GLint new_capacity = dm.count + 256; GLint width = new_capacity, height = 1;