xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 32674117a8f1efc6b355cfaacc739a7fb043868d

Fix :clone producing weird results for some names
On trying to increment numbers greater than (2**31 - 1), it wrapped
into negative numbers.

New behaviour:
- should work fine for numbers up to `2**63 - 1` (typically last `long
long` but the limit can be different depending on a system)
- numbers greater than the limit are ignored and `(1)` is appended

Thanks to CaptainFantastic.
Author: xaizek
Author date (UTC): 2025-05-01 21:33
Committer name: xaizek
Committer date (UTC): 2025-05-02 07:58
Parent(s): 671b12cd4d74984f345bca925486c226668ce1b6
Signing key: 99DC5E4DB05F6BE2
Tree: c9a329b29a2874dfed5f5f054bbbca746d5c76f5
File Lines added Lines deleted
ChangeLog 3 0
src/fops_misc.c 4 4
tests/fileops/gen_clone_name.c 29 0
File ChangeLog changed (mode: 100644) (index fbeaacfea..852dae55e)
68 68 Fixed truncating wide characters on drawing columns broken on introducing Fixed truncating wide characters on drawing columns broken on introducing
69 69 column-specific highlighting in 0.14-beta. Thanks to Snake52996. column-specific highlighting in 0.14-beta. Thanks to Snake52996.
70 70
71 Fixed :clone producing weird results on trying to increment numbers
72 greater than `2**31 - 1`. Thanks to CaptainFantastic.
73
71 74 0.14-beta to 0.14 (2025-02-08) 0.14-beta to 0.14 (2025-02-08)
72 75
73 76 Improved documentation on zh/zl menu keys a bit. Improved documentation on zh/zl menu keys a bit.
File src/fops_misc.c changed (mode: 100644) (index 181cd20b1..2862cc1d1)
... ... gen_clone_name(const char dir[], const char normal_name[])
919 919 static char result[NAME_MAX + 1]; static char result[NAME_MAX + 1];
920 920
921 921 char extension[NAME_MAX + 1]; char extension[NAME_MAX + 1];
922 int i;
922 long long i;
923 923 size_t len; size_t len;
924 924 char *p; char *p;
925 925
 
... ... gen_clone_name(const char dir[], const char normal_name[])
934 934 if(result[len - 1] == ')' && (p = strrchr(result, '(')) != NULL) if(result[len - 1] == ')' && (p = strrchr(result, '(')) != NULL)
935 935 { {
936 936 char *t; char *t;
937 long l;
938 if((l = strtol(p + 1, &t, 10)) > 0 && t[1] == '\0')
937 long long l;
938 if((l = strtoll(p + 1, &t, 10)) > 0 && t[1] == '\0' && l != LONG_LONG_MAX)
939 939 { {
940 940 len = p - result; len = p - result;
941 941 i = l + 1; i = l + 1;
 
... ... gen_clone_name(const char dir[], const char normal_name[])
944 944
945 945 do do
946 946 { {
947 snprintf(result + len, sizeof(result) - len, "(%d)%s%s", i++,
947 snprintf(result + len, sizeof(result) - len, "(%lld)%s%s", i++,
948 948 (extension[0] == '\0') ? "" : ".", extension); (extension[0] == '\0') ? "" : ".", extension);
949 949 } }
950 950 while(path_exists_at(dir, result, NODEREF)); while(path_exists_at(dir, result, NODEREF));
File tests/fileops/gen_clone_name.c changed (mode: 100644) (index 7ea7cf1a4..b8c7bacfb)
... ... TEST(dot_files)
49 49 assert_string_equal(".config(1).d(1)", gen_clone_name(".", ".config.d(1)")); assert_string_equal(".config(1).d(1)", gen_clone_name(".", ".config.d(1)"));
50 50 } }
51 51
52 TEST(large_numbers)
53 {
54 /* 2**31-1 / 2**31 / 2**31+1 */
55 assert_string_equal("name(2147483648)",
56 gen_clone_name(".", "name(2147483647)"));
57 assert_string_equal("name(2147483649)",
58 gen_clone_name(".", "name(2147483648)"));
59 assert_string_equal("name(2147483650)",
60 gen_clone_name(".", "name(2147483649)"));
61
62 /* 2**32-1 / 2**32 / 2**32+1 */
63 assert_string_equal("name(4294967296)",
64 gen_clone_name(".", "name(4294967295)"));
65 assert_string_equal("name(4294967297)",
66 gen_clone_name(".", "name(4294967296)"));
67 assert_string_equal("name(4294967298)",
68 gen_clone_name(".", "name(4294967297)"));
69
70 /* 2**63-2 / 2**63-1 / 2**63 / 2**63+1 */
71 assert_string_equal("name(9223372036854775807)",
72 gen_clone_name(".", "name(9223372036854775806)"));
73 assert_string_equal("name(9223372036854775807)(1)",
74 gen_clone_name(".", "name(9223372036854775807)"));
75 assert_string_equal("name(9223372036854775808)(1)",
76 gen_clone_name(".", "name(9223372036854775808)"));
77 assert_string_equal("name(9223372036854775809)(1)",
78 gen_clone_name(".", "name(9223372036854775809)"));
79 }
80
52 81 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
53 82 /* vim: set cinoptions+=t0 filetype=c : */ /* vim: set cinoptions+=t0 filetype=c : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master