cursor y-coordinate wrong

Whether I use SDL_GetMouseState() or check event.motion.x & y after polling mouse motion, the y-coordinate is always wildly off. The x-coordinate is correct in both the cases.
The y-coordinate isn’t even linear when moving the mouse downwards, it goes everywhere at first then increases gradually.
What could be causing this?

Are you sure your code is right? Maybe you could post a small example that demonstrates the problem, or at least the code where you use SDL_GetMouseState and event.motion.y.

On second thought, it seems unlikely that you would have made a mistake both when fetching the mouse state and when using the event.

If your code is correct and you suspect that there might be a bug in SDL then it would be helpful to know which version of SDL that you use. Do you use SDL2 or SDL3?

FWIW SDL_GetMouseState() works fine for me and returns the correct y-coordinate, on all the platforms I support.

I am using sprintf to display cursor position. Turns out the problem was sprintf appending garbage values. I appended a null pointer at the right place to fix it.