Note that there are some explanatory texts on larger screens.

plurals
  1. POC adding array elements cause segmentation fault
    primarykey
    data
    text
    <p>I have read several forums but can't find the solution to this.</p> <p><code></p> <pre><code>int sIndex = 3; char serverArgs[serverCommandCount + 3][20]; strcpy(serverArgs[0], "ant"); strcpy(serverArgs[1], "-f"); strcpy(serverArgs[2], "/dev/server1/trunk/build.xml"); if(serverStop){strcpy(serverArgs[sIndex], "jboss-stop"); sIndex++;} if(serverClean){strcpy(serverArgs[sIndex], "clean"); sIndex++;} if(serverDeploy){strcpy(serverArgs[sIndex], "deploy"); sIndex++;} if(releaseDB){strcpy(serverArgs[sIndex], "releasedb"); sIndex++;} if(createDB){strcpy(serverArgs[sIndex], "createdb"); sIndex++;} if(serverStart){strcpy(serverArgs[sIndex], "jboss-start"); sIndex++;} if(serverDebug){strcpy(serverArgs[sIndex], "jboss-start-debug"); sIndex++;} execv(antEx, serverArgs); </code></pre> <p></code> In this solution the problem is the execv wanting a char *[ ] rather than a char[ ]. </p> <p><code></p> <pre><code>int sIndex = 3; char *serverArgs[serverCommandCount + 3]; for(index = 0; index &lt; serverCommandCount + 3; index++) serverArgs[index] = malloc(20); strcpy(serverArgs[0], "ant"); strcpy(serverArgs[1], "-f"); strcpy(serverArgs[2], "/dev/server1/trunk/build.xml"); if(serverStop){strcpy(serverArgs[sIndex], "jboss-stop"); sIndex++;} if(serverClean){strcpy(serverArgs[sIndex], "clean"); sIndex++;} if(serverDeploy){strcpy(serverArgs[sIndex], "deploy"); sIndex++;} if(releaseDB){strcpy(serverArgs[sIndex], "releasedb"); sIndex++;} if(createDB){strcpy(serverArgs[sIndex], "createdb"); sIndex++;} if(serverStart){strcpy(serverArgs[sIndex], "jboss-start"); sIndex++;} if(serverDebug){strcpy(serverArgs[sIndex], "jboss-start-debug"); sIndex++;} execv(antEx, serverArgs); </code></pre> <p></code></p> <p>When I try it this way, I get a segmentation fault when it tries to execute <code></p> <p>strcpy(serverArgs[1], "-f");</p> <p></code></p> <p>What am I missing?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload