Re: need help!!!



Hi Yiqing Lee,

On Tue, 2002-07-09 at 17:19, Yiqing Lee wrote:
> Hi, list

	Firstly, this list is intended for questions about bonobo, you'd do
better to post things such as this to nautilus-list gnome org, or
gnome-love gnome org 

> This search word in text entry will retrieved and append to the web URL

	Ok - you blow the heap here, and start stomping on memory you don't own
:-)

> 		//get customrized search engine from preference
> 		search_web_uri = eel_preferences_get (NAUTILUS_PREFERENCES_SEARCH_WEB_URI);
> 
> 		//attach search word to form whole URL
> 		strcat(search_web_uri,"/search?hl=en&ie=UTF-8&btnG=Google+Search&q=");
> 		strcat(search_web_uri,gtk_entry_get_text(GTK_ENTRY(entry)));

	The bug is here [ also, you should not use '//' comments in C - it's a
non-standard GNU extension ].

	man strcat:

[snip]
The  strcat() function appends the src string to the dest string
overwriting the `\0' character at the end of dest, and then adds a
terminating `\0' character.  The strings may  not  overlap,
and the dest string must have enough space for the result.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[snip]

	eel_preferences_get cannot allocate a sufficiently large chunk of
memory in returning a string such that arbitrary other strings can be
appended to it - that would not be reasonable :-)

	I suspect you want to use:

	new_string = g_strconcat (search_web_uri, "foo", "baa", NULL);

	The trailing NULL is a very important terminator in there, don't forget
it.

	HTH,

		Michael.

-- 
 mmeeks gnu org  <><, Pseudo Engineer, itinerant idiot




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]