]> granicus.if.org Git - graphviz/commitdiff
smyrna: squash -Wconversion warnings related to grid column count
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 5 Nov 2022 02:44:59 +0000 (19:44 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 10 Nov 2022 03:50:53 +0000 (19:50 -0800)
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

index 92d6ae1bac04737eb862a0ddbb2a0eecb7716959..3e90d8a6d6976e55613f798efa9f972165699a5d 100644 (file)
@@ -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;