1994 Commits

Author SHA1 Message Date
Andrew Borodin
2893ee212f Add tests for edit_replace_cmd().
* (status_msg_init): add MC_MOCKABLE attribute.
  * (status_msg_deinit): likewise.
  * (edit_search_update_callback): likewise.
  * (edit_dialog_replace_show): add MC_MOCKABLE and make public.
  * (edit_dialog_replace_prompt_show): likewise.
  * (edit_search_options): make public.
  * (B_REPLACE_ALL, B_REPLACE_ONE, B_SKIP_REPLACE): likewise.
  * (macros_list): init explicitly.
  * tests/src/editor/mc.charsets: add ASCII charset.
  * tests/src/editor/edit_replace_cmd.c: new file.
  * tests/src/editor/Makefile.am: add new test.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-02-23 18:52:47 +03:00
Andrew Borodin
18c0c2fabb Ticket #4655: remove PCRE and PCRE2 search engines.
GRegex as PCRE wrapper was introduced in GLib-2.14. PCRE was required
for MC on OSes with GLib < 2.14. Currently MC requires GLib >= 2.32.
Since 2.73.2 (released at 2022-07-08), GRegex is based on PCRE2.

We can remove PCRE and PCRE2 from MC and use GLib only.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-02-22 20:22:07 +03:00
Yury V. Zaytsev
ac9a81d9bd Ticket #4642: extract and re-implement str_chomp to fix buffer overflow, add tests
Found in Alpine/musl on s390x, confirmed on aarch64 using valgrind - introduced
in 65a7278d8a:

{{{
==156518== Invalid read of size 1
==156518==    at 0x413BE0: vfs_parse_ls_lga (parse_ls_vga.c:863)
==156518==    by 0x4076C3: process_ls_line (mc_parse_ls_l.c:350)
==156518==    by 0x4076C3: process_input (mc_parse_ls_l.c:376)
==156518==    by 0x40736B: main (mc_parse_ls_l.c:404)
==156518==  Address 0x536be6f is 1 bytes before a block of size 2 alloc'd
==156518==    at 0x48854F0: malloc (vg_replace_malloc.c:446)
==156518==    by 0x4CF4FCB: g_malloc (gmem.c:100)
==156518==    by 0x4D0E99B: g_strdup (gstrfuncs.c:323)
==156518==    by 0x413887: g_strdup_inline (gstrfuncs.h:321)
==156518==    by 0x413887: vfs_parse_ls_lga (parse_ls_vga.c:848)
==156518==    by 0x4076C3: process_ls_line (mc_parse_ls_l.c:350)
==156518==    by 0x4076C3: process_input (mc_parse_ls_l.c:376)
==156518==    by 0x40736B: main (mc_parse_ls_l.c:404)
}}}

https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/79071

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-02-03 10:54:51 +01:00
Yury V. Zaytsev
8406bddbd4 formatting: step 6 - manual tweaks
* Reformat tests with magic comma
* Remove macro guards causing unstable formatting

```
find . -type file -name '*.[ch]' | xargs sed -i '' -E 's|# *endif.+//.+$|#endif|g'
```

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-02-02 19:38:47 +01:00
Yury V. Zaytsev
c3ff1763f6 formatting: step 4 - reformat all files with make indent
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-02-02 19:38:47 +01:00
Yury V. Zaytsev
f1094c9faa formatting: step 3 - add clang-format configuration
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-02-02 19:38:47 +01:00
Andrew Borodin
8ade31c315 formatting: step 2.3 - use designated initializer for quick_dialog_t structures
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-02-02 19:17:21 +01:00
Yury V. Zaytsev
bc4da2a92d formatting: step 2.1 - remove indent control comments
```
master % find . -type file -name '*.[ch]' | xargs sed -i '' '/INDENT-ON/d'
master % find . -type file -name '*.[ch]' | xargs sed -i '' '/INDENT-OFF/d'
```

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-02-02 19:16:54 +01:00
Yury V. Zaytsev
851a1a2dae Ticket #4592: migrate to clang-format - step 1: convert comments /* */ -> //
"Safe" automatic replacement and then manual tweaks:

```
find . -type file -name '*.[ch]' | xargs sed -i '' -E '/^\/\*/! s|/\*([^/]+)\*/$|//\1|g'
find . -type file -name '*.[ch]' | xargs sed -i '' -E s/ +$//
```

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-02-02 19:13:21 +01:00
Yury V. Zaytsev
8cba5f6e51 doc: switch links to https://, update or remove dead links
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-01-31 10:12:32 +01:00
Yury V. Zaytsev
19830cd8ac doc: rename docs in lib/event to README for visibility
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-01-31 09:33:29 +01:00
Yury V. Zaytsev
1ec62cd234 doc: merge lib/vfs/HACKING into README and remove obsolete links (dead projects)
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-01-31 09:30:17 +01:00
Andrew Borodin
81f3331262 (tty_flush_winch): return boolean.
Return TRUE if at least one SIGWINCH flag was read from pipe.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-01-25 18:04:54 +03:00
Andrew Borodin
a493aa9b3b Ticket #4630: mc doesn't fully resize itself...
if reading directory while terminal's resized.

