← cproj

testing

3a372833d553a360a0d04aa1ae155ed6e2065759 · Ovidiu · Jul 30, 2019 12:57

+5 −4 · 2 files changed

  • mylib/src/myhash.c +1 −0
  • mylib/test/t_hash.c +4 −4
diff --git a/mylib/src/myhash.c b/mylib/src/myhash.c
index e1d2d7f..151c9b0 100644
--- a/mylib/src/myhash.c
+++ b/mylib/src/myhash.c
@@ -112,6 +112,7 @@ HashNode *h_insert (HashTable *hTable, char *key, char *value) {
 	 	hTable->h_items[resultHash] = newNode;
      } else {
  		// Keys are the same , reeuse key and assign a different value + 1 for '/0'
+		// Latest value will be used for the key.
 			newNode->h_value = (char *) realloc((void *) newNode->h_value, strlen(value)+1);
 			newNode->h_value = strcpy(newNode->h_value,value);
      }
diff --git a/mylib/test/t_hash.c b/mylib/test/t_hash.c
index 9d988b5..3f7c78a 100644
--- a/mylib/test/t_hash.c
+++ b/mylib/test/t_hash.c
@@ -114,7 +114,7 @@ static char *readFile(char *fn) {
 
 		// Allocate string that can hold all of the data
 		// includes + 1 for null character + 1 to codfy end of file for Tuple
-		buf = (char *) malloc(sizeof(char) * (s.st_size + 2));
+		buf = (char *) malloc(s.st_size + 2);
 
 		// read
 		readSize = fread(buf, sizeof(char), s.st_size, stream);
@@ -148,9 +148,9 @@ int main(int argc, char** argv){
 
 	// initialise filename to NULL
 	char *fileRead = NULL;
-	
+	// the two strings need to be stored  
 	char *format,*format0;
-	
+	// local data strucure to store strucutre
 	struct Tuple kv_tuple;	
 	
 	if (argc != 2) {
@@ -161,6 +161,7 @@ int main(int argc, char** argv){
 		// fileread from filename
 		fileRead = readFile(fn);
 		format = t_parseBuff(fileRead);
+		// save 
 		format0 = format;
 		
 		while (kv_format(&kv_tuple,&format)) {
@@ -173,7 +174,6 @@ int main(int argc, char** argv){
 			if(++counter ==  50)
 				break;
 			}
-				
 	}
 	dumpTable(tableResult,0);