runtime-tools
runtime-tools copied to clipboard
Fix nil ptr panic when adding env variables to uninitialized Generator
When calling AddProcessEnv on a Generator instance that was created using zero-value initialization (Generator{}) rather than through New(), the envMap field would be nil. This caused a panic when attempting to write to the map in the addEnv helper function.
This commit adds a nil check before writing to the envMap in addEnv. If the map is uninitialized, it creates a new empty map before proceeding with the map insertion operation.
A new test case has been added to TestEnvCaching that validates this scenario by creating a Generator using zero-value initialization and verifying that AddProcessEnv works correctly without panicking.
Fixes #790