Skip to content

Conversation

andreaskaris
Copy link

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

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.

Signed-off-by: Andreas Karis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When creating a Generator instance using zero-value initialization (Generator{}), calling AddProcessEnv causes a nil pointer panic.
1 participant