Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled warnings various platforms and fixed C++20 Windows build #2411

Merged
merged 11 commits into from
Feb 9, 2023

Conversation

oviano
Copy link
Contributor

@oviano oviano commented Jul 20, 2022

  1. adds some more disabled warnings to platform_sys.h on Apple platforms, Windows and Android.
  2. include platform_sys.h in some haicrypt files to remove warnings from these files too.
  3. removed unary_function when compiling C++20, as it was deprecated in C++17 and produces an error when building using MSVC as C++20.

@maxsharabayko maxsharabayko added this to the Next Release milestone Jul 20, 2022
@maxsharabayko maxsharabayko added Type: Maintenance Work required to maintain or clean up the code [core] Area: Changes in SRT library core labels Jul 20, 2022
srtcore/group.cpp Outdated Show resolved Hide resolved
@maxsharabayko
Copy link
Collaborator

macOS builds are failing in Travis CI.

error: unknown warning group '-Wambiguous-reversed-operator', ignored [-Werror,-Wunknown-warning-option]
#pragma clang diagnostic ignored "-Wambiguous-reversed-operator"

@oviano
Copy link
Contributor Author

oviano commented Jul 21, 2022

macOS builds are failing in Travis CI.

error: unknown warning group '-Wambiguous-reversed-operator', ignored [-Werror,-Wunknown-warning-option]
#pragma clang diagnostic ignored "-Wambiguous-reversed-operator"

I can see:

osx_image: xcode11.1

I'm building with latest Xcode, 13.4.1. Presumably it uses a newer clang version.

srtcore/group.cpp Outdated Show resolved Hide resolved
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
#pragma clang diagnostic ignored "-Wambiguous-reversed-operator"
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please paste, somewhere in comments maybe, where exactly these warnings are being reported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In file included from /Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/window.cpp:58:
In file included from thirdparty/srt/srtcore/window.h:61:
thirdparty/srt/srtcore/packet.h:157:54: error: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
    return SEQNO_CONTROL::mask | SEQNO_MSGTYPE::wrap(size_t(type));
                                 ~~~~~~~~~~~~~       ^~~~~~~~~~~~
/Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/window.cpp:96:29: error: implicit conversion loses integer precision: 'long long' to 'const int' [-Werror,-Wshorten-64-to-32]
            const int rtt = count_microseconds(currtime - r_aSeq[i].tsTimeStamp);
                      ~~~   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/window.cpp:115:38: error: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Werror,-Wshorten-64-to-32]
   for (int j = r_iTail, n = r_iHead + size; j < n; ++ j)
                         ~   ~~~~~~~~^~~~~~
/Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/window.cpp:125:26: error: implicit conversion loses integer precision: 'long long' to 'const int' [-Werror,-Wshorten-64-to-32]
         const int rtt = count_microseconds(currtime - r_aSeq[j].tsTimeStamp);
                   ~~~   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/window.cpp:179:24: error: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
   for (int i = 0, n = asize; i < n; ++ i)
                   ~   ^~~~~
/Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/window.cpp:195:17: error: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Werror,-Wshorten-64-to-32]
      bytesps = (unsigned long)ceil(1000000.0 / (double(sum) / double(bytes)));
              ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/window.cpp:243:24: error: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
   for (int i = 0, n = psize; i < n; ++ i)
                   ~   ^~~~~
7 errors generated.
In file included from /Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/core.cpp:66:
In file included from thirdparty/srt/srtcore/api.h:63:
thirdparty/srt/srtcore/cache.h:116:20: error: ISO C++20 considers use of overloaded operator '==' (with operand types 'srt::CInfoBlock' and 'srt::CInfoBlock') to be ambiguous despite there being a unique best viable function [-Werror,-Wambiguous-reversed-operator]
         if (*data == ***i)
             ~~~~~ ^  ~~~~
/Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/core.cpp:4606:19: note: in instantiation of member function 'srt::CCache<srt::CInfoBlock>::lookup' requested here
    if (m_pCache->lookup(&ib) >= 0)
                  ^
In file included from /Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/core.cpp:66:
In file included from thirdparty/srt/srtcore/api.h:63:
thirdparty/srt/srtcore/cache.h:256:9: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
   bool operator==(const CInfoBlock& obj);
        ^
