Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
edited title
Source Link
Jabberwocky
  • 51.3k
  • 18
  • 71
  • 127

Why do iI get a Run-Time Check Failure #2 (completely Beginner)

Im new to C Programming and the Windows API im getting "Run-Time Check Failure #2 - Stack around the variable 'pMyStringAdress' was corrupted." after compilation in Visual Studio

Thats my code:

#include <stdio.h>
#include <Windows.h>
#include <string.h>

char MyStrings[] = {
    "ich bin ein text"
};
text";

int main() {
     
    SIZE_T SizeMyStrings = sizeof(MyStrings);

    PVOID pMyStringAdress = VirtualAlloc(
        NULL,
        SizeMyStrings,
        MEM_COMMIT | MEM_RESERVE,
        PAGE_READWRITE
    );

    if (pMyStringAdress == NULL) {
        printf("VirtualAlloc fehlgeschlagen mit fehlercode %d", GetLastError());
    }
    else {
        printf("Speicher erfolgreich allokiert sitzt bei: %p\n", &pMyStringAdress);
    }

    printf("Probiere in den Speicher zu schreiben.");
 
    memcpy(&pMyStringAdress, MyStrings, SizeMyStrings);
    
    return 0;
}

Why do i get a Run-Time Check Failure #2 (completely Beginner)

Im new to C Programming and the Windows API im getting "Run-Time Check Failure #2 - Stack around the variable 'pMyStringAdress' was corrupted." after compilation in Visual Studio

Thats my code:

#include <stdio.h>
#include <Windows.h>
#include <string.h>

char MyStrings[] = {
    "ich bin ein text"
};


int main() {
     
    SIZE_T SizeMyStrings = sizeof(MyStrings);

    PVOID pMyStringAdress = VirtualAlloc(
        NULL,
        SizeMyStrings,
        MEM_COMMIT | MEM_RESERVE,
        PAGE_READWRITE
    );

    if (pMyStringAdress == NULL) {
        printf("VirtualAlloc fehlgeschlagen mit fehlercode %d", GetLastError());
    }
    else {
        printf("Speicher erfolgreich allokiert sitzt bei: %p\n", &pMyStringAdress);
    }

    printf("Probiere in den Speicher zu schreiben.");
 
    memcpy(&pMyStringAdress, MyStrings, SizeMyStrings);
    
    return 0;
}

Why do I get a Run-Time Check Failure #2

Im new to C Programming and the Windows API im getting "Run-Time Check Failure #2 - Stack around the variable 'pMyStringAdress' was corrupted." after compilation in Visual Studio

Thats my code:

#include <stdio.h>
#include <Windows.h>
#include <string.h>

char MyStrings[] = "ich bin ein text";

int main() {    
    SIZE_T SizeMyStrings = sizeof(MyStrings);

    PVOID pMyStringAdress = VirtualAlloc(
        NULL,
        SizeMyStrings,
        MEM_COMMIT | MEM_RESERVE,
        PAGE_READWRITE
    );

    if (pMyStringAdress == NULL) {
        printf("VirtualAlloc fehlgeschlagen mit fehlercode %d", GetLastError());
    }
    else {
        printf("Speicher erfolgreich allokiert sitzt bei: %p\n", &pMyStringAdress);
    }

    printf("Probiere in den Speicher zu schreiben.");
    memcpy(&pMyStringAdress, MyStrings, SizeMyStrings);
    return 0;
}
Source Link

Why do i get a Run-Time Check Failure #2 (completely Beginner)

Im new to C Programming and the Windows API im getting "Run-Time Check Failure #2 - Stack around the variable 'pMyStringAdress' was corrupted." after compilation in Visual Studio

Thats my code:

#include <stdio.h>
#include <Windows.h>
#include <string.h>

char MyStrings[] = {
    "ich bin ein text"
};


int main() {
    
    SIZE_T SizeMyStrings = sizeof(MyStrings);

    PVOID pMyStringAdress = VirtualAlloc(
        NULL,
        SizeMyStrings,
        MEM_COMMIT | MEM_RESERVE,
        PAGE_READWRITE
    );

    if (pMyStringAdress == NULL) {
        printf("VirtualAlloc fehlgeschlagen mit fehlercode %d", GetLastError());
    }
    else {
        printf("Speicher erfolgreich allokiert sitzt bei: %p\n", &pMyStringAdress);
    }

    printf("Probiere in den Speicher zu schreiben.");

    memcpy(&pMyStringAdress, MyStrings, SizeMyStrings);
    
    return 0;
}