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;