github-vet / github-vet/rangeloop-pointer-findings

cockroachdb/cockroach: pkg/sql/pg_catalog.go; 55 LoC

Open
#11,366 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [cockroachdb/cockroach](https://www.github.com/cockroachdb/cockroach) at [pkg/sql/pg_catalog.go](https://github.com/cockroachdb/cockroach/blob/4e3a9ccdb9cac89ae32d6248bb9b119b5bc250f7/pkg/sql/pg_catalog.go#L2620-L2674)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to overload was used in a composite literal at line 2650

[Click here to see the code in its original context.](https://github.com/cockroachdb/cockroach/blob/4e3a9ccdb9cac89ae32d6248bb9b119b5bc250f7/pkg/sql/pg_catalog.go#L2620-L2674)

Click here to show the 55 line(s) of Go which triggered the analyzer.

```go
for _, overload := range overloads {
params, _ := tree.GetParamsAndReturnType(overload)
sortOperatorOid := oidZero
aggregateKind := tree.NewDString("n")
aggNumDirectArgs := zeroVal
if params.Length() != 0 {
argType := tree.NewDOid(tree.DInt(params.Types()[0].Oid()))
returnType := tree.NewDOid(tree.DInt(oid.T_bool))
switch name {
// Cases to determine sort operator.
case "max", "bool_or":
sortOperatorOid = h.OperatorOid(">", argType, argType, returnType)
case "min", "bool_and", "every":
sortOperatorOid = h.OperatorOid("<", argType, argType, returnType)

// Cases to determine aggregate kind.
case "rank", "percent_rank", "cume_dist", "dense_rank":
aggregateKind = tree.NewDString("h")
aggNumDirectArgs = tree.NewDInt(1)
case "mode":
aggregateKind = tree.NewDString("o")
default:
if strings.HasPrefix(name, "percentile_") {
aggregateKind = tree.NewDString("o")
aggNumDirectArgs = tree.NewDInt(1)
}
}
}
regprocForZeroOid := tree.NewDOidWithName(tree.DInt(0), types.RegProc, "-")
err := addRow(
h.BuiltinOid(name, &overload).AsRegProc(name), // aggfnoid
aggregateKind, // aggkind
aggNumDirectArgs, // aggnumdirectargs
regprocForZeroOid, // aggtransfn
regprocForZeroOid, // aggfinalfn
regprocForZeroOid, // aggcombinefn
regprocForZeroOid, // aggserialfn
regprocForZeroOid, // aggdeserialfn
regprocForZeroOid, // aggmtransfn
regprocForZeroOid, // aggminvtransfn
regprocForZeroOid, // aggmfinalfn
tree.DBoolFalse, // aggfinalextra
tree.DBoolFalse, // aggmfinalextra
sortOperatorOid, // aggsortop
tree.DNull, // aggtranstype
tree.DNull, // aggtransspace
tree.DNull, // aggmtranstype
tree.DNull, // aggmtransspace
tree.DNull, // agginitval
tree.DNull, // aggminitval
)
if err != nil {
return err
}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: 4e3a9ccdb9cac89ae32d6248bb9b119b5bc250f7

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.