문제

I have the following piece of code in appPOSWebDlg.cpp:

#include "stdafx.h"
#include "afx.h"
#include <stdlib.h>
#include <Ras.h>
...

//Attribute
char            *site;
...

// Method
int readFile() {

    char * aux;
    int result;

    result = readParameter(hFile, aux);
    if (result == 0) {
        memcpy(site, aux, 256);
    } else {
        return 1;
    }
    return 0;
}

But the program stops at the memcpy line and I'm not sure why. After debugging, I can confirm that the aux parameter is being assigned correctly with the value expected. Furthermore, I even used the memcpy inside the readParameter method to assign it and had no problem. So why can't I assign that value to attribute site using the same method?

도움이 되었습니까?

해결책

Your "site" pointer is invalid. You've defined it as a pointer, but, not allocated any space for it, so, your copy command is overlaying some code. You'll need to allocated the pointer correctly by performing a "new" and a "delete" when you are done.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top