From 67da7046353b8a48028aa53bdd879ac8bead387a Mon Sep 17 00:00:00 2001 From: Deinerovych Date: Tue, 29 Oct 2024 15:27:15 +0100 Subject: [PATCH] 2 --- cv6/a_station.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cv6/a_station.c b/cv6/a_station.c index ef739e1..3492502 100644 --- a/cv6/a_station.c +++ b/cv6/a_station.c @@ -25,11 +25,11 @@ void destroy_station(struct station* station) { } int select_track(struct station* station, const char* target) { - int hash = 0; + unsigned int hash = 0; for (int i = 0; target[i] != '\0'; i++) { - hash = (hash * 31 + target[i]) % station->track_count; + hash = (hash * 31 + target[i]); } - return hash; + return hash % station->track_count; } void add_target_capacity(struct station* station, const char* target, int capacity) { @@ -46,6 +46,7 @@ void add_target_capacity(struct station* station, const char* target, int capaci struct car* new_car = malloc(sizeof(struct car)); strncpy(new_car->value, target, TARGET_SIZE); + new_car->value[TARGET_SIZE - 1] = '\0'; // Гарантия завершения строки new_car->capacity = capacity; new_car->next = station->tracks[index]; station->tracks[index] = new_car;