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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/byte_io.h

Issue 1615653011: Fix a bug in webrtc::ByteReader (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 data[1] = val >> 8; 303 data[1] = val >> 8;
304 } 304 }
305 }; 305 };
306 306
307 // Specializations for four byte words. 307 // Specializations for four byte words.
308 template <typename T> 308 template <typename T>
309 class ByteReader<T, 4, false> { 309 class ByteReader<T, 4, false> {
310 public: 310 public:
311 static T ReadBigEndian(const uint8_t* data) { 311 static T ReadBigEndian(const uint8_t* data) {
312 static_assert(sizeof(T) >= 4, kSizeErrorMsg); 312 static_assert(sizeof(T) >= 4, kSizeErrorMsg);
313 return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; 313 return (Get(data, 0) << 24) | (Get(data, 1) << 16) | (Get(data, 2) << 8) |
314 Get(data, 3);
314 } 315 }
315 316
316 static T ReadLittleEndian(const uint8_t* data) { 317 static T ReadLittleEndian(const uint8_t* data) {
317 static_assert(sizeof(T) >= 4, kSizeErrorMsg); 318 static_assert(sizeof(T) >= 4, kSizeErrorMsg);
318 return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); 319 return Get(data, 0) | (Get(data, 1) << 8) | (Get(data, 2) << 16) |
320 (Get(data, 3) << 24);
321 }
322
323 private:
324 inline static T Get(const uint8_t* data, unsigned int index) {
325 return static_cast<T>(data[index]);
319 } 326 }
320 }; 327 };
321 328
322 // Specializations for four byte words. 329 // Specializations for four byte words.
323 template <typename T> 330 template <typename T>
324 class ByteWriter<T, 4, false> { 331 class ByteWriter<T, 4, false> {
325 public: 332 public:
326 static void WriteBigEndian(uint8_t* data, T val) { 333 static void WriteBigEndian(uint8_t* data, T val) {
327 static_assert(sizeof(T) >= 4, kSizeErrorMsg); 334 static_assert(sizeof(T) >= 4, kSizeErrorMsg);
328 data[0] = val >> 24; 335 data[0] = val >> 24;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 data[4] = val >> 32; 399 data[4] = val >> 32;
393 data[5] = val >> 40; 400 data[5] = val >> 40;
394 data[6] = val >> 48; 401 data[6] = val >> 48;
395 data[7] = val >> 56; 402 data[7] = val >> 56;
396 } 403 }
397 }; 404 };
398 405
399 } // namespace webrtc 406 } // namespace webrtc
400 407
401 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_BYTE_IO_H_ 408 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_BYTE_IO_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698