fix icons not showing and segfault when size not properly formatted

This commit is contained in:
Night Kaly 2024-03-30 13:00:16 +00:00
parent 652473a0ec
commit 1f0f19174a
No known key found for this signature in database
GPG key ID: 8E829D3381CFEBBE
3 changed files with 38 additions and 33 deletions

7
ccc.c
View file

@ -630,7 +630,12 @@ void add_file_stat(char *filepath, int ftype)
unit++; unit++;
} }
/* display sizes */ /* display sizes */
sprintf(size, "%.3g%s", bytes, units[unit]); /* Check if there are decimal places */
if (bytes == (unsigned int) bytes) {
sprintf(size, "%d%s", (unsigned int) bytes, units[unit]);
} else {
sprintf(size, "%.2f%s", bytes, units[unit]);
}
/* get file mode string */ /* get file mode string */
char *mode_str = get_file_mode(file_stat.st_mode); char *mode_str = get_file_mode(file_stat.st_mode);

62
icons.c
View file

@ -20,7 +20,6 @@ unsigned int hash(char *name)
hash_value = (hash_value * name[i]) % TABLE_SIZE; hash_value = (hash_value * name[i]) % TABLE_SIZE;
} }
printf("Name: %s | Hash Value: %d\n", name, hash_value);
return hash_value; return hash_value;
} }
@ -50,69 +49,70 @@ void hashtable_init()
md->icon = L""; md->icon = L"";
icon *py = memalloc(sizeof(icon)); icon *py = memalloc(sizeof(icon));
strcpy(md->name, "py"); strcpy(py->name, "py");
md->icon = L""; py->icon = L"";
icon *java = memalloc(sizeof(icon)); icon *java = memalloc(sizeof(icon));
strcpy(md->name, "java"); strcpy(java->name, "java");
md->icon = L""; java->icon = L"";
icon *json = memalloc(sizeof(icon)); icon *json = memalloc(sizeof(icon));
strcpy(md->name, "json"); strcpy(json->name, "json");
md->icon = L""; json->icon = L"";
icon *js = memalloc(sizeof(icon)); icon *js = memalloc(sizeof(icon));
strcpy(md->name, "js"); strcpy(js->name, "js");
md->icon = L""; js->icon = L"";
icon *html = memalloc(sizeof(icon)); icon *html = memalloc(sizeof(icon));
strcpy(md->name, "html"); strcpy(html->name, "html");
md->icon = L""; html->icon = L"";
icon *rs = memalloc(sizeof(icon)); icon *rs = memalloc(sizeof(icon));
strcpy(md->name, "rs"); strcpy(rs->name, "rs");
md->icon = L""; rs->icon = L"";
icon *sh = memalloc(sizeof(icon)); icon *sh = memalloc(sizeof(icon));
strcpy(md->name, "sh"); strcpy(sh->name, "sh");
md->icon = L""; sh->icon = L"";
icon *go = memalloc(sizeof(icon)); icon *go = memalloc(sizeof(icon));
strcpy(md->name, "go"); strcpy(go->name, "go");
md->icon = L""; go->icon = L"";
icon *r = memalloc(sizeof(icon)); icon *r = memalloc(sizeof(icon));
strcpy(md->name, "r"); strcpy(r->name, "r");
md->icon = L""; r->icon = L"";
icon *diff = memalloc(sizeof(icon)); icon *diff = memalloc(sizeof(icon));
strcpy(md->name, "diff"); strcpy(diff->name, "diff");
md->icon = L""; diff->icon = L"";
icon *hs = memalloc(sizeof(icon)); icon *hs = memalloc(sizeof(icon));
strcpy(md->name, "hs"); strcpy(hs->name, "hs");
md->icon = L""; hs->icon = L"";
icon *log = memalloc(sizeof(icon)); icon *log = memalloc(sizeof(icon));
strcpy(md->name, "log"); strcpy(log->name, "log");
md->icon = L"󱀂"; log->icon = L"󱀂";
icon *rb = memalloc(sizeof(icon)); icon *rb = memalloc(sizeof(icon));
strcpy(md->name, "rb"); strcpy(rb->name, "rb");
md->icon = L""; rb->icon = L"";
icon *iso = memalloc(sizeof(icon)); icon *iso = memalloc(sizeof(icon));
strcpy(md->name, "iso"); strcpy(iso->name, "iso");
md->icon = L"󰻂"; iso->icon = L"󰻂";
icon *lua = memalloc(sizeof(icon)); icon *lua = memalloc(sizeof(icon));
strcpy(md->name, "lua"); strcpy(lua->name, "lua");
md->icon = L""; lua->icon = L"";
hashtable_add(c); hashtable_add(c);
hashtable_add(h); hashtable_add(h);
hashtable_add(cpp); hashtable_add(cpp);
hashtable_add(hpp); hashtable_add(hpp);
hashtable_add(md);
hashtable_add(py); hashtable_add(py);
hashtable_add(java); hashtable_add(java);
hashtable_add(json); hashtable_add(json);

View file

@ -5,7 +5,7 @@
#include <wchar.h> #include <wchar.h>
#define MAX_NAME 30 #define MAX_NAME 30
#define TABLE_SIZE 50 #define TABLE_SIZE 100
typedef struct { typedef struct {
char name[MAX_NAME]; char name[MAX_NAME];