Skip to content

[BUG] Fix unnecessary double conversion in Windows getSymbol #22

@tazarov

Description

@tazarov

Description

The Windows implementation of getSymbol in ort/library_windows.go uses an unnecessary double conversion through unsafe.Pointer that is error-prone.

Current Code

File: ort/library_windows.go:24

func getSymbol(handle uintptr, symbol string) (uintptr, error) {
    proc, err := windows.GetProcAddress(windows.Handle(handle), symbol)
    if err != nil {
        return 0, err
    }
    return uintptr(unsafe.Pointer(proc)), nil  // Double conversion
}

Issue

The double conversion uintptr(unsafe.Pointer(proc)) is unnecessary because:

  • windows.GetProcAddress returns *byte
  • This can be converted directly to uintptr
  • The intermediate unsafe.Pointer step adds no safety

Proposed Fix

func getSymbol(handle uintptr, symbol string) (uintptr, error) {
    proc, err := windows.GetProcAddress(windows.Handle(handle), symbol)
    if err != nil {
        return 0, err
    }
    // Direct conversion - GetProcAddress returns *byte which is uintptr-compatible
    return uintptr(proc), nil
}

Impact

  • Severity: Low (current code works, but is unnecessarily complex)
  • Priority: Medium (should fix before v1.0)
  • Risk: Minimal (simplification of existing working code)

Testing

  • Verify Windows builds still compile
  • Run existing tests on Windows platform
  • No behavior change expected

Related

Acceptance Criteria

  • Remove unnecessary unsafe.Pointer intermediate conversion
  • Add comment explaining why direct conversion is safe
  • Verify Windows tests pass
  • Consider adding Windows-specific test if none exist

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions