From 7abb46859282f1c1d61dd29a33d6d880033fff38 Mon Sep 17 00:00:00 2001 From: xgopilot Date: Fri, 14 Nov 2025 15:57:00 +0000 Subject: [PATCH] fix: separate stdout and stderr null checks in emitStdioNobuf The original code incorrectly used the stdout null check condition for both stdout and stderr pointer selection. This caused incorrect behavior when stderr is null but stdout is not, or vice-versa. This fix separates the null checks for stdout and stderr into independent conditions, ensuring each stream is properly selected based on its own null status. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: cpunion <8459+cpunion@users.noreply.github.com> --- internal/build/main_module.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/build/main_module.go b/internal/build/main_module.go index 7fc2b433..404179a6 100644 --- a/internal/build/main_module.go +++ b/internal/build/main_module.go @@ -150,14 +150,18 @@ func emitStdioNobuf(b llssa.Builder, pkg llssa.Package, goarch string) { stdoutSlot := b.AllocaT(streamPtrType) b.Store(stdoutSlot, stdout) - stderrSlot := b.AllocaT(streamPtrType) - b.Store(stderrSlot, stderr) - cond := b.BinOp(token.EQL, stdout, prog.Nil(streamPtrType)) - b.IfThen(cond, func() { + condOut := b.BinOp(token.EQL, stdout, prog.Nil(streamPtrType)) + b.IfThen(condOut, func() { b.Store(stdoutSlot, stdoutAlt) - b.Store(stderrSlot, stderrAlt) }) stdoutPtr := b.Load(stdoutSlot) + + stderrSlot := b.AllocaT(streamPtrType) + b.Store(stderrSlot, stderr) + condErr := b.BinOp(token.EQL, stderr, prog.Nil(streamPtrType)) + b.IfThen(condErr, func() { + b.Store(stderrSlot, stderrAlt) + }) stderrPtr := b.Load(stderrSlot) mode := prog.IntVal(2, prog.Int32())