Вопрос

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