Skip to content

Commit

Permalink
[core] Fixed srt_getsockopt cast for bool options (#1925)
Browse files Browse the repository at this point in the history
Cast to bool instead of int in srt_getsockopt(..) for:
- SRTO_SENDER
- SRTO_TSBPDMODE
- SRTO_DRIFTTRACER
- SRTO_ENFORCEDENCRYPTION

Additionally:
- Fixed TestEnforcedEncryption: bool optval
- Minor improvements to Travis run_codecov
  • Loading branch information
maxsharabayko authored Apr 14, 2021
1 parent 109f667 commit 4f06c2e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ script:
fi
- if [ "$TRAVIS_COMPILER" != "x86_64-w64-mingw32-g++" ]; then
./test-srt --gtest_filter="-TestMuxer.IPv4_and_IPv6:TestIPv6.v6_calls_v6*";
source ./scripts/collect-gcov.sh;
fi
- if (( "$RUN_CODECOV" )); then
source ./scripts/collect-gcov.sh;
bash <(curl -s https://codecov.io/bash);
fi
- if (( "$RUN_SONARCUBE" )); then
Expand Down
16 changes: 8 additions & 8 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,13 @@ void CUDT::getOpt(SRT_SOCKOPT optName, void *optval, int &optlen)
break;

case SRTO_SENDER:
*(int32_t *)optval = m_config.bDataSender;
optlen = sizeof(int32_t);
*(bool *)optval = m_config.bDataSender;
optlen = sizeof(bool);
break;

case SRTO_TSBPDMODE:
*(int32_t *)optval = m_config.bTSBPD;
optlen = sizeof(int32_t);
*(bool *)optval = m_config.bTSBPD;
optlen = sizeof(bool);
break;

case SRTO_LATENCY:
Expand Down Expand Up @@ -679,8 +679,8 @@ void CUDT::getOpt(SRT_SOCKOPT optName, void *optval, int &optlen)
break;

case SRTO_DRIFTTRACER:
*(int*)optval = m_config.bDriftTracer;
optlen = sizeof(int);
*(bool*)optval = m_config.bDriftTracer;
optlen = sizeof(bool);
break;

case SRTO_MINVERSION:
Expand Down Expand Up @@ -734,8 +734,8 @@ void CUDT::getOpt(SRT_SOCKOPT optName, void *optval, int &optlen)
#endif

case SRTO_ENFORCEDENCRYPTION:
optlen = sizeof(int32_t); // also with TSBPDMODE and SENDER
*(int32_t *)optval = m_config.bEnforcedEnc;
optlen = sizeof(bool);
*(bool *)optval = m_config.bEnforcedEnc;
break;

case SRTO_IPV6ONLY:
Expand Down
12 changes: 6 additions & 6 deletions test/test_enforced_encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ class TestEnforcedEncryption
bool GetEnforcedEncryption(PEER_TYPE peer_type)
{
const SRTSOCKET socket = peer_type == PEER_CALLER ? m_caller_socket : m_listener_socket;
int value = -1;
int value_len = sizeof value;
EXPECT_EQ(srt_getsockopt(socket, 0, SRTO_ENFORCEDENCRYPTION, (void*)&value, &value_len), SRT_SUCCESS);
return value ? true : false;
bool optval;
int optlen = sizeof optval;
EXPECT_EQ(srt_getsockopt(socket, 0, SRTO_ENFORCEDENCRYPTION, (void*)&optval, &optlen), SRT_SUCCESS);
return optval ? true : false;
}


Expand Down Expand Up @@ -503,8 +503,8 @@ class TestEnforcedEncryption

int m_pollid = 0;

const int s_yes = 1;
const int s_no = 0;
const bool s_yes = true;
const bool s_no = false;

const bool m_is_tracing = false;
static const char* m_km_state[];
Expand Down

0 comments on commit 4f06c2e

Please sign in to comment.