Description
When creating a Generator instance using zero-value initialization (Generator{}), calling AddProcessEnv causes a nil pointer panic.
Steps to Reproduce
- Create a
Generator using zero-value initialization instead of New():
g := generate.Generator{}
- Call
AddProcessEnv on the generator:
g.AddProcessEnv("KEY", "value")
- The program panics with a nil pointer dereference
Expected Behavior
AddProcessEnv should work correctly regardless of whether the Generator was created using New() or zero-value initialization.
Actual Behavior
The program panics because the envMap field is nil when the Generator is created using zero-value initialization, and the addEnv helper function attempts to write to this nil map.
Root Cause
The addEnv function in generate.go writes to g.envMap without checking if it has been initialized. When using zero-value initialization, this field remains nil.
Environment
- Component:
generate package
- Affected function:
AddProcessEnv (via addEnv helper)