Re: [evolution-patches] Fix for bug#306986



Hi,

>
> +static void
> +html_engine_strip_quote(gchar *word)
> +{
> +       if(word[0]=='\'' && word[strlen(word)-1]=='\'') {
> +               int i;
> +
> +               for(i=1;i<strlen(word)-1;i++)
> +                       word[i-1]=word[i];
> +               word[strlen(word)-2]='\0';
> +       }
> +}
> 

strlen(word) can be saved in some temporary variable so as to avoid
these many function calls. 

The declaration of i can be moved outside the if-loop. (Compiler might
do it, while optimizing)

This makes a string <<'word'\0>> to <<word\0'\0>> 

Wont this be leaking memory when we issue the g_free by passing the
base-address of the string, Since char beyond \0 (the apostophe) wont be
freed at all?

An alternative approach will be:

fn() {

	int n;
	n = strlen(word);
	if(word[0]=='\'' && word[n-1]=='\'') {
		word[0]=word[n-1]=' ';
		g_strstrip(word);
        }
}

so that the movement of characters will be internally taken care by GLib
in an efficient manner using g_memmove.

On Mon, 2005-12-19 at 14:25 +0530, Rohini wrote:
> Hi
> 
> I have attached the fix for bug#306986: Adding new word (enclosed in
> single quotes) to dictionary does not work
> 
> Thanks,
> Rohini
> _______________________________________________
> Evolution-patches mailing list

-- 
Sankar P <psankar novell com>



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