I ran in to a problem with plcont while translating example 16 to
OCaml.  While writing the OCaml PLplot bindings I mistakenly assumed
that the plcont function would accept NULL for its pltr and pltr_data
arguments and fall back on a default transform of some sort.  However,
setting pltr to NULL gave me segmentation faults as plcont uses the
pltr callback function regardless of its value.

I have attached three small patches to this email in the hope that one
of them will be acceptable to the core developers:

plcont_doc_pltr.diff - This patch adds a note to the plcont
documentation (api.xml) stating that behavior is undefined when pltr
is NULL.

plcont_default_pltr.diff - This patch changes plcont to use pltr0 as a
callback when the pltr argument is NULL.

plcont_pltr_null_abort.diff - This patch changes plcont to abort using
plabort with an error if the pltr argument is NULL.  This is my
personal preference for a solution.

While the documentation does not say that the pltr callback can be set
to NULL for plcont, that is how (I think) all of the other plotting
functions which accept a transformation callback work.  Any of the
above 3 patches will do something to remedy this problem.  I
personally prefer the 3rd patch (plcont_pltr_null_abort.diff) because
it is less likely to surprise users with a potentially strange default
transform and it removes a source of potential segmentation faults or
other crashes.

Sincerely,
Hez

-- 
Hezekiah M. Carty
Graduate Research Assistant
University of Maryland
Department of Atmospheric and Oceanic Science
diff --git a/doc/docbook/src/api.xml b/doc/docbook/src/api.xml
index 517e0a5..3815f9b 100644
--- a/doc/docbook/src/api.xml
+++ b/doc/docbook/src/api.xml
@@ -1796,6 +1796,13 @@ from relative device coordinates,
 	    <xref linkend="contour-plots-c"/>.
 	    The transformation function should
 	    have the form given by any of &pltr0;, &pltr1;, or &pltr2;.
+            Note that unlike &plshades; and similar PLplot functions
+            which have a <literal><parameter>pltr</parameter></literal>
+            argument, plcont requires that a transformation function be
+            provided in the C interface.  There is no fallback if
+            <literal><parameter>pltr</parameter></literal> is NULL.  Leaving
+            <literal><parameter>pltr</parameter></literal> as a NULL will
+            lead to undefined behavior.
 	  </para>
 	</listitem>
       </varlistentry>
diff --git a/src/plcont.c b/src/plcont.c
index 02b574e..346ed1d 100644
--- a/src/plcont.c
+++ b/src/plcont.c
@@ -485,9 +485,17 @@ c_plcont(PLFLT **f, PLINT nx, PLINT ny, PLINT kx, PLINT lx,
     PLfGrid2 grid;
 
     grid.f = f;
-    plfcont(plf2eval2, (PLPointer) &grid,
-	    nx, ny, kx, lx, ky, ly, clevel, nlevel,
-	    pltr, pltr_data);
+    if (pltr == NULL) {
+      // If pltr is undefined, use a simple identity transformation
+      plfcont(plf2eval2, (PLPointer) &grid,
+              nx, ny, kx, lx, ky, ly, clevel, nlevel,
+              pltr0, pltr_data);
+    }
+    else {
+      plfcont(plf2eval2, (PLPointer) &grid,
+              nx, ny, kx, lx, ky, ly, clevel, nlevel,
+              pltr, pltr_data);
+    }
 }
 
 /*--------------------------------------------------------------------------*\
diff --git a/src/plcont.c b/src/plcont.c
index 02b574e..c217314 100644
--- a/src/plcont.c
+++ b/src/plcont.c
@@ -485,9 +485,15 @@ c_plcont(PLFLT **f, PLINT nx, PLINT ny, PLINT kx, PLINT lx,
     PLfGrid2 grid;
 
     grid.f = f;
-    plfcont(plf2eval2, (PLPointer) &grid,
-	    nx, ny, kx, lx, ky, ly, clevel, nlevel,
-	    pltr, pltr_data);
+    if (pltr == NULL) {
+      // If pltr is undefined, abort with an error.
+      plabort("plcont: The pltr callback must be defined");
+    }
+    else {
+      plfcont(plf2eval2, (PLPointer) &grid,
+              nx, ny, kx, lx, ky, ly, clevel, nlevel,
+              pltr, pltr_data);
+    }
 }
 
 /*--------------------------------------------------------------------------*\
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to