Skip to content

possibly missing scope delimiters #12

Description

@conradsnicta

@MattPlumlee In the file src/linalg.cpp, within the function domultgesub_(), on lines 145 and 152, it looks like there are missing scope delimiters (curly braces), possibly leading to erroneous results.

More specifically, the missing scope delimiters in the for loops may lead to the out vector and/or the outge matrix not being constructed properly. In turn, both out and outge may contain garbage values, dependent on previous runs and/or uninitialised memory.

outerbase/src/linalg.cpp

Lines 145 to 159 in 927cf78

for (uword l = 0; l < terms.n_cols; ++l)
if(terms.at(k,l)>0) temp %= basemat.col(knotptst[l]+terms.at(k,l));
out += temp;
for (uword l = 0; l < (gest.n_elem-1); ++l) {
if(terms.at(k,hypmatch[l])>0){
tempalt.fill(a[k]);
for (uword m = 0; m < terms.n_cols; ++m)
if(terms.at(k,m)>0 && m != hypmatch[l])
tempalt %= basemat.col(knotptst[m]+terms.at(k,m));
outge.col(l) += tempalt%basematge.col(gest[l]+
terms.at(k,hypmatch[l]))-temp%basematge.col(gest[l]);
}
}

g++ 12.3.1 produces these warnings:

linalg.cpp: In function ‘void domultgesub_(arma::vec&, arma::mat&, const arma::vec&, arma::vec&, arma::vec&, const arma::umat&, const arma::uvec&, const arma::mat&, const arma::mat&, const arma::uvec&, const arma::uvec&, const arma::uword&)’:
linalg.cpp:145:3: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
  145 |   for (uword l = 0; l < terms.n_cols; ++l)
      |   ^~~
linalg.cpp:147:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
  147 |     out += temp;
      |     ^~~
linalg.cpp:152:9: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
  152 |         for (uword m = 0; m < terms.n_cols; ++m)
      |         ^~~
linalg.cpp:156:11: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
  156 |           outge.col(l) += tempalt%basematge.col(gest[l]+
      |           ^~~~~

CC @eddelbuettel

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions