Valgrind: Conditional jump or move depends on uninitialised value(s)

I have a package called geogrid that I and others have recently updated. I want to submit these updates to CRAN in a new version of the package. All of my tests pass and I pass all the criteria needed for successful submission to CRAN except for one.

Valgrind is reporting this error. The main error is: Conditional jump or move depends on uninitialised value(s). Which, as I understand, relates to non-declaration of variables before their use and memory issues.

When creating the package I integrated some really helpful C++ code from a collaborator into the package. This can be found at I think this is the code that's causing the error - namely the function step_two() in this file.

Unfortunately, the code is quite iterative and i'm not well versed in how R shares inputs / variables with C++.

Any suggestions on how to prevent the error or on materials from which I could learn are much appreciated!

Side note: apologies for posting full link. New users cannot use more than 2 links in the first post.

So at geogrid/src/minimal-assignment.cpp at b81fdd4eab851bc28457948f53c8eccef02f09e7 · jbaileyh/geogrid · GitHub the code uses values from cost, rcov and ccov in a conditional.

Those objects were declared at geogrid/src/minimal-assignment.cpp at b81fdd4eab851bc28457948f53c8eccef02f09e7 · jbaileyh/geogrid · GitHub, however if you look at the Armadillo documentation you will see that when calling the constructor with only the size as the code does the memory is not initialized.

vec(size(X)) (memory is not initialised)

So you change the declarations to call with two arguments where the second argument is the default value, maybe 0 is appropriate?

Thanks for suggesting this and for pointing me to the Armadillo docs. There are lots of options for initialising the memory as suggested (potentially relevant ones below):

|fill::zeros| = |set all elements to 0|
|fill::ones| = |set all elements to 1|
|fill::none| = |do not modify the elements|

When trying to supply a default value, I don't think it expects one:

devtools::check() returns:

minimal-assignment.cpp:434:15: error: no matching constructor for initialization of 'arma::mat' (aka 'Mat<double>')
    arma::mat cost(input_cost, 0);

I think this suggests that it won't take additional arguments such as the fill_value outlined here see: mat(size(X), fill_type) (memory is initialised).

Apologies if this is obvious and thanks for the help.

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