Commit c3034d0
committed
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.
Signed-off-by: Andreas Karis <[email protected]>1 parent 0ea5ed0 commit c3034d0
2 files changed
+12
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
543 | 546 | | |
544 | 547 | | |
545 | 548 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
127 | 136 | | |
128 | 137 | | |
129 | 138 | | |
| |||
0 commit comments