Reply
Thread Tools
electroaudio's Avatar
Posts: 381 | Thanked: 336 times | Joined on Jan 2011 @ Stockholm, Sweden
#1
I dont understand this error, but i dont understand C so well either...
When the code in pink is commented out, then the routine seem to work very well, but when the part in pink is part of the compilation, then the program will crash (sort of..) randomly with error sigsegv-11

Code:
GdkPixbuf *get_pixbuf_file (gchar *fullpath)
{   

    GdkPixbuf *pixbuf=NULL; 
	struct stat statbuf;
	int counter=0;
	char mychar;
	char xxx[50];
	char *mime_icon_name=NULL;
	gchar *mime_icon_file=NULL;
	gchar *test;
	gchar *file_open;
	GtkIconTheme *icon_theme;
	char *ext = strrchr(fullpath, '.');

	if (ext==NULL)
		...
	if (strstr(ext,".desktop") && strstr(".desktop",ext))
		...
	if (strstr(fullpath, "/folder.png") && (fast_mode==0))
		...
	mime_icon_name=NULL;
	if ((mime_icon_name=strrchr(fullpath, '.'))==0)
		..
             if ((statbuf.st_mode &S_IXUSR))
               ...


	memset (xxx,0,sizeof(xxx));
	  for ( counter = 0 ;  (counter<= (sizeof(xxx)-0)) && (mime_icon_name[counter]!=0) ; counter++ ){
		  mychar=mime_icon_name[counter];
		 xxx[counter]=(tolower(mychar));
		} 


	mime_icon_file=g_strconcat ("/home/user/.deskypplet/icons/",xxx+1,".png",NULL);

	if ((pixbuf=gdk_pixbuf_new_from_file_at_size(mime_icon_file,app->icon_x_size,app->icon_y_size,NULL))!=0)
		{
		 return pixbuf;
		}
	else
		{
		 pixbuf= gdk_pixbuf_new_from_file_at_size("/home/user/.deskypplet/icons/dummy.png",app->icon_x_size,app->icon_y_size,NULL);
		 return pixbuf;
		}		
}
Ps. I have deleted code that i dont believe has anything to do with it and replaced it with "..." to make it more readable
__________________
Deskypplet , a desktop for N900 *RIP*

Last edited by electroaudio; 2012-04-14 at 23:56.
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#2
Maybe change

Code:
counter<=
to

Code:
counter<
__________________
N9: Go white or go home
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#3
xxx must be NULL terminated for the line after the pink code to not randomly crash. The pink code doesn't guarantee that. So, you might actually want to change:

Code:
counter<= (sizeof(xxx)-0
to

Code:
counter< (sizeof(xxx)-1
__________________
N9: Go white or go home
 
electroaudio's Avatar
Posts: 381 | Thanked: 336 times | Joined on Jan 2011 @ Stockholm, Sweden
#4
Originally Posted by daperl View Post
xxx must be NULL terminated for the line after the pink code to not randomly crash. The pink code doesn't guarantee that. So, you might actually want to change:

Code:
counter<= (sizeof(xxx)-0
to

Code:
counter< (sizeof(xxx)-1
First time i have tried to compile over a 3G network from a cafe
Unfourtunately that didnt help.

But what about the definitions of the string? is it a guarantee that a declared pointer has any space to hold a string?
Like the mime_icon_name , how can it have any allocated space to it to hold the 50 chars?
__________________
Deskypplet , a desktop for N900 *RIP*

Last edited by electroaudio; 2012-04-14 at 16:13.
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#5
Yes, exactly, define it the same as xxx. That should get you to point B. It's not very well written.

So, instead of:

Code:
char *mime_icon_name=NULL;
make it

Code:
char mime_icon_name[50];
There are possibly other memory problems, but start there.
__________________
N9: Go white or go home
 
electroaudio's Avatar
Posts: 381 | Thanked: 336 times | Joined on Jan 2011 @ Stockholm, Sweden
#6
That feels much better, but now i get a lot of "incompatible types in assignment" errors from the compiler when the string is used instead.

Is it possible to rewrite the functions below to work again with this stringdefinition?

Code:
mime_icon_name=NULL;
if ((mime_icon_name=strrchr(fullpath, '.'))==0)
mime_icon_name=g_strconcat (".noext-exe","\0",NULL);
mime_icon_name=g_strconcat (".noext","\0",NULL);
It didnt complain about these lines, but do they still work as expected?

Code:
.. && (mime_icon_name[counter]!=0) 
mychar=mime_icon_name[counter];
xxx[counter]=(tolower(mychar));
__________________
Deskypplet , a desktop for N900 *RIP*

Last edited by electroaudio; 2012-04-14 at 19:26.
 
electroaudio's Avatar
Posts: 381 | Thanked: 336 times | Joined on Jan 2011 @ Stockholm, Sweden
#7
Sorry, it should be a pointer as it was.
It got its value from the parts that i had edited out.
But after adding:
Code:
 if (mime_icon_name!=NULL){ ...}
Around it, it works perfectly.

Now i only need to add a timer to prevent readdir() from getting stuck in /dev/ for example.
__________________
Deskypplet , a desktop for N900 *RIP*

Last edited by electroaudio; 2012-04-14 at 23:55.
 

The Following User Says Thank You to electroaudio For This Useful Post:
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#8
That's what I figured.
__________________
N9: Go white or go home
 

The Following User Says Thank You to daperl For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 14:20.