Skip to content

Commit

Permalink
[Trifocal+P2Pt] Fix buffer overlow - clean memleak test
Browse files Browse the repository at this point in the history
  • Loading branch information
rfabbri committed Nov 18, 2023
1 parent 4811c3b commit 2e52031
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions minus/chicago14a-HxH.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ HxH(const C<F>* __restrict ux /*x and t*/, const C<F> * __restrict uparams, C<F>
static constexpr F C0 = 1.;
static constexpr F C1 = -1.;
static constexpr F C2 = 2.;
static constexpr F C3 = 0.;
// static constexpr F C3 = 0.;
const C<F> G0 = C1 * t;
const C<F> G1 = C0 + G0;
const C<F> G2 = G1 * X15;
Expand Down Expand Up @@ -3321,7 +3321,7 @@ HxH_constants(const C<F>* __restrict ux /*x and t*/, const C<F> * __restrict upa
static constexpr F C0 = 1.;
static constexpr F C1 = -1.;
static constexpr F C2 = 2.;
static constexpr F C3 = 0.;
// static constexpr F C3 = 0.;
const C<F> G0 = C1 * t;
const C<F> G1 = C0 + G0;
const C<F> G2 = G1 * X15;
Expand Down Expand Up @@ -6526,7 +6526,7 @@ HxH_constants_all_sols(const C<F>* __restrict ux /*x and t*/, const C<F> * __res
static constexpr F C0 = 1.;
static constexpr F C1 = -1.;
static constexpr F C2 = 2.;
static constexpr F C3 = 0.;
// static constexpr F C3 = 0.;
const C<F> G0 = C1 * t;
const C<F> G1 = C0 + G0;
const C<F> G2 = G1 * X15;
Expand Down
4 changes: 2 additions & 2 deletions minus/chicago14a-Hxt.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Hxt(const C<F> * __restrict ux, const C<F> * __restrict uparams, C<F> * __restri
static constexpr F C0 = 1.;
static constexpr F C1 = -1.;
static constexpr F C2 = 2.;
static constexpr F C3 = 0.;
// static constexpr F C3 = 0.;
const C<F> G0 = -t;
const C<F> G1 = C0 + G0; // Packet2cd G1G3 = pload(G1G3); // Use Eigen arrays for AVX/SSE
const C<F> G2 = G1 * X15;
Expand Down Expand Up @@ -3938,7 +3938,7 @@ Hxt_constants(const C<F> * __restrict ux, const C<F> * __restrict uparams, C<F>
static constexpr F C0 = 1.;
static constexpr F C1 = -1.;
static constexpr F C2 = 2.;
static constexpr F C3 = 0.;
// static constexpr F C3 = 0.;
const C<F> G0 = -t;
const C<F> G1 = C0 + G0; // Packet2cd G1G3 = pload(G1G3); // Use Eigen arrays for AVX/SSE
const C<F> G2 = G1 * X15;
Expand Down
4 changes: 2 additions & 2 deletions minus/internal-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ struct minus_array { // Speed critical -----------------------------------------
}

static inline __attribute__((always_inline)) void
fadd_to_self(C<F> * __restrict a, const C<F> * __restrict b)
fadd_to_self(F * __restrict a, F * __restrict b)
{
for (unsigned int i=0; i < N+1; ++i,++a,++b) *a += *b;
for (unsigned int i=0; i < 2*N+1; ++i,++a,++b) *a += *b;
}

static inline __attribute__((always_inline)) void
Expand Down
7 changes: 4 additions & 3 deletions minus/minus.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ track(const track_settings &s, const C<F> s_sols_u[f::nve*f::nsols], const C<F>
C<F> *const dxdt = (C<F> *) dxdtf;
C<F> *const x0 = x0t0;
F *const t0 = (F *) (x0t0 + f::nve);
F *const t = (F *) (xt + f::nve);
C<F> *const x1t1 = xt;
C<F> *const dx = dxdt;
C<F> *const dx4 = dx;
Expand Down Expand Up @@ -169,7 +170,7 @@ track(const track_settings &s, const C<F> s_sols_u[f::nve*f::nsols], const C<F>

v::add_to_self(xt, dx4);
v::multiply_scalar_to_self(dx4, 2.);
xt[f::nve] += one_half_dt; // t0+.5dt
*t += one_half_dt; // t0+.5dt
evaluate_Hxt(xt, params, Hxt);
memoize_Hxt<P,F>(Hxt);/*, ycHxt);*/
lsolve<P,F>(AA, dxi);
Expand All @@ -190,7 +191,7 @@ track(const track_settings &s, const C<F> s_sols_u[f::nve*f::nsols], const C<F>
v::add_to_self(xt, dxi);
v::multiply_scalar_to_self(dxi, 2.);
v::add_to_self(dx4, dxi);
xt[f::nve] = *t0 + *dt; // t0+dt
*t = *t0 + *dt; // t0+dt
evaluate_Hxt(xt, params, Hxt);
memoize_Hxt<P,F>(Hxt);/*, ycHxt);*/
lsolve<P,F>(AA, dxi);
Expand All @@ -203,7 +204,7 @@ track(const track_settings &s, const C<F> s_sols_u[f::nve*f::nsols], const C<F>

// make prediction
v::fcopy(x0t0, x1t1);
v::fadd_to_self(x1t1, dxdt);
v::fadd_to_self((double *)x1t1, (double *)dxdt);


/// CORRECTOR ///
Expand Down

0 comments on commit 2e52031

Please sign in to comment.