diff --git a/TestList.csv b/TestList.csv index cfc65f4..d3cbcc7 100644 --- a/TestList.csv +++ b/TestList.csv @@ -28,4 +28,5 @@ 44,Alena,Matouskova,3037,1,0,1 45,Josef,Suchy,3038,1,0,1 46,Marketa,Rezacova,3039,1,0,1 -47,Libor,Hanak,3040,1,0,1 \ No newline at end of file +47,Libor,Hanak,3040,1,0,1 +48,Libor,Hanak,3040,1,0,1 \ No newline at end of file diff --git a/include/users.h b/include/users.h index 96b4d90..c739e7d 100644 --- a/include/users.h +++ b/include/users.h @@ -59,7 +59,7 @@ uint16_t generateUUID(list_t *_list); * @param _surname Pointer to a string containing the user's surname. * @return Pointer to the UUID of the user if found, or 0 if no match is found. */ -uint16_t searchUUIDByName(list_t *_list, char *_name, char *_surname, uint16_t * _uuids_found); +uint16_t searchUUIDByName(list_t *_list, char *_name, char *_surname, uint16_t **_uuids_found); /** * @brief Searches for a person in a linked list by their UUID. diff --git a/src/tui.c b/src/tui.c index e6dfe12..ddf6b82 100644 --- a/src/tui.c +++ b/src/tui.c @@ -404,7 +404,7 @@ void personSearch(list_t *person_list, int terminal_x, int terminal_y) } else if (highlight == 2) { - uint16_t count = searchUUIDByName(person_list, name, surname, uuids_found); + uint16_t count = searchUUIDByName(person_list, name, surname, &uuids_found); list_t found_pesons; found_pesons.head = NULL; node_t **last_ptr = &found_pesons.head; diff --git a/src/users.c b/src/users.c index c792f67..1f40513 100644 --- a/src/users.c +++ b/src/users.c @@ -56,14 +56,14 @@ node_t *searchPersonByUUID( return NULL; } -uint16_t searchUUIDByName( - list_t *_list, - char *_name, - char *_surname, - uint16_t **_uuids_found) +uint16_t searchUUIDByName(list_t *_list, char *_name, char *_surname, uint16_t **_uuids_found) { - int sum = 0; + uint16_t sum = 0; uint16_t *uuids = malloc(sizeof(uint16_t)); + if (uuids == NULL) { + *_uuids_found = NULL; + return 0; + } pthread_mutex_lock(&_list->lock); node_t *current = _list->head; @@ -75,14 +75,15 @@ uint16_t searchUUIDByName( if (strcmp(_name, current->user.name) == 0 && strcmp(_surname, current->user.surname) == 0) { sum++; - uint16_t *uuids = realloc(uuids, sum * sizeof(uint16_t)); - if (uuids == NULL) + uint16_t *temp = realloc(uuids, sum * sizeof(uint16_t)); + if (temp == NULL) { pthread_mutex_unlock(&_list->lock); free(uuids); puts("Fatal error: free memory is not sufficient for this operation"); exit(EXIT_FAILURE); } + uuids = temp; uuids[sum - 1] = current->user.uuid; } }