Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database/sql/driver: convertAssignRows not all nilPtr destinations covered in the switch cases #66237

Open
borissmidt opened this issue Mar 10, 2024 · 1 comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@borissmidt
Copy link

borissmidt commented Mar 10, 2024

Go version

latest

Output of go env in your module/workspace:

latest

What did you do?

I was reading through the source code of database/sql/driver to learn to write better go and out of interest how a language is designed.

What did you see happen?

I suspect no errNilPtr will be returned in
https://github.com/golang/go/blob/master/src/database/sql/convert.go#L272-L278

         case time.Time:
		switch d := dest.(type) {
		case *time.Time:
			*d = s
			return nil
		case *string:
			*d = s.Format(time.RFC3339Nano)
			return nil
		case *[]byte:
			if d == nil {
				return errNilPtr
			}
			*d = []byte(s.Format(time.RFC3339Nano))
			return nil

To confirm this i didn't see any tests for the returning of a nilptr err.

What did you expect to see?

Since dest has to be pointer it would be best to first test if the dest is a nil ptr at the top level of the function.
https://github.com/golang/go/blob/master/src/database/sql/convert.go#L219-L221

func convertAssignRows(dest, src any, rows *Rows) error {
	if d == nil {
		return errNilPtr
	}
	// Common cases, without reflect.
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/570475 mentions this issue: database/sql/driver.convertAssignRows: not all nilPtr cases for dest where covered

@seankhliao seankhliao changed the title database/sql/driver.convertAssignRows: issue Not all nilPtr destinations covered in the switch cases. database/sql/driver: convertAssignRows not all nilPtr destinations covered in the switch cases Mar 12, 2024
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 12, 2024
@cherrymui cherrymui added this to the Backlog milestone Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants