#stack smashing deteced

11 messages · Page 1 of 1 (latest)

lilac socket
#

Hi guys i have a programm which receives 1 byte at a time from a server and writes it in a buffer and then prints it
but somewhow i get this stack smashing detected

Buffersize is 1

    int total_bytes = 0;
    int bytes_received = 0;

    while (1) {
        bytes_received = recv(socket_descriptor, buffer + total_bytes, BUFFFER, 0);

        if (bytes_received <= 0) {
            // Handle error or connection closure
            break;
        }

        if (buffer[total_bytes] == '\n') {
            buffer[total_bytes + 1] = '\0';
            break;
        }
        total_bytes++;
    }


    printf ("Nachricht erhalten: %s\n", buffer);
thin arrowBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

hazy flax
lilac socket
#

oh tanks mate

#

another question

#

    send(socket_descriptor, "VERSION 2.4\n", sizeof("VERSION 2.4"), 0);

    readFromServer(socket_descriptor, buffer);

    printf("Nachricht erhalten: %s\n", buffer);

    send(socket_descriptor, "ID 33uwj28t4xtv2\n", sizeof("ID 33uwj28t4xtv2"), 0);
#

it works

#

but my problem is

#

i send this string : VERSION 2.4\n

#

but size i specify toss end is : VERSION 2.4

#

isnt that 1 byte less?