This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pass by value and also snprintf()


On 04/27/2015 10:37 AM, Bruce Korb wrote:
> int
> main(int argc, char ** argv)
> {
>         char       buffer[0x1000];
>         size_t     bufsz  = sizeof(buffer);
>         char const fmt[]  = "Allocated sblock_id=%d for band_id=%d\n";
>         int32_t    sblock = 1;
>         int32_t    band   = 1;
>         void *     fn     = sprintf;
...
>         void * values[5] = {
>                 [0] = buffer,
>                 [1] = &bufsz,
>                 [2] = UCONST(fmt),
>                 [3] = &sblock,
>                 [4] = &band };

That would be because you're passing buffer and fmt instead of a pointer to
buffer and fmt.  You need to do

        char *     buffer_p = buffer;
        const char *fmt_p = fmt;

        void * values[5] = {
                [0] = &buffer_p,
                [1] = &bufsz,
                [2] = &fmt_p,
                [3] = &sblock,
                [4] = &band };

One of the many peculiarities of the libffi api...


r~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]