-
Notifications
You must be signed in to change notification settings - Fork 866
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
Fixing a member (m_nHeader) being referenced before initialized #2433
Fixing a member (m_nHeader) being referenced before initialized #2433
Conversation
Hi @maxsharabayko Per your request, I tested SRT master branch and this branch IRT Issue #2400 . The Sanitizer error is the same in both cases:
|
NOTE: This reads from a memory address that has not been set. It is not too much of a problem, unless this memory location happens to reside in a virtual page frame that has not been mapped to a physical page frame, then it can segfault. This can happen when for instance a new page frame is created, but has never been written too. Reading from a memory address there can segfault. Either way it is undefined behavior. Perhaps |
This is because the OTOH I frankly never liked these reference fields. I have once tried to refax them to turn these names into methods returning ad-hoc references to these fields (or, this time, by using the PROPERTIES through |
No because it's a reference. References can't be set to NULL, and tricks to do it are even more dangerous. |
I think you can use the default constructor for |
Static sanitizer error.
ca0e23e
to
1a59f5a
Compare
Hmm, this PR actually helps to resolve the issue on GCC 12.0.1. Configurecmake .. -DENABLE_CODE_COVERAGE=ON -DENABLE_BONDING=ON -DCMAKE_CXX_FLAGS="-Werror" -DCMAKE_BUILD_TYPE=Debug Build (Before the Fix)[ 27%] Building CXX object CMakeFiles/srt_virtual.dir/srtcore/packet.cpp.o
/mnt/d/Projects/srt/srt-max/srtcore/packet.cpp: In constructor ‘srt::CPacket::CPacket()’:
/mnt/d/Projects/srt/srt-max/srtcore/packet.cpp:181:27: error: member ‘srt::CPacket::m_nHeader’ is used uninitialized [-Werror=uninitialized]
181 | , m_iSeqNo((int32_t&)(m_nHeader[SRT_PH_SEQNO]))
| ^~~~~~~~~
cc1plus: all warnings being treated as errors
make[2]: *** [CMakeFiles/srt_virtual.dir/build.make:300: CMakeFiles/srt_virtual.dir/srtcore/packet.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/srt_virtual.dir/all] Error 2
make: *** [Makefile:136: all] Error 2 After the FixAll built successfully. |
Codecov Report
@@ Coverage Diff @@
## master #2433 +/- ##
==========================================
+ Coverage 65.91% 66.33% +0.42%
==========================================
Files 100 100
Lines 19822 19795 -27
==========================================
+ Hits 13065 13131 +66
+ Misses 6757 6664 -93
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
This is only a formal compiler shut-up. The thing taken from these uninitialized fields is their reference, which remains the same after initialization. Moreover, this type doesn't feature an explicit constructor that would initialize the internal array field, which means that it is "default initialized" (not default-constructed), i. e. left with garbage. This is cleared in the call of At least this initialization entry deserves some comment that explains this in short. |
Fixed a member (
m_nHeader
) being referenced before initialized. Fixes #2400.Status
Seems to help when compiled with
-Werror
and GCC 12 (see this comment).(int32_t&) m_nHeader[SRT_PH_SEQNO]
is still a problem. Even thoughm_nHeader[SRT_PH_SEQNO]
is a valid address, dereferencing it worries the sanitizer because the value itself is not initialized.It is not an error in this case but would be nice to have it resolved.