title: Overwriting memory ?Using malloc in C, when calling structure
body: <p>im having problem with allocating memory for my following structure:</p>
  
  <pre><code>    typedef struct level {
      char* raw_map;      // original string representing the level map
      char* name;         // level name
      char* description;  // level description
      char* password;     // level password
      struct level *next; // pointer to the next level
  } LEVEL;
  </code></pre>
  
  <p>My function looks like this:</p>
  
  <pre><code>LEVEL* parse_level(char* line){
  
      LEVEL *level =(LEVEL*)malloc(sizeof(LEVEL));
  
      int i=0;
  
      level-&gt;name = (char*)malloc(sizeof(level-&gt;name));
      while(line[i] != ';'){
         level-&gt;name[i]= line[i];
         i++;
      }
      level-&gt;password =(char*)malloc(sizeof(level-&gt;password));
      i++;
      while(line[i] != ';'){
         level-&gt;password[i]= line[i];
         i++;
      }
      return level;
  </code></pre>
  
  <p>So far, i have only set first two types of structure.</p>
  
  <p>I call funciton like that:</p>
  
  <pre><code>int main(){
  
      LEVEL *first = (LEVEL*)malloc(sizeof(LEVEL));
      first =  parse_level("nameoffirstlevelwillbehere;mandragoramo5000");
      printf("name: %s pass: %s\n",first-&gt;name, first-&gt;password);
  }
  </code></pre>
  
  <p>Im not sure that issue somewhere in malloc structure because im using pointers for first time in functions so i'm not sure they are placed right. When i have code like that i will have in first->name only 12 characters instead of full string until first ';'. Same happened in level->password. Thanks for help.</p>