From f2c8d9f7d26f78f0df2a5315b5718bfcce08d1eb Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Sun, 18 Jan 2026 20:58:23 +0000 Subject: [PATCH] fix: use loop variable instead of global ticker in GenerateFreshName (#40) ## Description `GenerateFreshName` used a global `ticker` variable but never incremented it inside the loop. This caused an infinite loop if the first generated name (`_0`) was already in the used set. - Remove global `ticker` variable. - Use loop variable `i` directly to generate candidate names. ## Benefits - Fixes infinite loop bug when generated name collides with used set. - Removes unnecessary global state. - Simpler and more predictable behavior. ## Checklist - [x] Code follows conventional commit format. - [x] Branch follows naming convention (`/`). Always use underscores. - [x] Tests pass (if applicable). - [x] Documentation updated (if applicable). Reviewed-on: https://git.maximhutz.com/mvhutz/lambda/pulls/40 Co-authored-by: M.V. Hutz Co-committed-by: M.V. Hutz --- pkg/lambda/generate_name.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/lambda/generate_name.go b/pkg/lambda/generate_name.go index fbfa898..03f5018 100644 --- a/pkg/lambda/generate_name.go +++ b/pkg/lambda/generate_name.go @@ -6,13 +6,11 @@ import ( "git.maximhutz.com/max/lambda/pkg/set" ) -var ticker uint64 = 0 - // GenerateFreshName generates a variable name that is not in the used set. // This function does not mutate the used set. func GenerateFreshName(used set.Set[string]) string { for i := uint64(0); ; i++ { - attempt := "_" + string(strconv.AppendUint(nil, ticker, 10)) + attempt := "_" + string(strconv.AppendUint(nil, i, 10)) if !used.Has(attempt) { return attempt