thirdparty/srt/srtcore/cache.h:146:20: error: ISO C++20 considers use of overloaded operator '==' (with operand types 'srt::CInfoBlock' and 'srt::CInfoBlock') to be ambiguous despite there being a unique best viable function [-Werror,-Wambiguous-reversed-operator]
         if (*data == ***i)
             ~~~~~ ^  ~~~~
/Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/core.cpp:6221:19: note: in instantiation of member function 'srt::CCache<srt::CInfoBlock>::update' requested here
        m_pCache->update(&ib);
                  ^
In file included from /Users/oliver/Git/source/ovlibs/ovnet/thirdparty/srt/srtcore/core.cpp:66:
In file included from thirdparty/srt/srtcore/api.h:63:
thirdparty/srt/srtcore/cache.h:256:9: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
   bool operator==(const CInfoBlock& obj);
        ^
thirdparty/srt/srtcore/cache.h:179:28: error: ISO C++20 considers use of overloaded operator '==' (with operand types 'srt::CInfoBlock' and 'srt::CInfoBlock') to be ambiguous despite there being a unique best viable function [-Werror,-Wambiguous-reversed-operator]
            if (*last_data == ***i)
                ~~~~~~~~~~ ^  ~~~~
thirdparty/srt/srtcore/cache.h:256:9: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
   bool operator==(const CInfoBlock& obj);
        ^
3 errors generated.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think breaking the gauge that shows a problem is not the best solution of the problem.

  1. Implicit conversion of type to size_t to be next used as uint32_t should be fixed by converting it first to uint32_t.
  2. The value of rtt if assigned from int64_t should be of type int64_t, not int. Further passing it to any calculations relying on int should then use an explicit conversion.
  3. Likely j in the loop, unless there's a risk of a negative value, should also use the size_t type.
  4. bytesps gets assigned a value that is explicitly converted - should then use the exact type of bytesps.
  5. The overloaded operator== for CInfoBlock likely lacks const.

Would you be able to try these above and retest if this also fixes the problems? If not, would you be able to send the list of the remaining problems so that I can prepare another fix?

Copy link
Contributor Author

@oviano oviano Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Ok.
  2. Maybe better to just cast to int straightaway from count_microseconds(currtime - r_aSeq[j].tsTimeStamp) as the precedent in SRT seems to be that RTT is an int.
  3. If you do this, you get warnings further down, for example r_iTail = (i + 1) % size now complains because r_iTail is an int, but the calculation is now size_t. Basically there is a mismatch throughout SRT where sizes are sometimes size_t, but the rest of the time int. Sometimes you set int to negative numbers/return (-1) to indicate an invalid value, so size_t can't be used everywhere. You could use ssize_t but that's not supported everywhere, so maybe it's just better to cast to (int) to remove these warnings?
  4. and 5. yes, trivial changes. I've done 5 already.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in (3) you can alternatively do r_iHead + int(size).

It's not about silencing warnings, but precisely defining your intentions.

Copy link
Contributor Author

@oviano oviano Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've worked through the remaining clang ones and casted in the way that makes sense to me.

Just going to re-enable the Windows warnings I had disabled, and fix any remaining ones on that platform.

It would be good if someone could just check my changes though to make sure.

Copy link
Contributor Author

@oviano oviano Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just working through the remaining Windows ones.

This code:

    // Note: Intentionally the "fixed char size" types are used despite using
    // character size dependent FormatMessage (instead of FormatMessageA) so that
    // your compilation fails when you use wide characters.
    // The problem is that when TCHAR != char, then the buffer written this way
    // would have to be converted to ASCII, not just copied by strncpy.
    FormatMessage(0
            | FORMAT_MESSAGE_ALLOCATE_BUFFER
            | FORMAT_MESSAGE_FROM_SYSTEM
            | FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL, // no lpSource
            errnum, // dwMessageId (as controlled by FORMAT_MESSAGE_FROM_SYSTEM)
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            // This below parameter normally should contain a pointer to an allocated buffer,
            // and this way it's LPTSTR. But when FORMAT_MESSAGE_ALLOCATE_BUFFER, then it is
            // expected to be a the value of LPTSTR* type, converted to LPTSTR, that designates
            // a pointer to a variable of type LPTSTR, to which the newly allocated buffer is
            // assigned. This buffer should be freed afterwards using LocalFree().
            (LPSTR)&lpMsgBuf,
            0, NULL);

    if (lpMsgBuf)
    {
        strncpy(buf, lpMsgBuf, buflen-1);
        buf[buflen-1] = 0;
        LocalFree((HLOCAL)lpMsgBuf);
    }
    else
    {
        SysStrError_Fallback(errnum, buf, buflen);
    }

