Menu

#687 Main window placed partially off-screen

v2.4
closed-fixed
None
Windows
x64
2018-05-18
2015-11-14
No

In \src\arch\win32\ui.c, function ui_get_menu_height(), LONG min_y is assigned a value of LONG_MAX.

While this seems correct, it's a slight problem if you compile it with MSYS2 x64 (a rewrite of MSYS) due to an inconsistant data type. Both MSVC and MSYS define LONG as a 32-bit integer, but MSYS2 x64 defines LONG_MAX as a 64-bit integer. min_y therefore overflows and is set to -1. This affects the return value of the function, which then causes the window to appear partially off-screen.

Possible fixes:
set min_y and max_y to INT_MAX and INT_MIN (arbitrary values are acceptable, as there's no way a normal user is going to have a window that far.
Have the conditionals in the main loop always trigger if i==0. (e.g. if (!i || rect.top < min_y){...} )

As a side note, function ui_resize_canvas_window() calls ui_get_menu_height when it can instead use the cached value of menu_height.

Discussion

  • Marco van den Heuvel

    Let me get this straight:

    • all api documentation that I've read for windows says that a LONG is 32bit, therefor LONG_MAX is 32bit.
    • i686-w64-mingw32 (64bit mingw target) a LONG is 32bit and LONG_MAX is 32bit,
    • All versions of VS that support 64bit, a LONG is 32bit and LONG_MAX is 32bit.

    And now a new toolchain for windows has come out that has LONG as 32bit, but LONG_MAX as 64bit ??

    Ifso, send a bug report to the toolchain makers.

     
  • Raymond Martineau

    There's two different datatypes. "long" is the compiler-native datatype, and "LONG" is defined for use with the windows API. Certain toolchains, such as Cygwin and their derivatives (including MSYS2), use a 64-bit "long" to maintain compatability with other Unix programs, but need a 32-bit "LONG" in order to interface with the windows API.

    Also, window positions and sizes are already limited by a 16-bit integer, with the X and Y coordinates being stuffed into the lower and upper words of an LPARAM for WM_MOVE and WM_SIZE. As such, using LONG_MAX is overkill for a value that can't possibly be greater than INT_MAX (or short for that matter.)

     
  • Marco van den Heuvel

    Workaround added in rev. 30208, please retry.

     
  • Marco van den Heuvel

    • status: open --> pending-fixed
    • assigned_to: Marco van den Heuvel
     
  • gpz

    gpz - 2018-05-18
    • status: pending-fixed --> closed-fixed
     

Log in to post a comment.