(dialog_change_screen_size): don't flush SIGWINCH pipe if top_dlg isn't
created yet.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-01-25 18:04:41 +03:00
Yury V. Zaytsev
5b86e9099a subshell: fix environment variable names in mc_shell_recognize_path
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-01-15 17:41:40 +01:00
d3m3t3r
9f5d80def2 Ticket #3748: add support for ksh in subshell
Support Korn shell variants (ksh/oksh/mksh) in the subshell; mksh (MirBSD Korn
shell) is handled separately as it substantially differs from pdksh (Public
Domain Korn shell) based varaints.

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2025-01-15 16:47:24 +01:00
Andrew Borodin
4b96b8d5f3 Update copyright years.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-01-11 12:14:08 +03:00
Andrew Borodin
702c354602 search: change types of start and end search positions from gsize to off_t.
editor: related changes.
viewer: likewise.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-01-11 12:14:08 +03:00
Andrew Borodin
8a85062305 (size_trunc_len): fix Undefined Binary Operator Result.
lib/util.c:493:28: warning: The left operand of '!=' is a garbage value due to array index out of bounds [clang-analyzer-core.UndefinedBinaryOperatorResult]
  493 |     for (j = units; sfx[j] != NULL; j++)
      |                     ~~~~~~ ^

 - verify and limit input 'units' value

Found by Clang-19 Static Analyzer.

Reported-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <vmail.ru>
2025-01-11 12:13:17 +03:00
Andreas Mohr
b6f126bf66 (quick_create_labeled_input): fix potential leak of memory.
/tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/quick.c:150:9: warning: Potential leak of memory pointed to by 'label.quick_widget' [clang-analyzer-unix.Malloc]
  150 |         return;
      |         ^

Found by Clang-19 Static Analyzer.

Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-01-11 12:13:17 +03:00
Andrew Borodin
5c5dc8ccae (listbox_drawscroll:) fix division by zero warning.
Make Static Analyzer happy.

lib/widget/listbox.c:119:51: warning: Division by zero [clang-analyzer-core.DivideZero]
  119 |         line = 1 + ((l->current * (w->lines - 2)) / length);

Found by Clang-19 Static Analyzer.

Reported-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-01-11 12:13:17 +03:00
Andreas Mohr
52d5626f9d (quick_dialog_skip): fix undefined behavior.
quick.c:432:28: runtime error: member access within null pointer of type 'Widget' (aka 'struct Widget')
   #0 in quick_dialog_skip lib/widget/quick.c:432:28
   #1 in file_mask_dialog src/filemanager/filegui.c:1462:19
   #2 in do_confirm_copy_move src/filemanager/file.c:1977:11
   #3 in panel_operate src/filemanager/file.c:3536:16
   #4 in copy_cmd src/filemanager/./cmd.h:111:5
   #5 in midnight_execute_cmd src/filemanager/filemanager.c:1177:9
   #6 in midnight_callback src/filemanager/filemanager.c
   #7 in send_message lib/widget/../../lib/widget/widget-common.h:255:15
   #8 in buttonbar_call lib/widget/buttonbar.c:157:15
   #9 in buttonbar_callback lib/widget/buttonbar.c:174:42
   #10 in send_message lib/widget/../../lib/widget/widget-common.h:255:15
   #11 in group_handle_hotkey lib/widget/group.c:566:23
   #12 in group_default_callback lib/widget/group.c:640:16
   #13 in dlg_default_callback lib/widget/dialog.c:370:16
   #14 in midnight_callback src/filemanager/filemanager.c:1615:16
   #15 in send_message lib/widget/../../lib/widget/widget-common.h:255:15
   #16 in group_handle_key lib/widget/group.c:503:15
   #17 in group_default_callback lib/widget/group.c:637:16
   #18 in dlg_key_event lib/widget/dialog.c:252:19
   #19 in dlg_process_event lib/widget/dialog.c:539:9
   #20 in frontend_dlg_run lib/widget/dialog.c:321:9
   #21 in dlg_run lib/widget/dialog.c:573:5
   #22 in do_nc src/filemanager/filemanager.c:1826:16
   #23 in main src/main.c:469:21
   #24 in <null> <null>
   #25 in __libc_start_main <null>
   #26 in _start <null>

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior quick.c:432:28.

Found by Clang-19 Static Analyzer.

Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-01-11 12:13:17 +03:00
Andreas Mohr
e85297c0be Fix garbage return value warning.
Make Static Analyzer happy.

Bug Group   Bug Type              File                     Function/Method       Line
Logic error Garbage return value  src/filemanager/boxes.c  cd_box                1236
Logic error Garbage return value  lib/widget/wtools.c      fg_input_dialog_help  198

Found by Clang-19 Static Analyzer.

Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-01-11 12:13:17 +03:00
Andreas Mohr
4e1442f48d Cleanup cppcheck warnings.
Make cppcheck happy.

lib/search/regex.c:888:85: error: Uninitialized variable: *error [uninitvar]
        if (pcre2_jit_compile (mc_search_cond->regex_handle, PCRE2_JIT_COMPLETE) && *error != '\0')
                                                                                    ^
src/vfs/sftpfs/dir.c:95:26: warning: Uninitialized variable: handle [uninitvar]
    sftpfs_dir->handle = handle;
                         ^
Found by cppcheck-2.16.0

Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2025-01-11 12:13:17 +03:00
Andreas Mohr
9af3991d44 (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>
2025-01-11 12:13:17 +03:00