You are not logged in.
I'm having trouble with making character arrays that I'm using to store the cached files in compiz-deskmenu.
Code: http://pastebin.com/FNrvpTKS
When I try to execute that function, the program segfaults before it enters the if/else statement in the cache management. It may have to do with how I declared the array, but I'm pretty much lost at that .
Compile errors I get related to this:
deskmenu-menu.c:941:19: warning: 'cache_name' may be used uninitialized in this function
deskmenu-menu.c:904:30: warning: 'cache_file' may be used uninitialized in this function
Changing the original declarations to:
gchar **cache_name = NULL;
gchar **cache_file = NULL;
does not fix the problem, even though it gets rid of that compile error.
Last edited by ShadowKyogre (2010-11-27 05:06:56)
For every problem, there is a solution that is:
Clean
Simple and most of all...wrong!
Github page
Offline
There's nothing better than valgrind for diagnosing segfaults. Anyway, &cache_file[0] is undefined behaviour since you're dereferencing a NULL pointer ("&cache_file[0]" is equivalent to "&(*(cache_file + 0))", and "cache_file + 0" is NULL).
I suppose you want cache_file to be an array of pointers-to-gchar? What size should this array have? If that size is known at compile time, declare cache_file as "gchar *cache_file[NCACHEFILES]"; if the size is only known at run time, do "gchar **cache_files = malloc(ncachefiles * sizeof(gchar *))", and don't forget to free() it later.
Offline
There's nothing better than valgrind for diagnosing segfaults. Anyway, &cache_file[0] is undefined behaviour since you're dereferencing a NULL pointer ("&cache_file[0]" is equivalent to "&(*(cache_file + 0))", and "cache_file + 0" is NULL).
I suppose you want cache_file to be an array of pointers-to-gchar? What size should this array have? If that size is known at compile time, declare cache_file as "gchar *cache_file[NCACHEFILES]"; if the size is only known at run time, do "gchar **cache_files = malloc(ncachefiles * sizeof(gchar *))", and don't forget to free() it later.
Yes, it should normally have a flexible size, but I think 1000 would be a sane size limit for the array. I changed the &cache_file[0] to a temporary pointer for transfer, but now the only problem is that the arrays aren't being written back to (which probably makes the input & array element comparisons fail).
Code: http://pastebin.com/M6LRdWW6
[EDIT] Decided to use a GHashTable since that gets rid of these errors, allows a dynamic cache, and makes it easier to look up items in the cache since the cache structure is just a cached filename to a cached file content.
Last edited by ShadowKyogre (2010-11-27 05:05:58)
For every problem, there is a solution that is:
Clean
Simple and most of all...wrong!
Github page
Offline