Stack smashing detected

Hello,

I am new to C programming. I wrote a program that does the calculation I need and in the end it saves the results to a file. Everything goes as planned, but it exits with the error?

*** stack smashing detected ***: ./Convolucao terminated
Aborted (core dumped)

Convolucao is the name of the program. I tried to find what does stack smashing means, but I found nothing!
Could someone please clarify what does it mean so I can try to solve it?

Thank you very much

Luiz

Comments

  • : Hello,
    :
    : I am new to C programming. I wrote a program that does the
    : calculation I need and in the end it saves the results to a file.
    : Everything goes as planned, but it exits with the error?
    :
    : *** stack smashing detected ***: ./Convolucao terminated
    : Aborted (core dumped)
    :
    : Convolucao is the name of the program. I tried to find what does
    : stack smashing means, but I found nothing!
    : Could someone please clarify what does it mean so I can try to solve
    : it?
    :
    : Thank you very much
    :
    : Luiz
    :
    :


    I guess it has something to do with the size of the matrix I am working with. For 8x6 matrix, all goes fine. But for 1024x1024 I get that error. However, I am freeing all malloc`d memory.
    Any guesses??

    Thx

    Luiz
  • From what I gather from Wikipedia on Stack Smashing, somewhere in your program you are writing outside the buffer.
    Perhaps a bad index for allocated memory?

    It would help if you post (the relevant parts of) your code.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • : From what I gather from Wikipedia on Stack Smashing, somewhere in
    : your program you are writing outside the buffer.
    : Perhaps a bad index for allocated memory?
    :
    Yep, and more specificially it's a buffer allocated on the stack, e.g. with something like:

    char[100] x;

    Rather than something on the heap that you've malloc'd. That should help make the hunt a little easier.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
  • Hum, so maybe I was looking in the wrong place. I will look for this kind of arrays!
    I will look for the bug tonight. Whatever the outcome, I will post back again.
    Thanks!

    Luiz
  • : Hum, so maybe I was looking in the wrong place. I will look for this
    : kind of arrays!
    : I will look for the bug tonight. Whatever the outcome, I will post
    : back again.
    : Thanks!
    :
    : Luiz
    :
    Hello Guys,

    I haven`t found a buffer with an index outside the define size. What I found out is that the error occurs when the command return (0); is executed. I run the degguber dgb and the error is:

    *** stack smashing detected ***: /media/sdb1/Arq/Ltizei/QuantiTEM/ChemicalMapping_C/Convolucao/Convolucao terminated

    Program received signal SIGABRT, Aborted.
    0x00002b9b951fecab in raise () from /lib/libc.so.6

    Do you know what it could mean?

    Thanks

    Luiz
  • I forgot to add the portion where the error occurs.

    Luiz



    cell_file = fopen("cell.txt", "w");

    for(k = 0; k < 2*delta1+1; k++)
    {
    for(l=0; l < 2*delta2+1; l++)
    {
    fprintf(cell_file,"%f ", cell[k][l]);

    }
    fprintf(cell_file, "
    ");
    }

    fclose(cell_file);


    Conv_file = fopen("Convolution.txt", "w");

    for(k = 0; k < N;k++)
    {
    for(l = 0; l < M;l++)
    {
    fprintf(Conv_file,"%f ", Convolution[k][l]);

    }
    fprintf(Conv_file, "
    ");
    }

    fclose(Conv_file);


    //freeing used memory.
    free(ImageCell);
    free(cell);
    free(Convolution);
    free(matrix);

    return (0);
  • : I forgot to add the portion where the error occurs.
    :
    : Luiz
    :
    :
    :
    : cell_file = fopen("cell.txt", "w");
    :
    : for(k = 0; k < 2*delta1+1; k++)
    : {
    : for(l=0; l < 2*delta2+1; l++)
    : {
    : fprintf(cell_file,"%f ", cell[k][l]);
    :
    : }
    : fprintf(cell_file, "
    ");
    : }
    :
    : fclose(cell_file);
    :
    :
    : Conv_file = fopen("Convolution.txt", "w");
    :
    : for(k = 0; k < N;k++)
    : {
    : for(l = 0; l < M;l++)
    : {
    : fprintf(Conv_file,"%f ", Convolution[k][l]);
    :
    : }
    : fprintf(Conv_file, "
    ");
    : }
    :
    : fclose(Conv_file);
    :
    :
    : //freeing used memory.
    : free(ImageCell);
    : free(cell);
    : free(Convolution);
    : free(matrix);
    :
    : return (0);
    :


    Oh man, you won`t believe it!
    It took me 2 days of looking at every single line, and all functions bla bla bla, to find out you were right :) In the first part of my program there is an input ( the name of the file where the data is) that is a char array. I had fixed it at array[20]. While I was testing (input test.txt) all was fine. But when I started running data, which is in an archive sowhere else I overflowed this buffer. Arrghhh. Well, at least I learned something about stack smaching.
    Thanks for your help,

    Luiz
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories