runtime-tools icon indicating copy to clipboard operation
runtime-tools copied to clipboard

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

Open andreaskaris opened this issue 2 months ago • 0 comments

Description

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

Steps to Reproduce

  1. Create a Generator using zero-value initialization instead of New():
    g := generate.Generator{}
    
  2. Call AddProcessEnv on the generator:
    g.AddProcessEnv("KEY", "value")
    
  3. 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)

andreaskaris avatar Oct 03 '25 17:10 andreaskaris