Gives the warning incompatible types - from 'LPSTR' to 'LPWSTR'

Looking at the comment above - it seems to suggest we can't use SRT when compiled with wide characters. Thing is, SRT works just fine in my experience (many years) when compiled as wide char, so what would be the preferred workaround to deal with this warning? Can't we just use FormatMessageA?

Copy link
Collaborator

@ethouris ethouris Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like so. Especially that you skipped this line:

const char* lpMsgBuf;

Which should be const TCHAR* lpMsgBuf or something like that, and a similar transformation would have to be applied to the pointer type and likely the strncpy call as well, that is, it would have to change the encoding as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is, SysStrError is expected to return a char* to the caller (to write into log macros, etc) so why does this function need to anything with wide chars at all, it can just use FormatMessageA?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, as long as this form is perfectly portable (that is, Windows doesn't recommend to use FormatMessageA directly), that would be a better solution. @jlsantiago0 what do you think?

The clang version with latest Xcode gives a warning about the use of sprintf. The proper fix would be to replace sprintf with snprintf but I'm not too sure of the cross-platform cross-compiler implications of this.
@codecov-commenter
Copy link

Codecov Report

Merging #2411 (186cc06) into master (a08a42c) will decrease coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #2411      +/-   ##
==========================================
- Coverage   66.20%   66.19%   -0.02%     
==========================================
  Files          99       99              
  Lines       19841    19841              
==========================================
- Hits        13135    13133       -2     
- Misses       6706     6708       +2     
Impacted Files Coverage Δ
haicrypt/cryspr.c 23.11% <ø> (ø)
haicrypt/hcrypt_ctx_rx.c 63.63% <ø> (ø)
haicrypt/hcrypt_ctx_tx.c 53.01% <ø> (ø)
haicrypt/hcrypt_rx.c 25.86% <ø> (ø)
srtcore/cache.h 80.00% <0.00%> (-3.08%) ⬇️
srtcore/window.cpp 81.81% <0.00%> (-1.30%) ⬇️
srtcore/buffer_rcv.cpp 58.94% <0.00%> (-0.59%) ⬇️
srtcore/congctl.cpp 80.82% <0.00%> (-0.52%) ⬇️
srtcore/list.cpp 80.45% <0.00%> (-0.26%) ⬇️
srtcore/core.cpp 60.19% <0.00%> (ø)
... and 2 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@oviano
Copy link
Contributor Author

oviano commented Jan 16, 2023

Ok, I've removed the last warning pragmas and it builds for me on Win32, WinRT, Android, macOS, iOS and tvOS.

My Windows environment is VS2022, so hopefully your CI will pick up any issues with earlier versions of VS, but it seems to have failed above on a Linux test so maybe hasn't got that far.

@ethouris
Copy link
Collaborator

Note that merging it may take some more time because Max is on vacation this week.

@oviano
Copy link
Contributor Author

oviano commented Jan 17, 2023

Note that merging it may take some more time because Max is on vacation this week.

No problem!

Once merged, would you consider enabling warnings as errors so we can keep a lid on these warnings in future?

@ethouris
Copy link
Collaborator

I'm not sure if this is a good idea to do this by default. Adding an option for CMake build should do it, I hope.

@ethouris
Copy link
Collaborator

Fixes #1646

@maxsharabayko
Copy link
Collaborator

The Travis CI failure is unrelated to these changes. Merging.

@maxsharabayko maxsharabayko merged commit 21b55a2 into Haivision:master Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Type: Maintenance Work required to maintain or clean up the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants