runtime-tools
runtime-tools copied to clipboard
When creating a Generator instance using zero-value initialization (`Generator{}`), calling `AddProcessEnv` causes a nil pointer panic.
Description
When creating a Generator instance using zero-value initialization (Generator{}), calling AddProcessEnv causes a nil pointer panic.
Steps to Reproduce
- Create a
Generatorusing zero-value initialization instead ofNew():g := generate.Generator{} - Call
AddProcessEnvon 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:
generatepackage - Affected function:
AddProcessEnv(viaaddEnvhelper)