From 1905e1f6accc37e5ca54ba4583c45f5358930997 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Fri, 4 Nov 2022 19:44:59 -0700 Subject: [PATCH] smyrna: squash -Wconversion warnings related to grid column count MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This squashes the following compiler warnings: tvnodes.c: In function ‘update_tree’: tvnodes.c:294:28: warning: conversion to ‘size_t’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Wsign-conversion] 294 | types = gv_calloc(g->count, sizeof(GType)); | ~^~~~~~~ tvnodes.c: In function ‘add_column’: tvnodes.c:312:43: warning: conversion to ‘size_t’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Wsign-conversion] 312 | g->columns = gv_recalloc(g->columns, g->count, g->count + 1, | ~^~~~~~~ tvnodes.c:312:61: warning: conversion to ‘size_t’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Wsign-conversion] 312 | g->columns = gv_recalloc(g->columns, g->count, g->count + 1, | ~~~~~~~~~^~~ `count` is known non-negative all the time, but cannot be easily converted to a `size_t` because we need to interact with the GTK APIs that take `int` values. --- cmd/smyrna/tvnodes.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/smyrna/tvnodes.c b/cmd/smyrna/tvnodes.c index 92d6ae1ba..3e90d8a6d 100644 --- a/cmd/smyrna/tvnodes.c +++ b/cmd/smyrna/tvnodes.c @@ -291,7 +291,7 @@ static GtkTreeView *update_tree(GtkTreeView * tree, grid * g) } if (g->count > 0) { - types = gv_calloc(g->count, sizeof(GType)); + types = gv_calloc((size_t)g->count, sizeof(GType)); for (id = 0; id < g->count; id++) types[id] = g->columns[id]->type; store = update_tree_store(g->store, g->count, types); @@ -309,7 +309,8 @@ static void add_column(grid * g, char *name, bool editable, GType g_type) { if (*name == '\0') return; - g->columns = gv_recalloc(g->columns, g->count, g->count + 1, + assert(g->count >= 0); + g->columns = gv_recalloc(g->columns, (size_t)g->count, (size_t)g->count + 1, sizeof(gridCol*)); g->columns[g->count] = gv_alloc(sizeof(gridCol)); g->columns[g->count]->editable = editable; -- 2.40.0