aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorverdant <im@verdant.ee>2026-07-27 20:59:19 +0800
committerverdant <im@verdant.ee>2026-07-27 20:59:19 +0800
commita7a41d5e8875b6a5e7a8ac23601987aaabedfe92 (patch)
treeebee3888830a870e1e1bf59d71d489eea6cf035f
parentf1982d5443cf348b0c1314e9cb29755a9f899456 (diff)
downloadsf-a7a41d5e8875b6a5e7a8ac23601987aaabedfe92.tar.gz
sf-a7a41d5e8875b6a5e7a8ac23601987aaabedfe92.zip
Fix -Wformat-truncation warning and refactor redraw logic
-rw-r--r--main.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/main.c b/main.c
index e65b52a..0f48ced 100644
--- a/main.c
+++ b/main.c
@@ -63,37 +63,44 @@ int main(int argc, char **argv)
timeout(100);
while (1) {
- if (info->need_redraw) {
- fm_draw_entries(info->windows[FM_PANE_LEFT], info->cur,
- info->cursor, info->top, info->bottom);
-
- if (!info->cur->items[info->cursor].is_dir) {
- snprintf(next_path, sizeof(next_path), "%s/%s",
- info->cwd,
- info->cur->items[info->cursor].name);
- fm_preview_file(info->windows[FM_PANE_RIGHT],
- next_path);
- } else {
- snprintf(next_path, sizeof(next_path), "%s/%s",
- info->cwd,
- info->cur->items[info->cursor].name);
- file_list *new_list = info->next;
- new_list = fm_getdir(new_list, next_path);
- if (new_list) {
- info->next = new_list;
- int right_height =
- info->windows[FM_PANE_RIGHT]
- ->height;
- fm_draw_entries(
- info->windows[FM_PANE_RIGHT],
- info->next, -1, 0, right_height);
- }
+ if (!info->need_redraw)
+ continue;
+
+ fm_draw_entries(info->windows[FM_PANE_LEFT], info->cur,
+ info->cursor, info->top, info->bottom);
+
+ if (!info->cur->items[info->cursor].is_dir) {
+ size_t len = snprintf(
+ next_path, sizeof(next_path), "%s/%s", info->cwd,
+ info->cur->items[info->cursor].name);
+ if (len >= sizeof(next_path)) {
+ die("Length of items error");
+ }
+ fm_preview_file(info->windows[FM_PANE_RIGHT],
+ next_path);
+ } else {
+ size_t len = snprintf(
+ next_path, sizeof(next_path), "%s/%s", info->cwd,
+ info->cur->items[info->cursor].name);
+
+ if (len >= sizeof(next_path)) {
+ die("Length of items error");
+ }
+ file_list *new_list = info->next;
+ new_list = fm_getdir(new_list, next_path);
+ if (new_list) {
+ info->next = new_list;
+ int right_height =
+ info->windows[FM_PANE_RIGHT]->height;
+ fm_draw_entries(info->windows[FM_PANE_RIGHT],
+ info->next, -1, 0,
+ right_height);
}
-
- wrefresh(info->windows[FM_PANE_RIGHT]->win);
- wrefresh(info->windows[FM_PANE_LEFT]->win);
}
+ wrefresh(info->windows[FM_PANE_RIGHT]->win);
+ wrefresh(info->windows[FM_PANE_LEFT]->win);
+
ch = getch();
handling_keys(ch, info);
}