Char array corrupted after passing through ONC RPC
<p>when calling a ONC-RPC-function that returns a char array I get (apparently) uninitialized memory on the first call. Subsequent calls give me the correct result.</p>

<p>This example showcases the issue:</p>

<p>ftp.x:</p>

<pre><code>const BLOCKSIZE = 1024;

struct block {
    char arr&lt;BLOCKSIZE&gt;;
};

program FILE_GET_BLOCK_PROG {
    version FILE_GET_BLOCK_VERS {
        block FILE_GET_BLOCK() = 1;
    } = 1;
} = 0x42424243;
</code></pre>

<p>ftp_client.c:</p>

<pre><code>#include "ftp.h"

#include &lt;errno.h&gt;
#include &lt;string.h&gt;

size_t
file_get_block_prog_1(char *host, char *buf)
{
    CLIENT *clnt;
    block  *result_1;

#ifndef DEBUG
    clnt = clnt_create (host, FILE_GET_BLOCK_PROG, FILE_GET_BLOCK_VERS, "udp");
    if (clnt == NULL) {
        clnt_pcreateerror (host);
        exit (1);
    }
#endif  /* DEBUG */

    result_1 = file_get_block_1(NULL, clnt);
    if (result_1 == (block *) NULL) {
        clnt_perror (clnt, "call failed");
    }
#ifndef DEBUG
    clnt_destroy (clnt);
#endif   /* DEBUG */

    memcpy(buf, result_1-&gt;arr.arr_val, result_1-&gt;arr.arr_len);
    return result_1-&gt;arr.arr_len;
}

int
main (int argc, char *argv[])
{
    char *host, *source_filename;
    char buf[BLOCKSIZE+1];
    int block_count;
    size_t bytes_read;

    if (argc &lt; 2) {
        printf ("usage: %s server_host\n", argv[0]);
        exit (1);
    }
    host = argv[1];

    bytes_read = file_get_block_prog_1 (host, buf);
    buf[bytes_read] = '\0';
    printf("%d bytes:\n%s\n", bytes_read, buf);
    exit (0);
}
</code></pre>

<p>ftp_server.c:</p>

<pre><code>#include "ftp.h"

#include &lt;errno.h&gt;
#include &lt;string.h&gt;
#include &lt;sys/stat.h&gt;

block *
file_get_block_1_svc(void *argp, struct svc_req *rqstp)
{
    static block  result;
    static int request = 1;
    char buf[BLOCKSIZE+1];
    size_t bytes_read;

    strcpy(buf, "This is just a simple test block. There is nothing relevant in here.");

    result.arr.arr_len = strlen(buf);
    result.arr.arr_val = buf;
    printf("Request #%d:\n%s\n", request++, buf);

    return &amp;result;
}
</code></pre>

<p>When running the server and calling the client twice, this is my output:
client:</p>

<pre><code>$ ./ftp_client localhost
68 bytes:

$ ./ftp_client localhost
68 bytes:
This is just a simple test bock. There is nothing relevant in here.
</code></pre>

<p>server:</p>

<pre><code>Request #1:
This is just a simple test bock. There is nothing relevant in here.
Request #2:
This is just a simple test bock. There is nothing relevant in here.
</code></pre>

<p>Is there any initialization I missed that I need to do before the first request? What else would cause this behavior?</p>