What version of PHP are you using? No matter how I try, I've not been able to even get that error at the most basic level with inet_pton. Tried with PHP 7, PHP 8, tried forcing null characters into the function, etc.
Side note, it's also the exact same way XenForo core is using inet_pton in 2.3...