Changeset 76581ef in tol


Ignore:
Timestamp:
Sep 17, 2010, 5:18:50 PM (16 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
d979291
Parents:
84faccd
Message:

Adding error messages and avoiding invalid access in InversePermutation

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@2545 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/matrix_type/matgra.cpp

    r84faccd r76581ef  
    17391739    return;
    17401740  }
     1741//Std(BText("\nTRACE [InversePermutation] 1 n=")+pr);
     1742//Std(BText("\nTRACE [InversePermutation] 2 pr=")+pr);
     1743//Std(BText("\nTRACE [InversePermutation] 3 pc=")+pr);
    17411744  contens_.Alloc(pr,pc);
    17421745  const double* p = (const double*)P.Data().Buffer();
    17431746  double* c = (double*)contens_.GetData().GetBuffer();
     1747  for(i=0; i<n; i++)
     1748  {
     1749    c[k-1] = 0.0;   
     1750  }
    17441751  for(i=1; i<=n; i++, p++)
    17451752  {
    17461753    k = (int)(*p);
    1747     c[k-1] = i;
     1754  //Std(BText("\nTRACE [InversePermutation] 4.")+i+" k="<<k);
     1755    if(*p!=k)
     1756    {
     1757      Error(I2("Cannot apply InversePermutation to a matrix with non integer cells ",
     1758               "No se puede aplicar InversePermutation a una matriz con celdas o enteras ")+
     1759      (*p)+"!= "+k+"]");
     1760    }
     1761    else if((k<1)||(k>n))
     1762    {
     1763      Error(I2("Cannot apply InversePermutation to a matrix with cells out of range ",
     1764               "No se puede aplicar InversePermutation a una matriz con celdas fuera de rango ")+
     1765      k + "!<: [1, ..., "+n+"]");
     1766      c[k-1] = BDat::Nan();
     1767    }
     1768    else if(c[k-1]!=0.0)
     1769    {
     1770      Error(I2("Cannot apply InversePermutation to a matrix with repeated cells ",
     1771               "No se puede aplicar InversePermutation a una matriz con celdas repetidas ")+
     1772      c[k-1] + " <-> "+i+"]");
     1773    }
     1774    else
     1775    {
     1776      c[k-1] = i;
     1777    }
    17481778  //Std(BText("\n[InversePermutation] ")+k+" -> "+i)
    17491779  }
Note: See TracChangeset for help on using the changeset viewer.