Hi Andrew,
Andrew Ross wrote:
> Werner,
>
> Please be careful about replacing sprintf with snprintf in the examples. Not all
> compilers have snprintf available. Internally in the library we have cmake checks for
> this and define appropriate macros for platforms where snprintf is not available and a
> dummy wrapper plsnprintf which just calls sprintf.
>
Yes, you're right. I was too eager getting rid of this unsafe functions.
I'll revert it.
> These are defined in plplotP.h for internal use and are not available for users /
> examples. Your change as it stands is likely to break this example on some compilers
> including I believe Visual C++ and Borland.
>
That's the strange part - I tested these changes with Visual C++ and
Borland C++. So plplotP.h must be included somewhere.
> One option is to ensure the internal snprintf fixes are externally available. I'm not
> sure it is our role to provide this kind of additional functionality in the plplot API.
> The other option is to stick with sprintf in the examples, perhaps adding a comment to
> say that use of sprintf is discouraged, but for maximum portability we use it in our
> examples.
>
I'll revert the changes.
Regards,
Werner
> Andrew
>
> On Thu, Mar 19, 2009 at 12:03:34PM +0000, smekal@... wrote:
>
>> Revision: 9753
>> http://plplot.svn.sourceforge.net/plplot/?rev=9753&view=rev
>> Author: smekal
>> Date: 2009-03-19 12:03:33 +0000 (Thu, 19 Mar 2009)
>>
>> Log Message:
>> -----------
>> Replaced sprintf with snprintf in example 12.
>> Replaced // comment in examples 32 (not allowed in ANSI C).
>>
>> Modified Paths:
>> --------------
>> trunk/examples/c/x12c.c
>> trunk/examples/c/x32c.c
>>
>> Modified: trunk/examples/c/x12c.c
>> ===================================================================
>> --- trunk/examples/c/x12c.c 2009-03-19 12:02:01 UTC (rev 9752)
>> +++ trunk/examples/c/x12c.c 2009-03-19 12:03:33 UTC (rev 9753)
>> @@ -5,6 +5,8 @@
>>
>> #include "plcdemos.h"
>>
>> +#define STRING_SIZE 20
>> +
>> void
>> plfbox(PLFLT x0, PLFLT y0);
>>
>> @@ -19,7 +21,7 @@
>> main(int argc, const char *argv[])
>> {
>> int i;
>> - char string[20];
>> + char string[STRING_SIZE];
>> PLFLT y0[10];
>>
>> static PLFLT pos[] = {0.0, 0.25, 0.5, 0.75, 1.0};
>> @@ -60,9 +62,9 @@
>> plcol1(i/9.0);
>> plpsty(0);
>> plfbox((1980. + i), y0[i]);
>> - sprintf(string, "%.0f", y0[i]);
>> + snprintf(string, STRING_SIZE, "%.0f", y0[i]);
>> plptex((1980. + i + .5), (y0[i] + 1.), 1.0, 0.0, .5, string);
>> - sprintf(string, "%d", 1980 + i);
>> + snprintf(string, STRING_SIZE, "%d", 1980 + i);
>> plmtex("b", 1.0, ((i + 1) * .1 - .05), 0.5, string);
>> }
>>
>>
>> Modified: trunk/examples/c/x32c.c
>> ===================================================================
>> --- trunk/examples/c/x32c.c 2009-03-19 12:02:01 UTC (rev 9752)
>> +++ trunk/examples/c/x32c.c 2009-03-19 12:03:33 UTC (rev 9753)
>> @@ -80,7 +80,7 @@
>> plbox("bc", 1.0, 0, "bcgnst", 0, 0);
>> pllab("Group", "Value", "#frPLplot Example 32");
>>
>> - //plscmap1l(1,5,pos,red,green,blue,NULL);
>> + /* plscmap1l(1,5,pos,red,green,blue,NULL); */
>>
>> for (i = 0; i < 10; i++) {
>> plcol1(i/9.0);
>>
>>
>> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
>>
>> ------------------------------------------------------------------------------
>> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
>> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
>> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
>> software that enables intelligent coding and step-through debugging.
>> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
>> _______________________________________________
>> Plplot-cvs mailing list
>> Plplot-cvs@...
>> https://lists.sourceforge.net/lists/listinfo/plplot-cvs
>>
>>
>
> ------------------------------------------------------------------------------
> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
> software that enables intelligent coding and step-through debugging.
> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
> _______________________________________________
> Plplot-devel mailing list
> Plplot-devel@...
> https://lists.sourceforge.net/lists/listinfo/plplot-devel
>
--
Dr. Werner Smekal
Institut fuer Allgemeine Physik
Technische Universitaet Wien
Wiedner Hauptstr 8-10
A-1040 Wien
Austria
DVR-Nr: 0005886
email: smekal@...
web: http://www.iap.tuwien.ac.at/~smekal
phone: +43-(0)1-58801-13463 (office)
+43-(0)1-58801-13469 (laboratory)
fax: +43-(0)1-58801-13499
|