Setting uninitialized values

Uninitialized values should be set to NULL to aid in memory deallocation
at cleanup time.
This commit is contained in:
John Jones 2016-12-05 18:17:17 -05:00
parent da6490ac7f
commit a180a63160
3 changed files with 18 additions and 12 deletions

View file

@ -28,7 +28,7 @@ struct Node
unsigned char * encoded;
struct Cid * cached;
int link_ammount;
struct Link * links[];
struct Link* links[];
};
/*====================================================================================
@ -118,7 +118,7 @@ int Node_Remove_Link(char * Name, struct Node * mynode);
* @param linksz: sizeof(your cid here)
* Returns your node with the newly added link
*/
struct Node * N_Add_Link(struct Node ** mynode, struct Link * mylink, size_t linksz);
struct Node* N_Add_Link(struct Node** mynode, struct Link* mylink, size_t linksz);
/*N_Create_From_Link
* Create a node from a link

View file

@ -46,6 +46,11 @@ struct Node * Create_Empty_Node()
{
struct Node * N;
N = (struct Node *)malloc(sizeof(struct Node));
N->data_size = 0;
N->cached = NULL;
N->data = NULL;
N->encoded = NULL;
N->link_ammount = 0;
return N;
}
@ -67,16 +72,14 @@ int Node_Set_Data(struct Node * N, unsigned char * Data)
return 1;
}
/*Node_Get_Data
/***
* Gets data from a node
* @param Node: = The node you want to get data from. (unsigned char *)
* Returns data of node.
* @param Node The node you want to get data from. (unsigned char *)
* @returns data of node.
*/
unsigned char * Node_Get_Data(struct Node * N)
unsigned char* Node_Get_Data(struct Node* N)
{
unsigned char * DATA;
DATA = N->data;
return DATA;
return N->data;
}
/**
@ -93,7 +96,7 @@ int Node_Set_Cid(struct Node* N, struct Cid* cid) {
* @param Node: The node you want to copy (struct CP_Node *)
* Returns a copy of the node you wanted to copy.
*/
struct Node * Node_Copy(struct Node * CP_Node)
struct Node* Node_Copy(struct Node * CP_Node)
{
struct Node * CN;
CN = (struct Node*) malloc(sizeof(struct Node) + sizeof(struct Link) * 2);
@ -133,7 +136,7 @@ void Node_Delete(struct Node * N)
* @param Name: (char * name) searches for link with this name
* Returns the link struct if it's found otherwise returns NULL
*/
struct Link * Node_Get_Link(struct Node * N, char * Name)
struct Link* Node_Get_Link(struct Node * N, char * Name)
{
struct Link * L;
for(int i=0;i<N->link_ammount;i++)
@ -218,6 +221,9 @@ struct Node * N_Create_From_Link(struct Link * mylink)
mynode->link_ammount = 0;
mynode->link_ammount++;
mynode->links[0] = malloc(sizeof(struct Link));
mynode->data_size = 0;
mynode->data = NULL;
mynode->cached = NULL;
memcpy(mynode->links[0], mylink, sizeof(struct Link));
return mynode;
}

View file

@ -38,5 +38,5 @@ int test_node() {
Free_Link(mylink2);
Free_Link(ResultLink);
Node_Delete(Mynode);
return 0;
return 1;
}