Attempt to fix seg fault

This commit is contained in:
Night Kaly 2025-01-17 15:11:21 +00:00
parent b6c7d09a6b
commit c68c0169d4
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM

13
ccc.c
View file

@ -196,7 +196,7 @@ int main(int argc, char **argv)
while (1) { while (1) {
list_files(); list_files();
keybinding(); keybinding();
} }
return 0; return 0;
} }
@ -537,6 +537,9 @@ void add_file_stat(char *filename, char *path, int ftype)
*/ */
void show_file_content(void) void show_file_content(void)
{ {
if (sel_file >= files->length) {
return;
}
file current_file = files->items[sel_file]; file current_file = files->items[sel_file];
move_cursor(1, half_width); move_cursor(1, half_width);
@ -555,7 +558,8 @@ void show_file_content(void)
} }
FILE *file = fopen(current_file.path, "r"); FILE *file = fopen(current_file.path, "r");
if (!file) { if (!file) {
bprintf("Unable to read %s", current_file.name); /* bprintf("Unable to read %s", current_file.name ? current_file.name : "unknown"); */
bprintf("Unable to read unknown");
return; return;
} }
@ -645,7 +649,7 @@ void list_files(void)
/* calculate range of files to show */ /* calculate range of files to show */
long range = files->length; long range = files->length;
/* not highlight if no files in directory */ /* not highlight if no files in directory */
if (range == 0 && errno == 0) { if (range == 0) {
for (int i = 0; i < rows - 1; i++) { for (int i = 0; i < rows - 1; i++) {
move_cursor(i + 1, 1); move_cursor(i + 1, 1);
bprintf("\033[K"); bprintf("\033[K");
@ -838,6 +842,9 @@ void nav_back(const Arg *arg)
void nav_enter(const Arg *arg) void nav_enter(const Arg *arg)
{ {
if (sel_file >= files->length) {
return;
}
file c_file = files->items[sel_file]; file c_file = files->items[sel_file];
/* Check if it is directory or a regular file */ /* Check if it is directory or a regular file */
if (c_file.type == DRY) { if (c_file.type == DRY) {