Note that there are some explanatory texts on larger screens.

plurals
  1. POStack Smashing Detected. C programming
    primarykey
    data
    text
    <p>i'm trying to run a C program. It seems to work fine, but at the end it shows:</p> <p>STACK SMASHING DETECTED</p> <p>This is the code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt; extern int errno; int main(int argc, char *argv[]){ /*Para pasar argumentos a la funcion main*/ char id[7]="\0"; char orden[10]="\0"; char arg[3]="\0"; char idhijo[7]="\0"; char ordenhijo[10]="\0"; char arghijo[3]="\0"; int i=0, j=0, k=0; int a=1, pipe1[2], pipe2[2], control, argument=0, status, posx=50, posy=50, s, t, arg_val=0, orden_val=0; FILE *fichero; char mensaje1[4], mensaje2[4], mensaje3[6]; char posxpadre[4]="50", posypadre[4]="50", hijoPID[4]; system("clear"); control = pipe(pipe1); if(control !=0){ perror("pipe1"); exit(errno); } control = pipe(pipe2); if(control !=0){ perror("pipe2"); exit(errno); } control = fork(); fichero=fopen(argv[1], "r"); if (fichero){ while((i != EOF) &amp;&amp; (j != EOF) &amp;&amp; (k != EOF)){ if((i != EOF) &amp;&amp; (j != EOF) &amp;&amp; (k != EOF)){ if (control ==-1){ perror("fork"); exit(errno); } if (control !=0){ k=fscanf(fichero, "%s", id); i=fscanf(fichero, "%s", orden); j=fscanf(fichero, "%s", arg); if(Robot_valido(id)){ write(pipe1[1], id, 7); write(pipe1[1], arg, 3); write(pipe1[1], posxpadre, 4); write(pipe1[1], posypadre, 4); write(pipe1[1], orden, 10); read(pipe2[0], posxpadre, 4); read(pipe2[0], hijoPID, 6); read(pipe2[0], posypadre, 4); printf("Hijo con PID %s desplazo el robot a la posicion: (%s, %s)\n\n", hijoPID, posxpadre, posypadre); } } else{ read(pipe1[0], idhijo, 7); read(pipe1[0], arghijo, 3); read(pipe1[0], posxpadre, 4); read(pipe1[0], posypadre, 4); read(pipe1[0], ordenhijo, 10); if (Robot_valido(idhijo)!=0){ Orden_valida(ordenhijo, arghijo, &amp;orden_val, &amp;arg_val); if (orden_val !=0 &amp;&amp; arg_val !=0){ argument=atoi(arghijo); posy=atoi(posypadre); posx=atoi(posxpadre); if (strcmp(ordenhijo, "arriba")==0){ if (posy&gt;1){ while (argument &gt; 0){ if (posy&gt;0){ posy--; argument--; } else{ argument=0; } } } } if (strcmp(ordenhijo, "abajo")==0){ if (posy&lt;100){ while (argument &gt; 0){ if (posy&lt;100){ posy++; argument--; } else{ argument=0; } } } } if (strcmp(ordenhijo, "derecha")==0){ if (posx&lt;100){ while (argument &gt; 0){ if (posx&lt;100){ posx++; argument--; } else{ argument=0; } } } } if (strcmp(ordenhijo, "izquierda")==0){ if (posx&gt;0){ while (argument &gt; 0){ if (posx&gt;0){ posx--; argument--; } else{ argument=0; } } } } printf("Robot desplazado hasta la posicion: (%d, %d)\n", posx, posy); sprintf(mensaje1, "%d", posx); sprintf(mensaje2, "%d", posy); sprintf(mensaje3, "%d", getpid()); write(pipe2[1], mensaje1, 4); write(pipe2[1], mensaje3, 6); write(pipe2[1], mensaje2, 4); } } } } } close(pipe1[0]); close(pipe1[1]); close(pipe2[0]); close(pipe2[1]); } } </code></pre> <p>Does anybody know why this is happening? I've done a lot of research in Google but every possible answer i tried didn't work. Any help would be really helpful.</p> <p>Thank you all!!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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