# Non-deterministic Map Iteration - ID: go-map-iteration-without-sort - Severity: MEDIUM - CWE: CWE-330 (CWE-330) - Languages: Go ## Description Converts map to slice without sorting, producing non-deterministic output. ## Detection Message Map iteration order in Go is non-deterministic. This code converts a map to a slice without sorting, which will produce different orderings on each execution. ## Remediation Add sorting after collecting keys/values from the map: ```go // Before (non-deterministic): result := make([]string, 0, len(myMap)) for key := range myMap { result = append(result, key) } return result // Order varies! // After (deterministic): result := make([]string, 0, len(myMap)) for key := range myMap { result = append(result, key) } sort.Strings(result) // Always same order return result ``` For non-string types, use sort.Slice: ```go sort.Slice(result, func(i, j int) bool { return result[i].Name < result[j].Name }) ``` ## Documentation [object Object]