On Wed, Sep 2, 2009 at 6:04 AM, Andrew Ross<andrewr...@users.sourceforge.net> wrote: > On Wed, Sep 02, 2009 at 01:06:16AM -0700, Jerry wrote: >> In example x19c.c, the callback geolocation_labeler for plslabelfunc >> has an argument named length which is used only in a call to snprintf. >> The purpose appears to be to be an input to fix the length of the >> string formed by snprintf. I can't find where this argument receives a >> value. Trying to trace the calling chain through the code seems to run >> in to a dead end pretty quickly. Alternately, how many elements is >> allocated to the output string, label? > > This argument is passed in by the user (in C) to say how long the > label string (char *label) is to prevent overruns. The output > string must be pre-allocated by the user.
The length argument is passed in by PLplot to the callback function. This length value provides the maximum strength the string can be, as Andrew said, to avoid overruns. However, the output string is allocated and freed by PLplot, not be the user. So the label text should be copied/written directly to the space pointed to by "label" (using the name from geolocation_labeler in C example 19), being careful to keep the output to no more than "length" characters/bytes. That is why snprintf is used in the example. For the OCaml bindings, since strings (and arrays, etc.) are allocated and freed automatically by the OCaml garbage collector, I use snprintf in a small C function to copy the OCaml-produced string to the PLplot-provided "label" pointer location. Any bytes past "length" are discarded by snprintf. I hope this clarifies things. If not, please let me know. Hez -- Hezekiah M. Carty Graduate Research Assistant University of Maryland Department of Atmospheric and Oceanic Science ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel