user1504712
user1504712

Reputation: 33

Invalid parameter passed to C runtime function with QTest

I am developing a Qt project with Qt creator, all works fine, but when i came to the unit testing part using QTest, after compilation I get the error "Invalid parameter passed to C run-time function".

Can anyone help me to find the source of the problem? Is it due to the use of cstdio functions or has it something to do with the .pro configuration?

This is a test method I implemented and did not work:

void TestFichier::testLoad()
{
    Fichier a;
    a.load("input.txt");
    FILE *f=fopen("input.txt","rb");
    int c;
    int i,*tab=a.getHexValues();
    for (i=0;i<3;i++)
        c=fgetc(f);
    fclose(f);
    QCOMPARE(tab[2],c);
}

Fichier is a class I created with a method load.

Upvotes: 0

Views: 5790

Answers (2)

alexisdm
alexisdm

Reputation: 29886

MSDN fgetc documentation states:

If [the parameter] stream is NULL, fgetc and fgetwc invoke the invalid parameter handler, as described in Parameter Validation.

So you should check if fopen returns NULL, and in that case, find the type of error with errno.

Upvotes: 1

NG_
NG_

Reputation: 7183

Probably, your problem is that you make some errors while working with dynamical memory. For example, you can use pointers to unallocated memory, or so. Check your code at getHexValues() method.

Upvotes: 0

Related Questions