Menu

#310 Fix warnings with mingw-w64 12

3.x Stable
closed-accepted
nobody
None
5
2023-05-21
2023-04-12
Jason
No

I tested trunk against a daily prerelease build of ubuntu 23.04, which has mingw-w64 12, and got a couple of warnings about a dangling pointer and a not ignored unused variable. So I made a patch that fixes these two issues.

1 Attachments

Discussion

  • Anders

    Anders - 2023-04-12

    We don't want to pass that extra parameter in so many places.

    What about just static int *g_parms = 0;?

     

    Last edit: Anders 2023-04-12
  • Jason

    Jason - 2023-04-13

    First thing I tried, didn't work. Here is the warning from mingw-w64:

    Source/exehead/exec.c: In function 'ExecuteEntry':
    Source/exehead/exec.c:274:11: warning: storing the address of local variable 'lent' in 'g_parms' [-Wdangling-pointer=]
      274 |   g_parms = lent.offsets;
          |   ~~~~~~~~^~~~~~~~~~~~~~
    Source/exehead/exec.c:256:9: note: 'lent' declared here
      256 |   entry lent = *entry_;
          |         ^~~~
    Source/exehead/exec.c:119:13: note: 'g_parms' declared here
      119 | static int *g_parms = 0;
          |             ^~~~~~~
    

    Previous versions of mingw-w64 in ubuntu were based on gcc 10, but this is the first version of ubuntu (23.04) using the newer gcc 12 backend for mingw-w64.

    Some research showed that other software revealed the same issues when they upgraded to gcc 12 proper.

    Can we just add a define that references 'parms' indirectly and remove the global variable?

    @@ -148,13 +148,14 @@
     // the string to expand gets modified.
     // When calling this function with numbers like 0x13, it means create the string
     // from the string ID found in entry.offset[3] and put it into g_bufs[1].
    -static TCHAR * NSISCALL GetStringFromParm(int id_)
    +static TCHAR * NSISCALL GetStringFromParmEx(const int *parms, int id_)
     {
       int id = id_ < 0 ? -id_ : id_;
    
    -  TCHAR *result = GetNSISString(g_bufs[id >> 4], g_parms[id & 0xF]);
    +  TCHAR *result = GetNSISString(g_bufs[id >> 4], parms[id & 0xF]);
       if (id_ < 0) validate_filename(result);
       return result;
     }
    +#define GetStringFromParm(id_) GetStringFromParmEx(parms, id_)
    
     
  • Anders

    Anders - 2023-04-13

    All the functions using it are static and only called by that function so the pointer cannot dangle.

    If you can't fool it with a (int*)(char*) cast then ifdef GCC pragma/attribute away the warning.

     

    Last edit: Anders 2023-04-13
  • Jason

    Jason - 2023-04-14

    Alright.

    Index: Contrib/Makensisw/utils.h
    ===================================================================
    --- Contrib/Makensisw/utils.h   (revision 7387)
    +++ Contrib/Makensisw/utils.h   (working copy)
    @@ -84,8 +84,8 @@
     void SetDialogFocus(HWND hDlg, HWND hCtl); // Use this and not SetFocus()!
     #define DlgRet(hDlg, val) ( SetWindowLongPtr((hDlg), DWLP_MSGRESULT, (val)) | TRUE )
     HWND GetComboEdit(HWND hCB);
    -#define DisableItems(hwnd) EnableDisableItems(((hwnd), 0))
    -#define EnableItems(hwnd) EnableDisableItems(((hwnd), 1))
    +#define DisableItems(hwnd) EnableDisableItems(((void)(hwnd), 0))
    +#define EnableItems(hwnd) EnableDisableItems(((void)(hwnd), 1))
     void EnableDisableItems(int on);
     bool OpenRegSettingsKey(HKEY &hKey, bool create = false);
     #define CreateRegSettingsKey(refhkey) OpenRegSettingsKey((refhkey), true)
    Index: Source/exehead/exec.c
    ===================================================================
    --- Source/exehead/exec.c   (revision 7387)
    +++ Source/exehead/exec.c   (working copy)
    @@ -271,7 +271,14 @@
       //var4 = g_usrvars[parm4];
       //var5 = g_usrvars[parm5];
    
    +#if __GNUC__ >= 12
    +#pragma GCC diagnostic push
    +#pragma GCC diagnostic ignored "-Wdangling-pointer"
    +#endif
       g_parms = lent.offsets;
    +#if __GNUC__ >= 12
    +#pragma GCC diagnostic pop
    +#endif
    
       switch (which)
       {
    

    I'll also attach an alternate patch that removes 'g_parms' and passes the parms through using defines, in case anyone else searches for this issue.

     
  • Anders

    Anders - 2023-05-21
    • status: open --> closed-accepted
     

Log in to post a comment.

Monday.com Logo