Very similar to other patches in this space. Avoid implicit int types and add missing #includes so that this code works with gcc-14.