Counter give negative value and error

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18.00
Platform: Ubuntu 18.04.4
Compiler: Not Provided

I use the makeclass to run a analysis of a data in root Tree give me by GAMOS/Geant4. When I run I see that an error in size of the vector dist[count], but I fix this increase the size of count. But when I run a root file if more data, give me an error:

In file included from input_line_110:1:
/media/gamos/Seagate Basic/gamos6/dados/doseElA.C:155:39: warning: invalid memory pointer passed to a callee:
…distC[count] = TMath::Sqrt(pow((Step_FinalPosX->at(k)-Step_FinalPosX->at…

Run without this line and print the values of count, and the result was negative in some data.

I place the files attached.

How can I fix this?
doseElA.h (69.2 KB) doseElA.C (19.1 KB)

Best regards

Hi @David_Fernandes,
obviously I can’t run the code correctly because I’m missing the input files, but just from reading the code I would say count can’t have negative values without an integer overflow (but in that case you should see a lot of positive values being printed before): it’s initialized to 0 and always incremented.

Do you mean distC[count] takes negative values?

In any case, there seems to be a bug in your logic somewhere that needs investigation on your part: I would suggest to inspect each element in that line: is Step_FinalPosX a valid pointer? is Step_FinalPosX->at(k) ok?


Thanks @eguiraud for the reply.
“(but in that case you should see a lot of positive values being printed before)” That is exactly what I saw. The disctC[count] i wasn’t print yet only the count. But I proceed as you said looking fot Step_FinalPosX and Step_FinalPosX->at(k) and return here.

Best regards

If count goes above the maximum positive integer that int can represent, it will overflow and assume negative values. On most platforms that maximum value is 2**31-1 == 2147483647.
If you need higher counts you can use e.g. an unsigned long long int, that goes up to 18446744073709551615.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.