Skip to content

bind: MakeSetterFloat64 rejects the documented uintptr type #219

Description

@linkdata

Summary

bind.MakeSetterFloat64 documents support for the predeclared signed and unsigned integer types, but passing a uintptr value panics as unsupported.

Class / severity

Robustness / correctness — Low. Correct use of a documented but uncommon numeric type causes an immediate panic.

Contract and valid usage

The MakeSetterFloat64 doc says v may be a setter/getter/static value of "the predeclared signed and unsigned integer types." uintptr is a predeclared unsigned integer type, and the docs list no exclusion for it.

Reproduction

package bind_test

import (
	"testing"

	"github.com/linkdata/jaws/lib/bind"
)

func TestMakeSetterFloat64AcceptsUintptr(t *testing.T) {
	s := bind.MakeSetterFloat64(uintptr(42))
	if got := s.JawsGet(nil); got != 42 {
		t.Fatalf("JawsGet() = %v, want 42", got)
	}
}

The constructor panics with:

expected bind.Setter[float64], bind.Getter[float64] or float64 not uintptr

Root cause

The private numeric constraint omits ~uintptr (lib/bind/setterfloat64.go:19-23), and the dispatch in MakeSetterFloat64 has no makeSetterFloat64for[uintptr] case (lib/bind/setterfloat64.go:199-209). The sanitizer consequently also has no uintptr bounds case.

Impact

Libraries that generically adapt Go numeric fields can crash when a valid uintptr reaches this API, despite relying on its documented supported domain.

Suggested fix

Add ~uintptr to numeric, handle uintptr in sanitizeFloatForT using the platform-width unsigned bound, add makeSetterFloat64for[uintptr], and cover static, Getter, and Setter forms in tests. Alternatively, explicitly exclude uintptr in the exported contract, but that would narrow the current documented domain.

Confidence

Confirmed on main at 6fd13a2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions