From: <hez...@us...> - 2009-08-05 15:18:05
|
Revision: 10215 http://plplot.svn.sourceforge.net/plplot/?rev=10215&view=rev Author: hezekiahcarty Date: 2009-08-05 15:17:56 +0000 (Wed, 05 Aug 2009) Log Message: ----------- Fix a string-handling segfault in the custom label support Modified Paths: -------------- trunk/doc/docbook/src/api.xml trunk/examples/c/x19c.c trunk/include/plplot.h trunk/include/plstrm.h trunk/src/plbox.c Modified: trunk/doc/docbook/src/api.xml =================================================================== --- trunk/doc/docbook/src/api.xml 2009-08-05 02:28:55 UTC (rev 10214) +++ trunk/doc/docbook/src/api.xml 2009-08-05 15:17:56 UTC (rev 10215) @@ -11914,14 +11914,14 @@ <varlistentry> <term> <parameter>label_func</parameter> - (<literal>void (*) (PLINT, PLFLT, const char *, void *)</literal>, input) + (<literal>void (*) (PLINT, PLFLT, char *, PLINT, void *)</literal>, input) </term> <listitem> <para> This is the custom label function. In order to reset to the default labeling, set this to <literal>NULL</literal>. The - <literal>const char*</literal> argument should be set to point to - the appropriate label text. + <literal>char*</literal> argument should be set to the appropriate + label text. </para> </listitem> </varlistentry> Modified: trunk/examples/c/x19c.c =================================================================== --- trunk/examples/c/x19c.c 2009-08-05 02:28:55 UTC (rev 10214) +++ trunk/examples/c/x19c.c 2009-08-05 15:17:56 UTC (rev 10215) @@ -48,9 +48,8 @@ /* A custom axis labeling function for longitudes and latitudes. */ void -geolocation_labeler(PLINT axis, PLFLT value, const char *label, PLPointer data) { +geolocation_labeler(PLINT axis, PLFLT value, char *label, PLINT length, PLPointer data) { const char *direction_label; - char *custom_label; PLFLT label_val; if (axis == PL_Y_AXIS) { @@ -79,12 +78,11 @@ } if (axis == PL_Y_AXIS && value == 0.0) { /* A special case for the equator */ - sprintf(custom_label, "%s", direction_label); + snprintf(label, length, "%s", direction_label); } else { - sprintf(custom_label, "%.0f%s", fabs(label_val), direction_label); + snprintf(label, length, "%.0f%s", fabs(label_val), direction_label); } - label = custom_label; } /*--------------------------------------------------------------------------*\ Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2009-08-05 02:28:55 UTC (rev 10214) +++ trunk/include/plplot.h 2009-08-05 15:17:56 UTC (rev 10215) @@ -781,7 +781,7 @@ /* Setup a user-provided custom labeling function */ PLDLLIMPEXP void -c_plslabelfunc(void (*label_func)(PLINT, PLFLT, const char *, PLPointer), +c_plslabelfunc(void (*label_func)(PLINT, PLFLT, char *, PLINT, PLPointer), PLPointer label_data); /* Calculate world coordinates and subpage from relative device coordinates. */ Modified: trunk/include/plstrm.h =================================================================== --- trunk/include/plstrm.h 2009-08-05 02:28:55 UTC (rev 10214) +++ trunk/include/plstrm.h 2009-08-05 15:17:56 UTC (rev 10215) @@ -656,7 +656,7 @@ PLINT xdigmax, ydigmax, zdigmax; PLINT xdigits, ydigits, zdigits; char *timefmt; - void (*label_func)(PLINT, PLFLT, const char *, PLPointer); + void (*label_func)(PLINT, PLFLT, char *, PLINT, PLPointer); PLPointer label_data; /* Variables governing physical coordinate system */ Modified: trunk/src/plbox.c =================================================================== --- trunk/src/plbox.c 2009-08-05 02:28:55 UTC (rev 10214) +++ trunk/src/plbox.c 2009-08-05 15:17:56 UTC (rev 10215) @@ -1400,12 +1400,9 @@ static void plform(PLINT axis, PLFLT value, PLINT scale, PLINT prec, char *string, PLINT len, PLBOOL ll, PLBOOL lf, PLBOOL lo) { - const char *custom_string; - /* Check to see if a custom labeling function is defined. If not, */ if (lo && plsc->label_func) { - (*plsc->label_func)(axis, value, custom_string, plsc->label_data); - snprintf(string, len, "%s", custom_string); + (*plsc->label_func)(axis, value, string, len, plsc->label_data); } else { if (lo) { @@ -1491,7 +1488,7 @@ * \*--------------------------------------------------------------------------*/ void -c_plslabelfunc(void (*label_func)(PLINT, PLFLT, const char *, PLPointer), PLPointer label_data) +c_plslabelfunc(void (*label_func)(PLINT, PLFLT, char *, PLINT, PLPointer), PLPointer label_data) { plsc->label_func = label_func; plsc->label_data = label_data; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |