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

Update gutil_dump.go #2305

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion util/gutil/gutil_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ func doDump(value interface{}, indent string, buffer *bytes.Buffer, option doDum
}
var (
reflectKind = reflectValue.Kind()
reflectTypeName = reflectValue.Type().String()
reflectTypeName = "invalid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may check the reflectValue at line 107:

// Double check nil value.
if value == nil || reflectValue.IsNil() || !reflectValue.IsValid() {
	buffer.WriteString(`<nil>`)
	return
}

Copy link
Author

@brick-carrier-fan brick-carrier-fan Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried your way of checking the reflectValue, and it brings the same mistake.
Not available to check reflectValue with IsNil().
The method I submitted is available.
I apologize for my poor English.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brick-carrier-fan OK, then try this:

// Double check nil value.
if value == nil || !reflectValue.IsValid() || (reflectValue.Kind() == reflect.Ptr && reflectValue.IsNil()) {
	buffer.WriteString(`<nil>`)
	return
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,buffer will go to get infinitely bigger,then get OOM panic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,buffer will go to get infinitely bigger,then get OOM panic

Any question carrying on this PR?

newIndent = indent + dumpIndent
)
if reflectValue.IsValid() {
reflectTypeName = reflectValue.Type().String()
}
reflectTypeName = strings.ReplaceAll(reflectTypeName, `[]uint8`, `[]byte`)
if !option.WithType {
reflectTypeName = ""
Expand Down