Hi,
I'm having problems of accessing to continuous buffer with pointers in the struct. My purpose is to allocate
the continuous buffer and access to the buffer with the pointers in the struct.
So it seems that there is something wrong probably with getting the pointers to current_code_ptr
and new_code_ptr.
So my question is that how to assign pointers to current_code_ptr and new_code_ptr ?
The reason why I'm asking help is that I found it very usefull to have continuous buffer accessible with
pointers containing the correct offset.
You can copy paste the code below and try it.
Thanks for your help.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define CODE_LENGTH 10
typedef struct
{
char* current_code_ptr;
char* new_code_ptr;
}CHANGE_DATA_STRUCT;
int main(void)
{
char code[CODE_LENGTH] = "Hello";
CHANGE_DATA_STRUCT* change_code_ptr = malloc(sizeof(CHANGE_DATA_STRUCT) +
CODE_LENGTH +
CODE_LENGTH);
memset(change_code_ptr, 0, sizeof(CHANGE_DATA_STRUCT) + (CODE_LENGTH * 2));
/* Get pointers. Something wrong here ????? */
change_code_ptr->current_code_ptr = (char *)change_code_ptr;
/* Get the pointer to the second offset */
change_code_ptr->new_code_ptr = change_code_ptr->current_code_ptr + CODE_LENGTH;
/* Here Visuall c++ claims about the bad ptr(CXX0030: Error, expression cannot be evaluated)*/
memcpy(change_code_ptr->current_code_ptr, code, CODE_LENGTH);
memcpy(change_code_ptr->new_code_ptr, code, CODE_LENGTH);
/* The execution crashes in above line with the following message.
Unhandled exception at 0x594aedfc in testing.exe: 0xC0000005: Access violation writing location 0x0000006f. */
return 1;
}
I'm having problems of accessing to continuous buffer with pointers in the struct. My purpose is to allocate
the continuous buffer and access to the buffer with the pointers in the struct.
So it seems that there is something wrong probably with getting the pointers to current_code_ptr
and new_code_ptr.
So my question is that how to assign pointers to current_code_ptr and new_code_ptr ?
The reason why I'm asking help is that I found it very usefull to have continuous buffer accessible with
pointers containing the correct offset.
You can copy paste the code below and try it.
Thanks for your help.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define CODE_LENGTH 10
typedef struct
{
char* current_code_ptr;
char* new_code_ptr;
}CHANGE_DATA_STRUCT;
int main(void)
{
char code[CODE_LENGTH] = "Hello";
CHANGE_DATA_STRUCT* change_code_ptr = malloc(sizeof(CHANGE_DATA_STRUCT) +
CODE_LENGTH +
CODE_LENGTH);
memset(change_code_ptr, 0, sizeof(CHANGE_DATA_STRUCT) + (CODE_LENGTH * 2));
/* Get pointers. Something wrong here ????? */
change_code_ptr->current_code_ptr = (char *)change_code_ptr;
/* Get the pointer to the second offset */
change_code_ptr->new_code_ptr = change_code_ptr->current_code_ptr + CODE_LENGTH;
/* Here Visuall c++ claims about the bad ptr(CXX0030: Error, expression cannot be evaluated)*/
memcpy(change_code_ptr->current_code_ptr, code, CODE_LENGTH);
memcpy(change_code_ptr->new_code_ptr, code, CODE_LENGTH);
/* The execution crashes in above line with the following message.
Unhandled exception at 0x594aedfc in testing.exe: 0xC0000005: Access violation writing location 0x0000006f. */
return 1;
}