memory - Segmentation fault on memcpy in C -


I am working on a small project where I am trying to declare a CPU and tell the values ​​of variables I am good, so far. So I have defined the following structures for my CPU and memory.

CPU (can only keep track of 3 variables)

  typedef struct variableReference {char * tag; Zero * references; } VariableReference; Typedef Structure CPU {int variableCounter; Int indication indicator; Variable reference datacassion [3]; Zero * currentContext; } CPU;  

Memory (and this is the creation function). By the way, CPU.currentContext indicates memory.base, then it can change.

  typedef struct memory {zero * base; Integer shape; }remember; Memory memory (full size) {memory pneumatic; NewMemory.base = malloc (size); NewMemory.size = Size; Return new memory; }  

So the first thing I do is allocate a block of memory and keep track of it using the CPU current reference pointer. I already have a function that tells the CPU to declare a variable (variables can only be integers) and the second one which assigns the value to the CPU to the variable. To do this, I monitor a limited amount of variable names and references in cpu.dataDictionary.

The variable works just fine to declare, but the problem occurs when I try to assign a value to that variable, which I do (like A = 4;):

  cpu_assignVariable (& myCPU, "a", 4, and myMemi); At that time, this first record in my cpu.dataDictionary is {"a", 0x804b008}, so all I should have had to check that condition in the allocated memory block, and copy the value (integer 4), such as :  
  zero * reference = cpu_dereferenceVariable (* myCPU, tags); // becomes a memory_write address (context, 1, size (value), (zero *) value); // write value  

Now the memory_litech implementation, where I get a segmentation fault (I have 1 offset because because I wrote the first variable name on the "reference" status:

int memory_write (zero * base, integer offset, integer size, zero * value) {memcpy (base + offset, value, size); return 0;}

I hope the memory block will look like this: | one | 0 | 0 | 0 | 4 | x | x | ... | x | but I found a split error error. Any thoughts ???

Thanks in advance!


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -