fix segmentaion fault in CMDList
This commit is contained in:
parent
d99ad2ad6d
commit
b350e78f7d
@ -53,13 +53,11 @@ int CMDList_add(CMDList_t *list, CMD_t* cmd)
|
||||
|
||||
if (*list_p == NULL)
|
||||
{ // it does not point to another list
|
||||
printf("create new sub list\n");
|
||||
// allocate a new list for it
|
||||
*list_p = CMDList_init();
|
||||
if (list_p == NULL)
|
||||
{ // allocation faild (memory full?)
|
||||
returnCode = -2;
|
||||
printf("ERROR: failt to init CMDList\n");
|
||||
}
|
||||
|
||||
// update list_p for the next list
|
||||
@ -67,14 +65,12 @@ int CMDList_add(CMDList_t *list, CMD_t* cmd)
|
||||
}
|
||||
else
|
||||
{ // it points to an other list
|
||||
printf("move to sub list\n");
|
||||
// update pointer to this list
|
||||
list_p = (CMDList_t**)(*list_p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // invalid caracter
|
||||
printf("invaled char\n");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -82,14 +78,17 @@ int CMDList_add(CMDList_t *list, CMD_t* cmd)
|
||||
read_p += 1;
|
||||
}
|
||||
|
||||
printf("return code: %i\n", returnCode);
|
||||
if (returnCode >= 0)
|
||||
{ // no errors
|
||||
|
||||
if (((CMDList_t*)list_p)->cmd != NULL)
|
||||
{ // replacing a command
|
||||
returnCode = 1;
|
||||
}
|
||||
// add command in it's spot
|
||||
(**list_p).cmd = cmd;
|
||||
((CMDList_t*)list_p)->cmd = cmd;
|
||||
}
|
||||
|
||||
printf("return code: %i\n", returnCode);
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
@ -109,37 +108,7 @@ CMD_t* CMDList_get(CMDList_t *list, char* cmd)
|
||||
{ // valid character
|
||||
|
||||
// get memory address of the caracter in the CMDList
|
||||
// list_p += (c - 'A') * sizeof(CMDList_t*);
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 'A': list_p = list_p->a; break;
|
||||
case 'B': list_p = list_p->b; break;
|
||||
case 'C': list_p = list_p->c; break;
|
||||
case 'D': list_p = list_p->d; break;
|
||||
case 'E': list_p = list_p->e; break;
|
||||
case 'F': list_p = list_p->f; break;
|
||||
case 'G': list_p = list_p->g; break;
|
||||
case 'H': list_p = list_p->h; break;
|
||||
case 'I': list_p = list_p->i; break;
|
||||
case 'J': list_p = list_p->j; break;
|
||||
case 'K': list_p = list_p->k; break;
|
||||
case 'L': list_p = list_p->l; break;
|
||||
case 'M': list_p = list_p->m; break;
|
||||
case 'N': list_p = list_p->n; break;
|
||||
case 'O': list_p = list_p->o; break;
|
||||
case 'P': list_p = list_p->p; break;
|
||||
case 'Q': list_p = list_p->q; break;
|
||||
case 'R': list_p = list_p->r; break;
|
||||
case 'S': list_p = list_p->s; break;
|
||||
case 'T': list_p = list_p->t; break;
|
||||
case 'U': list_p = list_p->u; break;
|
||||
case 'V': list_p = list_p->v; break;
|
||||
case 'W': list_p = list_p->w; break;
|
||||
case 'X': list_p = list_p->x; break;
|
||||
case 'Y': list_p = list_p->y; break;
|
||||
case 'Z': list_p = list_p->z; break;
|
||||
}
|
||||
list_p += (c - 'A');
|
||||
|
||||
if (*((CMDList_t**)list_p) == NULL)
|
||||
{ // no command found
|
||||
@ -165,12 +134,17 @@ CMD_t* CMDList_get(CMDList_t *list, char* cmd)
|
||||
if (list_p->cmd == NULL)
|
||||
{ // command incomplete
|
||||
found = false;
|
||||
cmd_object = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd_object = list_p->cmd;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd_object = NULL;
|
||||
}
|
||||
|
||||
return cmd_object;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user