On 8 July 2016 at 11:21, Tobias Ellinghaus <m...@houz.org> wrote:
> On Donnerstag, 7. Juli 2016 19:43:04 CEST Erwin Burema wrote:
> > Hi,
> >
> > I tried to use darktable-chart with a 'fake' chart (generated in
> argyllcms
> > with printarg added a gradient by hand) so I could experiment with
> haldclut
> > (which I applied via GIMP+G'MIC to this chart) and the generated styles.
> > Now when running the generated CSV file to darktable-chart I got a
> SIGSEGV
> > which I tracked down to line 150 in thinplate.c, the following patch is
> my
> > fix to this.
>
> Could you please attach the patch as a separate file? It seems that the
> mail
> program mangled a few lines so it doesn't apply cleanly. Best would be to
> use
> git format-patch.
>
Forgot to reply to all, so here patch as attachment to full mailinglist
>
> > Regards,
> >
> > Erwin Burema
>
> Tobias
>
> [diff]
___________________________________________________________________________
darktable developer mailing list
to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org
From 2c2e14f217a88721879c7a077c51b7e56b1cef30 Mon Sep 17 00:00:00 2001
From: Erwin Burema <e.bur...@gmail.com>
Date: Thu, 7 Jul 2016 19:20:33 +0200
Subject: [PATCH 1/1] Fixed SIGSEGV when using chart whit lots of patches,
changed to explicit malloc
---
src/chart/thinplate.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/src/chart/thinplate.c b/src/chart/thinplate.c
index c5ff0a9..fe8e2f1 100644
--- a/src/chart/thinplate.c
+++ b/src/chart/thinplate.c
@@ -30,6 +30,7 @@
#include <float.h>
#include <string.h>
#include <assert.h>
+#include <stdlib.h>
// #define REPLACEMENT // either broken code or doesn't help at all
// #define EXACT // use full solve instead of dot in inner loop
@@ -147,7 +148,7 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
// permutation[dim]
{
const int wd = N + 4;
- double A[wd * wd];
+ double *A = malloc(wd * wd * sizeof(double));
// construct system matrix A such that:
// A c = f
//
@@ -196,7 +197,11 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
{
const int sparsity = MIN(s, S);
#ifndef REPLACEMENT
- if(patches >= S - 4) return sparsity;
+ if(patches >= S - 4)
+ {
+ free(A);
+ return sparsity;
+ }
assert(sparsity < S + 4);
#endif
// find (sparsity+1)-th column a_m by m = argmax_t{ a_t^t r . norm_t}
@@ -217,7 +222,11 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
for(int i = 0; i <= sparsity; i++)
for(int j = 0; j < wd; j++) As[j * S + i] = A[j * wd + permutation[i]];
- if(solve(As, w, v, b[ch], coeff[ch], wd, sparsity, S)) return sparsity;
+ if(solve(As, w, v, b[ch], coeff[ch], wd, sparsity, S))
+ {
+ free(A);
+ return sparsity;
+ }
// compute tentative residual:
// r = b - As c
@@ -274,7 +283,11 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
for(int i = 0; i < sparsity; i++)
for(int j = 0; j < wd; j++) As[j * S + i] = A[j * wd + permutation[i]];
- if(solve(As, w, v, b[ch], coeff[ch], wd, sparsity-1, S)) return s;
+ if(solve(As, w, v, b[ch], coeff[ch], wd, sparsity-1, S))
+ {
+ free(A);
+ return s;
+ }
// compute tentative residual:
// r = b - As c
@@ -340,7 +353,11 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
for(int j = 0; j < wd; j++) As[j * S + i] = A[j * wd + permutation[i]];
// on error, return last valid configuration
- if(solve(As, w, v, b[ch], coeff[ch], wd, sp, S)) return sparsity;
+ if(solve(As, w, v, b[ch], coeff[ch], wd, sp, S))
+ {
+ free(A);
+ return sparsity;
+ }
// compute new residual:
// r = b - As c
@@ -364,6 +381,7 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this (
// if(err < 2.0) return sparsity+1;
olderr = err;
}
+ free(A);
return -1;
}
--
2.7.4