bug-libmatheval
[Top][All Lists]
Advanced

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

Re: [Bug-libmatheval] segmentation fault using matheval


From: Aleksandar B. Samardzic
Subject: Re: [Bug-libmatheval] segmentation fault using matheval
Date: Mon, 23 Aug 2004 19:33:35 +0200
User-agent: Mutt/1.4.2.1i

On Mon, Aug 23, 2004 at 10:16:54AM +0200, Ferrarese Leopoldo wrote:
> HI,
> I'm just returned from holiday! :)
> 
> >Must confess I still don't understand problem exactly.  If
> >evaluator_create() returned NULL, you should issue an error message to
> >user stating that syntax of his expression is wrong and you shouldn't
> >call any other function before calling evaluator_create() again
> >(presumably with corrected expression passed).  Specifically, if
> >evaluator_create() returned NULL, you shouldn't call evaluator_destroy()
> >with NULL as an argument.
> Mhh, maybe I don't explain the problem very well:
> When I call evaluator_create() with a function string "wrong", like 
> "log(2)++2" the 
> evaluator_create() return NULL, it's correct, but if I call 
> evaluator_create() again, with a correct function, like ("1+1"), the 
> evaluator_create() return NULL! so, the function don't work. I will wait 1 or 
> 2 second and after it work fine.
> Or I destroy a pointer create correctly, and after the evaluator_create() 
> work fine...
> But this solution don't work well for my application, because there are a 
> great number of wrong math funcion and after few minutes the application 
> don't work well....
> Now I create a filter to call the evaluator_create() only when the string is 
> a math expression...
>  
> 
> >Could you eventually supply a piece of C code like one I supplied in my
> >previous message (preferably your CGI program stripped), that would help
> >me to understand how exactly are you manipulating with evaluators?
> 
>  
> in the initialization module:
> function_safe=evaluator_create("1+1\0");
> 
> in the calc module:
> f = evaluator_create(string);
> if (f==NULL) 
>    {
>     if (function_safe!=NULL) evaluator_destroy(function_safe);
>     function_safe=evaluator_create("1+1\0");
>    }
> 
> very simple...

Thanks for additional input. I was finally able to repeat problem, using
following code (note that you don't have to put NUL character at the end
of your strings - compiler will do this automatically for you):

/*****/
#include <stdio.h>
#include <matheval.h>

int
main()
{
        char           *string0 = "1+1",
            *string1 = "log(2)++2";
        void           *f0,
                       *f1;

        f0 = evaluator_create(string0);
        fprintf(stderr, "Evaluator %s created for \"%s\" function\n",
                (f0 == NULL) ? "not" : "", string0);
        if (f0 != NULL)
                evaluator_destroy(f0);

        f1 = evaluator_create(string1);
        fprintf(stderr, "Evaluator %s created for \"%s\" function\n",
                (f1 == NULL) ? "not" : "", string1);
        if (f1 != NULL)
                evaluator_destroy(f1);

        f0 = evaluator_create(string0);
        fprintf(stderr, "Evaluator %s created for \"%s\" function\n",
                (f0 == NULL) ? "not" : "", string0);
        if (f0 != NULL)
                evaluator_destroy(f0);

        return 0;
}
/*****/

With libmatheval version 1.1.0 this code is printing:
  Evaluator  created for "1+1" function
  Evaluator not created for "log(2)++2" function
  Evaluator not created for "1+1" function
with last line obviously indicating error.  So I fixed the bug and new
version (1.1.1) is available (announcement coming in next message).
Could you now please try new version and let me know is it fixing your
problems?

Regards,
Alex





reply via email to

[Prev in Thread] Current Thread [Next in Thread]