From 6369ed08e29fc69ef34a71c3c2b562a6e92b6235 Mon Sep 17 00:00:00 2001 From: adman Date: Thu, 25 Dec 2025 17:57:59 +0100 Subject: [PATCH] fix fuzz result i returned which is how i normally code but returning doesnt set stuff which made things break here []byte("80\x00\x01\x05\x01\x010\x01\x00") --- proto_generator/native_decoder.go | 11 +++++------ proto_generator/printer.go | 8 ++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/proto_generator/native_decoder.go b/proto_generator/native_decoder.go index aedb502..eaf0f54 100644 --- a/proto_generator/native_decoder.go +++ b/proto_generator/native_decoder.go @@ -477,7 +477,6 @@ func RegistryEntryHolderDecoder(g *Generator, varToSet ast.Expr, dataRaw any, na if err != nil { return } - idPath := If(NotEquals(Ident(idName), NumLit(0)), NewBlockEllipsis(Assign121(varToSet, Ident(idName)), Return())) otherwiseType, err := g.VisitType(data.Otherwise.Type) if err != nil { @@ -485,20 +484,20 @@ func RegistryEntryHolderDecoder(g *Generator, varToSet ast.Expr, dataRaw any, na } resName := name + "Result" resNameIdent := Ident(resName) - resultVar := VarStmt(resName, otherwiseType) + var otherwisePath []ast.Stmt + otherwisePath = append(otherwisePath, VarStmt(resName, otherwiseType)) otherwiseDecodeStatements, err := g.VisitDecoder(resNameIdent, data.Otherwise.Type, name+"Otherwise") if err != nil { return } - resultAssign := Assign121(varToSet, resNameIdent) + otherwisePath = append(otherwisePath, otherwiseDecodeStatements...) + otherwisePath = append(otherwisePath, Assign121(varToSet, resNameIdent)) + idPath := IfElse(NotEquals(Ident(idName), NumLit(0)), NewBlockEllipsis(Assign121(varToSet, Ident(idName))), NewBlock(otherwisePath)) s = append(s, IdVar) s = append(s, idDecodeStatements...) s = append(s, idPath) - s = append(s, resultVar) - s = append(s, otherwiseDecodeStatements...) - s = append(s, resultAssign) return } diff --git a/proto_generator/printer.go b/proto_generator/printer.go index 2fb6c26..20d4d18 100644 --- a/proto_generator/printer.go +++ b/proto_generator/printer.go @@ -196,6 +196,14 @@ func If(cond ast.Expr, body *ast.BlockStmt) *ast.IfStmt { } } +func IfElse(cond ast.Expr, body *ast.BlockStmt, els *ast.BlockStmt) *ast.IfStmt { + return &ast.IfStmt{ + Cond: cond, + Body: body, + Else: els, + } +} + func NotEquals(lhs, rhs ast.Expr) *ast.BinaryExpr { return &ast.BinaryExpr{ X: lhs,