qulogic/libgnt

Merged in default (pull request #89)

2019-10-09, Gary Kramlich
8e797d173483
Merged in default (pull request #89)

Clean up the remaining pvs-studio findings

Approved-by: Elliott Sales de Andrade
  • +22 -4
    convey.yml
  • +1 -1
    gntentry.c
  • +2 -0
    gntinternal.h
  • +33 -18
    gntmain.c
  • +1 -1
    gntstyle.c
  • +6 -5
    gnttextview.c
  • +0 -4
    gnttree.c
  • +17 -9
    gntwm.c
  • +1 -1
    wms/irssi.c
  • --- a/convey.yml Mon Oct 07 02:32:27 2019 -0400
    +++ b/convey.yml Wed Oct 09 02:38:18 2019 +0000
    @@ -1,7 +1,9 @@
    # vi:et:ts=2 sw=2 sts=2
    environment:
    - GNT_VERSION=latest
    - - DOCS_TAG=libgnt/docs:${GNT_VERSION}
    + - DOCS_REPOSITORY=libgnt/docs
    + - REGISTRY_HOST=docker.io
    + - REPOSITORY=libgnt/builders
    tasks:
    import:
    @@ -21,10 +23,11 @@
    type: convey/clean
    files:
    - build-convey
    + - pvs-studio
    build-docs:
    type: docker/run
    - image: libgnt/builders:debian-buster-amd64
    + image: ${REGISTRY_HOST}/${REPOSITORY}:debian-buster-amd64
    script:
    - set -ex
    - cd ${CONVEY_WORKSPACE}
    @@ -33,12 +36,20 @@
    build-docs-image:
    type: docker/build
    dockerfile: doc/Dockerfile
    - tag: ${DOCS_TAG}
    + tag: ${REGISTRY_HOST}/${DOCS_REPOSITORY}:${GNT_VERSION}
    files:
    - build-convey/doc/html:.
    publish-docs-image:
    type: docker/push
    - image: ${DOCS_TAG}
    + image: ${REGISTRY_HOST}/${DOCS_REPOSITORY}:${GNT_VERSION}
    +
    + build-target:
    + type: docker/run
    + image: ${REGISTRY_HOST}/${REPOSITORY}:${TARGET}
    +
    + export-target:
    + type: docker/export
    + files: ${TARGET}
    plans:
    docs:
    @@ -67,3 +78,10 @@
    stages:
    - tasks: clean
    + pvs-studio:
    + environment: [TARGET=pvs-studio, PVS_STUDIO_KEY, PVS_STUDIO_USERNAME]
    + stages:
    + - tasks: [import, build-target]
    + - tasks: [export-target]
    + run: always
    +
    --- a/gntentry.c Mon Oct 07 02:32:27 2019 -0400
    +++ b/gntentry.c Wed Oct 09 02:38:18 2019 +0000
    @@ -1058,7 +1058,7 @@
    {
    GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
    GntWidgetClass *widget_class = GNT_WIDGET_CLASS(klass);
    - char s[3] = {'\033', erasechar(), 0};
    + char s[3] = {GNT_ESCAPE, erasechar(), 0};
    widget_class->clicked = gnt_entry_clicked;
    widget_class->destroy = gnt_entry_destroy;
    --- a/gntinternal.h Mon Oct 07 02:32:27 2019 -0400
    +++ b/gntinternal.h Wed Oct 09 02:38:18 2019 +0000
    @@ -26,6 +26,8 @@
    #undef G_LOG_DOMAIN
    #define G_LOG_DOMAIN "Gnt"
    +#define GNT_ESCAPE '\033'
    +
    #ifdef __GNUC__
    # ifndef GNT_LOG_DOMAIN
    # define GNT_LOG_DOMAIN ""
    --- a/gntmain.c Mon Oct 07 02:32:27 2019 -0400
    +++ b/gntmain.c Wed Oct 09 02:38:18 2019 +0000
    @@ -93,7 +93,7 @@
    static gboolean refresh_screen(void);
    -static GntWM *wm;
    +static GntWM *wm; // -V707
    static GntClipboard *clipboard;
    int gnt_need_conversation_to_locale;
    @@ -315,7 +315,7 @@
    is_escape = TRUE;
    }
    if (is_escape) {
    - *k = '\033';
    + *k = GNT_ESCAPE;
    k++;
    }
    @@ -328,7 +328,7 @@
    if (ch == 0xE0 || ch == 0xE1) {
    is_special = TRUE;
    if (!is_escape) {
    - *k = '\033';
    + *k = GNT_ESCAPE;
    k++;
    }
    *k = ch;
    @@ -397,7 +397,7 @@
    rd += HOLDING_ESCAPE;
    if (HOLDING_ESCAPE) {
    - keys[0] = '\033';
    + keys[0] = GNT_ESCAPE;
    g_source_remove(escape_stuff.timer);
    escape_stuff.timer = 0;
    }
    @@ -413,7 +413,7 @@
    char back;
    int p;
    - if (k[0] == '\033' && rd == 1) {
    + if (k[0] == GNT_ESCAPE && rd == 1) {
    escape_stuff.timer = g_timeout_add(250, escape_timeout, NULL);
    break;
    }
    @@ -924,24 +924,39 @@
    gnt_wm_get_keypress_mode(wm) == GNT_KP_MODE_WAIT_ON_CHILD);
    }
    +/* to save other's time... this ugly function converts the given string to the
    + * locale if necessary and returns it as a const gchar *. Since it needs to
    + * return a const gchar * there's a bunch of messing around with a static
    + * variable. While this works, this makes this non-thread safe and who knows
    + * what else.
    + */
    const char *C_(const char *x)
    {
    - static char *c = NULL;
    + static gchar *c = NULL;
    +
    + /* clear the old value we had for cm since it's no longer needed */
    + g_free(c);
    +
    if (gnt_need_conversation_to_locale) {
    GError *error = NULL;
    - g_free(c);
    - c = g_locale_from_utf8(x, -1, NULL, NULL, &error);
    - if (c == NULL || error) {
    - char *store = c;
    - c = NULL;
    - gnt_warning("Error: %s\n", error ? error->message : "(unknown)");
    + gchar *newc = NULL;
    +
    + newc = g_locale_from_utf8(x, -1, NULL, NULL, &error);
    + if(error != NULL) {
    + gnt_warning("Error: %s\n", error->message ? error->message : "(unknown)");
    +
    g_error_free(error);
    - error = NULL;
    - g_free(c);
    - c = store;
    +
    + return x;
    }
    - return c ? c : x;
    - } else
    - return x;
    +
    + if(newc != NULL) {
    + c = newc;
    +
    + return c;
    + }
    + }
    +
    + return x;
    }
    --- a/gntstyle.c Mon Oct 07 02:32:27 2019 -0400
    +++ b/gntstyle.c Wed Oct 09 02:38:18 2019 +0000
    @@ -136,7 +136,7 @@
    {
    if (*s == '^' && *(s + 1) == '[')
    {
    - *t = '\033'; /* escape */
    + *t = GNT_ESCAPE;
    s++;
    }
    else if (*s == '\\')
    --- a/gnttextview.c Mon Oct 07 02:32:27 2019 -0400
    +++ b/gnttextview.c Wed Oct 09 02:38:18 2019 +0000
    @@ -161,7 +161,7 @@
    scrcol = width - 1;
    rows = height - 2;
    - if (has_scroll && rows > 0)
    + if (has_scroll && rows > 0 && lines != NULL)
    {
    int total = g_list_length(g_list_first(view->list));
    int showing, position, up, down;
    @@ -174,14 +174,14 @@
    down = total - up;
    position = (rows - showing) * up / MAX(1, up + down);
    - position = MAX((lines != NULL), position);
    + position = MAX(1, position);
    if (showing + position > rows)
    position = rows - showing;
    - if (showing + position == rows && view->list && view->list->prev)
    + if (showing + position == rows && view->list->prev)
    position = MAX(1, rows - 1 - showing);
    - else if (showing + position < rows && view->list && !view->list->prev)
    + else if (showing + position < rows && !view->list->prev)
    position = rows - showing;
    mvwvline(window, position + 1, scrcol,
    @@ -650,7 +650,8 @@
    GList *list = view->list;
    view->list = g_list_prepend(g_list_first(view->list), line);
    - view->list = list;
    + view->list = list; // -V519
    +
    gnt_widget_draw(GNT_WIDGET(view));
    }
    --- a/gnttree.c Mon Oct 07 02:32:27 2019 -0400
    +++ b/gnttree.c Wed Oct 09 02:38:18 2019 +0000
    @@ -946,10 +946,6 @@
    return FALSE;
    }
    - if (old != priv->current) {
    - tree_selection_changed(tree, old, priv->current);
    - }
    -
    return TRUE;
    }
    --- a/gntwm.c Mon Oct 07 02:32:27 2019 -0400
    +++ b/gntwm.c Wed Oct 09 02:38:18 2019 +0000
    @@ -216,7 +216,6 @@
    PANEL *panel = NULL;
    while ((panel = panel_below(panel)) != NULL) {
    int sx, ex, sy, ey, w, y;
    - cchar_t ch;
    PANEL *below = panel;
    sx = getbegx(panel_window(panel));
    @@ -232,6 +231,8 @@
    ex < getbegx(panel_window(below)))
    continue;
    for (y = MAX(sy, getbegy(panel_window(below))); y <= MIN(ey, getbegy(panel_window(below)) + getmaxy(panel_window(below))); y++) {
    + cchar_t ch;
    + memset(&ch, 0, sizeof(ch));
    if (mvwin_wch(panel_window(below), y - getbegy(panel_window(below)), sx - 1 - getbegx(panel_window(below)), &ch) != OK)
    goto right;
    w = widestringwidth(ch.chars);
    @@ -826,6 +827,7 @@
    #else
    cchar_t wch;
    char unicode[12];
    + memset(&wch, 0, sizeof(wch));
    mvwin_wch(curscr, y, x, &wch);
    now = wch.attr;
    ch[0] = (char)(wch.chars[0] & 0xff);
    @@ -1079,15 +1081,21 @@
    static int
    widestringwidth(wchar_t *wide)
    {
    - int len, ret;
    - char *string;
    + gint len;
    + gchar *str;
    len = wcstombs(NULL, wide, 0) + 1;
    - string = g_new0(char, len);
    - wcstombs(string, wide, len);
    - ret = string ? gnt_util_onscreen_width(string, NULL) : 1;
    - g_free(string);
    - return ret;
    + str = g_new0(char, len);
    + if(str != NULL) {
    + gint ret;
    + wcstombs(str, wide, len);
    + ret = gnt_util_onscreen_width(str, NULL);
    + g_free(str);
    +
    + return ret;
    + }
    +
    + return 1;
    }
    #endif
    @@ -2191,7 +2199,7 @@
    gnt_widget_destroy(priv->list.window);
    return TRUE;
    }
    - } else if (keys[0] == '\033' && isdigit(keys[1]) && keys[2] == '\0') {
    + } else if (keys[0] == GNT_ESCAPE && isdigit(keys[1]) && keys[2] == '\0') {
    /* Alt+x for quick switch */
    int n = *(keys + 1) - '0';
    GList *list = NULL;
    --- a/wms/irssi.c Mon Oct 07 02:32:27 2019 -0400
    +++ b/wms/irssi.c Wed Oct 09 02:38:18 2019 +0000
    @@ -161,7 +161,7 @@
    name = gnt_widget_get_name(win);
    if (!name || !strstr(name, "conversation-window")) {
    if (!GNT_IS_MENU(win) && !gnt_widget_get_transient(win)) {
    - if ((!name || strcmp(name, "buddylist"))) {
    + if (!name || strcmp(name, "buddylist")) {
    gnt_widget_get_size(win, &w, &h);
    x = (getmaxx(stdscr) - w) / 2;
    y = (getmaxy(stdscr) - h) / 2;