mc/lib/widget
Andreas Mohr 053108afd2 (widget_focus): fix -Wanalyzer-deref-before-check warning
widget-common.c: In function 'widget_focus':
widget-common.c:123:12: error: check of '*g.current' for NULL after already dereferencing it []8;;https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Static-Analyzer-Options.html#index-Wanalyzer-deref-before-check-Werror=analyzer-deref-before-check]8;;]
  123 |         if (g->current == NULL || !widget_get_state (WIDGET (g->current->data), WST_FOCUSED))
      |            ^
  'widget_focus': event 1
    |
    |  116 |     if (g == NULL)
    |      |        ^
    |      |        |
    |      |        (1) following 'false' branch (when 'g' is non-NULL)...
    |
  'widget_focus': event 2
    |
    |  119 |     if (WIDGET (g->current->data) != w)
    |      |                 ~^~~~~~~~~
    |      |                  |
    |      |                  (2) ...to here
../../lib/widget/widget-common.h:15:31: note: in definition of macro 'WIDGET'
    |   15 | #define WIDGET(x) ((Widget *)(x))
    |      |                               ^
    |
  'widget_focus': event 3
    |
    |widget-common.c:119:27:
    |  119 |     if (WIDGET (g->current->data) != w)
../../lib/widget/widget-common.h:15:31: note: in definition of macro 'WIDGET'
    |   15 | #define WIDGET(x) ((Widget *)(x))
    |      |                               ^
    |
  'widget_focus': events 4-6
    |
    |widget-common.c:119:8:
    |  119 |     if (WIDGET (g->current->data) != w)
    |      |        ^
    |      |        |
    |      |        (4) following 'true' branch...
    |  120 |     {
    |  121 |         widget_do_focus (WIDGET (g->current->data), FALSE);
    |      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |         |
    |      |         (5) ...to here
    |  122 |         /* Test if focus lost was allowed and focus has really been loose */
    |  123 |         if (g->current == NULL || !widget_get_state (WIDGET (g->current->data), WST_FOCUSED))
    |      |            ~
    |      |            |
    |      |            (6) pointer '*g.current' is checked for NULL here but it was already dereferenced at (3)
    |

Found by gcc-14 analyzer

Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-12-15 14:06:21 +03:00
..
background.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
background.h Create WBackground widget. 2020-03-08 20:17:29 +03:00
button.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
button.h achown: add callback for permission buttons 2017-12-10 09:19:15 +03:00
buttonbar.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
buttonbar.h (buttonbar_find): rename from find_buttonbar. 2023-03-19 20:34:24 +03:00
check.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
check.h (check_set_text): new WCheck API. 2019-12-15 13:02:31 +03:00
dialog-switch.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
dialog-switch.h Ticket #4584: re-implement mocking via weak symbols instead of symbol duplication 2024-10-19 08:56:40 +02:00
dialog.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
dialog.h Move the some stuff from dialog.[ch] to dialog-switch.[ch]: 2023-08-04 21:04:54 +03:00
frame.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
frame.h WGroup: support colors. 2020-03-08 20:17:32 +03:00
gauge.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
gauge.h Ticket #2076: make copy/move/delete progress dialog wider. 2013-01-14 16:23:17 +04:00
group.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
group.h Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
groupbox.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
groupbox.h lib/widget/*.[ch]: fix indentation. 2012-11-20 13:27:10 +04:00
history.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
history.h Fix various typos in the source code (closes MidnightCommander/mc#177). 2023-01-28 21:38:05 +03:00
hline.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
hline.h (hline_set_textv): new API. 2020-05-17 18:48:19 +03:00
input_complete.c Ticket #4584: re-implement mocking via weak symbols instead of symbol duplication 2024-10-19 08:56:40 +02:00
input.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
input.h Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
label.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
label.h Clarify __attribute ((format (printf))) usage. 2015-11-05 14:33:20 +03:00
listbox-window.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
listbox-window.h Listbox window: rename functions. 2023-03-19 20:34:24 +03:00
listbox.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
listbox.h (listbox_add_item_take): new WListbox API. 2024-06-02 12:41:34 +03:00
Makefile.am Input complete: refactoring. 2020-05-17 18:48:19 +03:00
menu.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
menu.h Menu: renames: 2023-08-04 21:04:54 +03:00
mouse.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
mouse.h WGroup: support mouse events. 2020-03-08 20:17:32 +03:00
quick.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
quick.h Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
radio.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
radio.h Ticket #212: implement keybindings for radiobuttons. 2020-05-17 18:48:18 +03:00
rect.c Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
rect.h (rect_grow): new API. 2022-06-05 11:50:19 +03:00
widget-common.c (widget_focus): fix -Wanalyzer-deref-before-check warning 2024-12-15 14:06:21 +03:00
widget-common.h Indentation using GNU indent-2.2.13. 2024-06-02 12:49:13 +03:00
wtools.c Join create_message() and do_create_message(). 2024-12-15 14:06:21 +03:00
wtools.h Ticket #4584: re-implement mocking via weak symbols instead of symbol duplication 2024-10-19 08:56:40 +02:00