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 8ef02c3b33bf7bd9d753b401bd876ddfd9cc8b59

Properly handle string allocation errors in trie
* clone_nodes() wasn't considering key allocation failure as an error.
* trie_set() was assuming key allocation was always successful.
* alloc_string() was not checking result of malloc() for a string
buffer.
Author: xaizek
Author date (UTC): 2026-05-14 13:51
Committer name: xaizek
Committer date (UTC): 2026-05-15 12:48
Parent(s): 23063c741f15a85621fd232dfc3ac5b779f6910d
Signing key: 99DC5E4DB05F6BE2
Tree: d1d975c671888635861a3c69d0f8ea8c612c0a8f
File Lines added Lines deleted
src/utils/trie.c 19 2
File src/utils/trie.c changed (mode: 100644) (index 400ca8122..968148e5a)
... ... clone_nodes(trie_t *new_trie, const trie_node_t *node, int *error)
150 150 return NULL; return NULL;
151 151 } }
152 152
153 new_node->key = alloc_string(new_trie, node->key, node->key_len);
154 if(new_node->key == NULL)
155 {
156 *error = 1;
157 return NULL;
158 }
159
153 160 new_node->left = clone_nodes(new_trie, node->left, error); new_node->left = clone_nodes(new_trie, node->left, error);
154 161 new_node->right = clone_nodes(new_trie, node->right, error); new_node->right = clone_nodes(new_trie, node->right, error);
155 162 new_node->down = clone_nodes(new_trie, node->down, error); new_node->down = clone_nodes(new_trie, node->down, error);
156 new_node->key = alloc_string(new_trie, node->key, node->key_len);
157 163 new_node->first = node->key[0]; new_node->first = node->key[0];
158 164 new_node->key_len = node->key_len; new_node->key_len = node->key_len;
159 165 new_node->exists = node->exists; new_node->exists = node->exists;
 
... ... trie_set(trie_t *trie, const char str[], const void *data)
238 244 { {
239 245 return -1; return -1;
240 246 } }
247
241 248 node->key_len = strlen(str); node->key_len = strlen(str);
242 node->key = alloc_string(trie, str, node->key_len);
243 249 node->first = str[0]; node->first = str[0];
250
251 node->key = alloc_string(trie, str, node->key_len);
252 if(node->key == NULL)
253 {
254 return -1;
255 }
256
244 257 *link = node; *link = node;
245 258 break; break;
246 259 } }
 
... ... alloc_string(trie_t *trie, const char str[], int len)
348 361
349 362 trie->str_bufs = str_bufs; trie->str_bufs = str_bufs;
350 363 trie->str_bufs[trie->str_buf_count] = malloc(MAX(MIN_STR_BUF_SIZE, len)); trie->str_bufs[trie->str_buf_count] = malloc(MAX(MIN_STR_BUF_SIZE, len));
364 if(trie->str_bufs[trie->str_buf_count] == NULL)
365 {
366 return NULL;
367 }
351 368
352 369 ++trie->str_buf_count; ++trie->str_buf_count;
353 370 trie->last_offset = 0; trie->last_offset = 0;
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