From 0f47d2dbf07347546ce7044267143e3c5408561a Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Tue, 2 Jun 2026 12:29:07 -0400 Subject: [PATCH] Document title/path truncation behavior in Win32 binding --- internal/winapi/winapi.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/winapi/winapi.go b/internal/winapi/winapi.go index ffea79c..b0c5513 100644 --- a/internal/winapi/winapi.go +++ b/internal/winapi/winapi.go @@ -27,6 +27,7 @@ func ForegroundWindow() (hwnd uintptr, title, class string, ok bool) { } func windowTitle(h windows.HWND) string { + // 512 uint16s; titles over 511 chars are truncated — acceptable for a sensor tag. const max = 512 buf := make([]uint16, max) n, _, _ := procGetWindowTextW.Call( @@ -34,6 +35,7 @@ func windowTitle(h windows.HWND) string { uintptr(unsafe.Pointer(&buf[0])), uintptr(max), ) + // n==0 covers both call failure and a genuinely empty title; both are fine here. return windows.UTF16ToString(buf[:n]) } @@ -50,6 +52,8 @@ func windowClass(h windows.HWND) string { buf := make([]uint16, windows.MAX_PATH) size := uint32(len(buf)) + // MAX_PATH suffices for almost all paths; an over-long path fails here and + // degrades windowClass to "" (window left unclassified), never a crash. if err := windows.QueryFullProcessImageName(proc, 0, &buf[0], &size); err != nil { return "" }