Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Unified Diff: webrtc/modules/rtp_rtcp/source/byte_io.h

Issue 1226993003: Refactor byte_io to avoid potentially undefined behavior (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/rtp_rtcp/source/byte_io.h
diff --git a/webrtc/modules/rtp_rtcp/source/byte_io.h b/webrtc/modules/rtp_rtcp/source/byte_io.h
index 2617806dd941205c813a0b0c535f949429a6c97e..4ac47898baf1ee34f7e2226f9676210e5e6b4db5 100644
--- a/webrtc/modules/rtp_rtcp/source/byte_io.h
+++ b/webrtc/modules/rtp_rtcp/source/byte_io.h
@@ -88,13 +88,8 @@ class ByteReader {
static T SignExtend(const T val) {
uint8_t msb = static_cast<uint8_t>(val >> ((B - 1) * 8));
if (msb & 0x80) {
- // Sign extension is -1 (all ones) shifted left B bytes.
- // The "B % sizeof(T)"-part is there to avoid compiler warning for
- // shifting the whole size of the data type.
- T sign_extend = (sizeof(T) == B ? 0 :
- (static_cast<T>(-1L) << ((B % sizeof(T)) * 8)));
-
- return val | sign_extend;
+ T used_bits_mask = (1 << (B * 8)) - 1;
+ return ~used_bits_mask | val;
stefan-webrtc 2015/07/08 12:01:50 I think this deserves a comment. :)
sprang_webrtc 2015/07/08 12:57:03 Done.
}
return val;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698