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

httpx.Parse will panic when parsing *float32 #3840

Closed
jeffmingup opened this issue Jan 12, 2024 · 0 comments · Fixed by #3845
Closed

httpx.Parse will panic when parsing *float32 #3840

jeffmingup opened this issue Jan 12, 2024 · 0 comments · Fixed by #3845

Comments

@jeffmingup
Copy link

Describe the bug
httpx.Parse will panic when parsing *float32

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The code is

    	t.Run("has *float32", func(t *testing.T) {
     	var v struct {
     		// WeightFloat32
     		WeightFloat32 *float32 `json:"weightFloat32,optional"`
     	}
     	body := `{"weightFloat32": 3.2}`
     	r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(body))
     	r.Header.Set(ContentType, header.JsonContentType)
    
     	if assert.NoError(t, Parse(r, &v)) {
     		assert.Equal(t, float32(3.2), *v.WeightFloat32)
     	}
     })
  2. The error is

    panic: reflect: call of reflect.Value.OverflowFloat on ptr Value
    

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Environments (please complete the following information):

  • OS: [e.g. Linux]
  • go-zero version [e.g. 1.2.1]
  • goctl version [e.g. 1.2.1, optional]

More description
Add any other context about the problem here.

if value.OverflowFloat(fValue) {

This time the call.overflowfloat will be reported to panic, which can modify the method of detection overflow

kevwan added a commit to kevwan/go-zero that referenced this issue Jan 13, 2024
kevwan added a commit to kevwan/go-zero that referenced this issue Jan 13, 2024
kevwan added a commit to kevwan/go-zero that referenced this issue Jan 14, 2024
kevwan added a commit that referenced this issue Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant