Commit Graph

1973 Commits

Author SHA1 Message Date
Andreas Mohr
84e482abe9 (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>
2024-12-21 09:39:36 +03:00
Andreas Mohr
77151fd3fe 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>
2024-12-18 21:12:14 +03:00
Andreas Mohr
9ef2cb4efd 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>
2024-12-15 14:06:21 +03:00
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
Andrew Borodin
009efde431 Join create_message() and do_create_message().
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-12-15 14:06:21 +03:00
Andrew Borodin
71199a290f Make message box with button.
* (bg_message): use query_dialog() instead of fg_message().
  * (message): likewise.
  * (fg_message): isn't used anymore. Remove.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-12-15 14:06:21 +03:00
Andrew Borodin
c943b931d7 Ticket #4587: mcviewer: fix BOL regex search.
Refactoring.

* (mc_search_line_t): rename from edit_search_line_t and move to
lib/search.h.
* (mc_search_get_line_type): rename from edit_get_search_line_type()
and move to lib/search/regex.c.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-12-15 13:46:52 +03:00
Johannes Altmanninger
0ea77d2ec7 Ticket #4597: fix CSI parser
fish shell 4.0 wants to send sequences like "\x1b[=5u",
so strip them from the output as well.

See https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences

In future we should probably pass through some sequences like bracketed paste.

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-11-01 18:10:09 +01:00
Yury V. Zaytsev
61909fa24e mountlist: suppress unused label warning on FreeBSD
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-11-01 17:37:10 +01:00
Yury V. Zaytsev
289b9c85be (canonicalize_pathname_custom): fix --disable-charset build broken in 8f723b8
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-26 18:22:53 +02:00
Yury V. Zaytsev
93b539444b Ticket #4584: re-implement mocking via weak symbols instead of symbol duplication
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-19 08:56:40 +02:00
Yury V. Zaytsev
b8e2a376e3 Ticket #4495: check if environ is defined to fix redefinition on Alpine
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-18 20:57:43 +02:00
Yury V. Zaytsev
dd12be7c82 (extract_line): remove extra const qualifier erroneously introduced in bb4e152
```
../../lib/util.c:637:7: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
  637 | const const char *
      |       ^
```

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-18 19:46:17 +02:00
Andrew Borodin
d7b85ed9c9 Ticket #4593: tar: fix compilation on systems w/o stdckdint.h.
* lib/intprops.h: new file.
  * src/vfs/tar/tar-internal.h: include intprops.h, remove macros
    defined there.
  * src/vfs/tar/tar-sparse.c: remove macro, defined in intprops.h.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-08 13:02:17 +03:00
Yury V. Zaytsev
d11faea07d doc: fix typos in comments
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-05 18:55:01 +02:00
Andrew Borodin
c5379ab36e lib/vfs/path.h: fix coding style.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:07:14 +03:00
Andrew Borodin
d3c26320d4 lib/vfs/direntry.c: fix coding style.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:07:14 +03:00
Andrew Borodin
de9551be13 lib/vfs/vfs.c: fix coding style.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:07:14 +03:00
Andrew Borodin
72d0b4f878 Add some files and code rom Gnulib as preparation to TAR updates.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:07:13 +03:00
Yury V. Zaytsev
0775539b08 Fix typos/improve grammar in charsets.c / strutil.h
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-05 15:07:13 +03:00
Andrew Borodin
d2aa6486dd (mc_tmpdir): reduce variable scope.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:07:12 +03:00
Andrew Borodin
d6a93efb2b (create_sequence): reduce variable scope, trivial refactoring.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:05:58 +03:00
Andrew Borodin
6cb97d18f1 src/strutil/xstrtol.c: sync with gnulib.
Sync with gnulib 64ddc975e72cb55d2b2d755c25603bd70312aa5e:
  This patch alters xstrtoumax behavior slightly, in areas are not
  likely to affect any real callers, by making xstrtoumax behave more
  like the system strtol. In particular, it lets xstrtoumax support
  bases other than those required by POSIX, if the underlying
  implementation does; this removes the need for an g_assert().

  * lib/strutil/strtol.c: Do not include stdio.h.
  (xstrtoumax): Use same parameter names as POSIX, to make it
  easier for outsiders to follow. Do not require the base to be 0-36,
  as the underlying implementation is allowed to support other bases.

Sync with gnulib 16b33e6649425fcdce095f262da98b539d2f7448.

  * (xstrtoumax): Don't update *endptr if strtol doesn't.
  Also, if the underlying strtol gives an unusual error number and
  sets *endpnr = nptr, assume that's an error not a missing number.

Sync with gnulib bd1e981434c98751b1106a1744e77a27317b52b3
  * (xstrtoumax): Stop worrying about hypothetical implementations that
  are causing more confusion than the code is worth. Instead, go back
  more to old way of doing things.  None of this matters for practical
  applications.

Add commemt.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:05:58 +03:00
Andrew Borodin
bb4e152c59 (extract_line): optionally return the lengh of the line.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:05:58 +03:00
Andrew Borodin
2db4f47bdd (tr_utf8_search_{first,last}): minor refactoring.
Reduce variable scope.
Call strlen(search) before loop.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:05:58 +03:00
Andrew Borodin
87f46330d5 (str_utf8_make_make_term_form): call strlen() one time.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:05:58 +03:00
Andrew Borodin
cb4c49f143 strutils: don't call strlen() in MIN() macro.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:05:58 +03:00
Andrew Borodin
bc79d61b2d (str_verscmp): glibification.
Use g_ascii_isdigit() instead of isdigit().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:05:58 +03:00
Andrew Borodin
b5f465a3d8 (filevercmp): make inline.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:05:58 +03:00
Andrew Borodin
f47688a781 lib/vfs/interface.c: add missed INDENT-ON, indentation.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-10-05 15:05:58 +03:00
Yury V. Zaytsev
8f723b8a7f charset: reimplement is_supported_encoding to use iconv instead of mc built-in charset table
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-05 11:49:26 +02:00
Andrew Borodin
35c103fa97 (str_crt_conv_from): handle INVALID_CONV.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-05 11:49:26 +02:00
Andrew Borodin
3526dfcf34 (str_nconvert_to_display, str_nconvert_to_input): handle invalid conversion.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-05 11:49:26 +02:00
Yury V. Zaytsev
1e0e6b5e1e charset: rename IBM866 to CP866 for iconv and adjust charset names for codeset
```
linux $ iconv -l | grep 866
866//
866NAV//
CP866//
CP866NAV//
CSIBM866//
IBM866//
IBM866NAV//

solaris $ iconv -l | grep 866
    CP866 (CP866, CP-866, CP_866, 866),
    IBM-866,

macos % iconv -l | grep 866
CP866 866 CSIBM866 IBM866 MSCP866

musl/src/locale/codepages.h: "cp866\0"
```

On glibc-based systems, codeset will be set to charmap name, on most other systems it seems to be taken from locale name.

## Linux

```
zaytsev@fedora:~$ locale -a | grep ru
ru_RU
ru_RU.cp866
ru_RU.ibm866
ru_RU.iso88595
ru_RU.koi8r
ru_RU.utf8
russian
ru_UA
ru_UA.koi8u
ru_UA.utf8

zaytsev@fedora:~/src$ LC_ALL=ru_RU.cp866 LANG=ru_RU.cp866 ./a.out
IBM866

zaytsev@fedora:~/src$ LC_ALL=ru_RU.koi8r LANG=ru_RU.koi8r ./a.out
KOI8-R

zaytsev@fedora:~/src$ LC_ALL=ru_RU.iso88595 LANG=ru_RU.iso88595 ./a.out
ISO-8859-5
```

## macOS

```
ru_RU.ISO8859-5
ru_RU.CP866
ru_RU.CP1251
ru_RU.UTF-8
ru_RU.KOI8-R
ru_RU

zaytsev@Yurys-MBP mc % LANG=ru_RU.CP866 LC_ALL=ru_RU.CP866 ./a.out
CP866

zaytsev@Yurys-MBP mc % LANG=ru_RU.ISO8859-5 LC_ALL=ru_RU.ISO8859-5 ./a.out
ISO8859-5
```

## FreeBSD

```
ru_RU.CP1251
ru_RU.CP866
ru_RU.ISO8859-5
ru_RU.KOI8-R
ru_RU.UTF-8

zaytsev@cfarm240:~ $ LANG=ru_RU.ISO8859-5 LC_ALL=ru_RU.ISO8859-5 ./a.out
ISO8859-5

zaytsev@cfarm240:~ $ LANG=ru_RU.CP866 LC_ALL=ru_RU.CP866 ./a.out
CP866
```

## Solaris

```
ru
ru.UTF-8
ru.koi8-r
ru_RU
ru_RU.ANSI1251
ru_RU.ISO8859-5
ru_RU.KOI8-R
ru_RU.UTF-8

zaytsev@gcc-solaris10:~/src$ LANG=ru_RU.ISO8859-5 LC_ALL=ru_RU.ISO8859-5 ./a.o>
ISO8859-5

zaytsev@gcc-solaris10:~/src$ LANG=ru.koi8-r LC_ALL=ru.koi8-r ./a.out
KOI8-R
```

## AIX

```
zaytsev@gcc111:[/home/zaytsev]locale -a
C
POSIX
en_US.8859-15
en_US.IBM-858
en_US.ISO8859-1
en_US

-bash-5.1$ LANG=en_US.ISO8859-1 LC_ALL=en_US.ISO8859-1 ./a.out
ISO8859-1
```

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-05 11:49:26 +02:00
Yury V. Zaytsev
07e24c0289 lib/path: clarify conditions for creating converters
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-10-05 11:49:26 +02:00
Yury V. Zaytsev
a3ce493ae2 vfs: fix tempdir path building to account for trailing slash on macOS
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-09-03 07:39:25 +02:00
Yury V. Zaytsev
ad96349c91 x11: fix -Wdeprecated-declarations for g_module_build_path
```
x11conn.c:140:5: warning: 'g_module_build_path' is deprecated [-Wdeprecated-declarations]
  140 |     x11_module_fname = g_module_build_path (NULL, "X11");
      |     ^~~~~~~~~~~~~~~~
```

Reported-by: David Martín <dhmartina@yahoo.es>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-08-15 21:09:08 +02:00
Yury V. Zaytsev
eb1375b65d vfs: implement support for all known stat formats and centralize handling
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-07-28 10:00:52 +02:00
Yury V. Zaytsev
c8e8f01faf utilvfs: concentrate timesbuf handling in one place
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-07-28 10:00:52 +02:00
Yury V. Zaytsev
77e5913c02 utilvfs: abstract mc_timesbuf_t handling with own mc_timespec_t type
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-07-28 10:00:52 +02:00
Yury V. Zaytsev
191108766f Ticket #4542: fix support of timestamps with nanosecond precision on macOS
utilvfs: isolate utime / utimensat calls in a helper function

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-07-28 10:00:52 +02:00
Yury V. Zaytsev
ab7ed3cf2c maint: fix typo in variable name (parse_ls_vga.c)
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-06-03 20:44:09 +02:00
Yury V. Zaytsev
335c5a78bb glibcompat: remove g_direct_equal shim
This function is present at least in glib-2.43.92:

../../lib/glibcompat.c:69:1: error: static declaration of 'g_direct_equal' follows non-static declaration
   69 | g_direct_equal (gconstpointer v1, gconstpointer v2)
      | ^~~~~~~~~~~~~~
In file included from /home/zaytsev/opt/glib/include/glib-2.0/glib.h:50,
                 from ../../lib/global.h:10,
                 from ../../lib/glibcompat.c:36:
/home/zaytsev/opt/glib/include/glib-2.0/glib/ghash.h:180:10: note: previous declaration of 'g_direct_equal' was here
  180 | gboolean g_direct_equal (gconstpointer  v1,
      |          ^~~~~~~~~~~~~~

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-06-03 16:18:12 +02:00
Yury V. Zaytsev
bda4e480d2 maint: fix typos in the code
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2024-06-03 16:18:04 +02:00
Andrew Borodin
6718b3ec26 Indentation using GNU indent-2.2.13.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-06-02 12:49:13 +03:00
Yury V. Zaytsev
40867e5740 clang: fix -Wimplicit-fallthrough warning
../../../lib/search/normal.c:75:9: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
        default:
        ^
../../../lib/search/normal.c:75:9: note: insert 'break;' to avoid fall-through
        default:
        ^
        break;

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-06-02 12:49:13 +03:00
Yury V. Zaytsev
04496c6fc1 clang: fix -Wconditional-uninitialized warnings
../../../src/filemanager/file.c:2402:61: warning: variable 'attrs' may be uninitialized when used here [-Wconditional-uninitialized]
                while (attrs_ok && mc_fsetflags (dst_vpath, attrs) != 0 && !ctx->skip_all)
                                                            ^~~~~
../../../src/filemanager/file.c:2266:24: note: initialize the variable 'attrs' to silence this warning
    unsigned long attrs;
                       ^
                        = 0

../../../src/filemanager/file.c:3227:38: warning: variable 'attrs' may be uninitialized when used here [-Wconditional-uninitialized]
            mc_fsetflags (dst_vpath, attrs);
                                     ^~~~~
../../../src/filemanager/file.c:2942:24: note: initialize the variable 'attrs' to silence this warning
    unsigned long attrs;
                       ^
                        = 0

../../../lib/strutil/tokenize.c:163:44: warning: variable 'delimopen' may be uninitialized when used here [-Wconditional-uninitialized]
        if (nestdelim != 0 && string[i] == delimopen)
                                           ^~~~~~~~~
../../../lib/strutil/tokenize.c:72:19: note: initialize the variable 'delimopen' to silence this warning
    char delimopen;
                  ^
                   = '\0'

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-06-02 12:49:13 +03:00
Andrew Borodin
a802f14c2e (path_trunc): optimization.
Get rid of double conversion of path: remove passwords using
vfs_path_from_str_flags (path, VPF_STRIP_PASSWORD).

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-06-02 12:49:13 +03:00
Andrew Borodin
5a67afc812 (vfs_path_build_url_params_str): minor refactoring.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-06-02 12:49:13 +03:00
Andrew Borodin
9e039f66d1 (vfs_path_from_str_uri_parser): fix coding style.
(vfs_path_to_str_flags): likewise.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-06-02 12:49:13 +03:00