I can produce a segmentation fault in evaluator_evaluate() by entering the
following input:

-5.45exp(-t/0.22)

However, adding a * between the constant and exp allows the code to
run successfully.

-5.45*exp(-t/0.22)

I check the output of evaluator_create(), and it does return a valid
pointer in both instances.

I have attached the code I was using to perform this test. (it's short)

--Evan
//created Evan Andersen
//2012

//Free for all to use

#include <stdio.h>
#include <matheval.h>
#include <string.h>
#include <math.h>

int compare(void* correct, void* approx, int numElements,char** names, double* values, double error)
{
    double result = evaluator_evaluate(correct, numElements, names, values);
    double guess = evaluator_evaluate(approx, numElements, names, values);
    
    if((fabs(result - guess)/fabs(result)) > error)
    {
        return 0;
    }
    return 1;
}

int main()
{
    char buffer[1024];
    fgets(buffer, sizeof(buffer), stdin);
    buffer[strlen(buffer) - 1] = '\0';
    
    char* solution = "-60/11*e^(-t/0.22)";
    void* correct = evaluator_create(solution);
    void* student = evaluator_create(buffer);
    
    if(!correct)
    {
        fprintf(stderr, "Failed to initialize math evaluator\n", stderr);
        return -1;
    }
    
    char *names[] = { "t" };
    double values[] = {0.0};

    int i;
    while(1)
    {
        values[0] = i*0.01;
        if(!compare(correct, student, 1, names, values, 0.01))
        {
            printf("Solution incorrect\n");
            break;
        }
        if(i > 10000)
        {
            printf("Solution Correct\n");
            break;
        }
        i++;
    }
    
    evaluator_destroy(correct);
    evaluator_destroy(student);
    
    return 0;
}

Reply via email to