| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/spdy/hpack_huffman_table.h" | 5 #include "net/spdy/hpack_huffman_table.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/numerics/safe_conversions.h" |
| 11 #include "net/spdy/hpack_input_stream.h" | 12 #include "net/spdy/hpack_input_stream.h" |
| 12 #include "net/spdy/hpack_output_stream.h" | 13 #include "net/spdy/hpack_output_stream.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 using base::StringPiece; | 17 using base::StringPiece; |
| 17 using std::string; | 18 using std::string; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 49 return size_t(1) << indexed_length; | 50 return size_t(1) << indexed_length; |
| 50 } | 51 } |
| 51 | 52 |
| 52 HpackHuffmanTable::HpackHuffmanTable() {} | 53 HpackHuffmanTable::HpackHuffmanTable() {} |
| 53 | 54 |
| 54 HpackHuffmanTable::~HpackHuffmanTable() {} | 55 HpackHuffmanTable::~HpackHuffmanTable() {} |
| 55 | 56 |
| 56 bool HpackHuffmanTable::Initialize(const HpackHuffmanSymbol* input_symbols, | 57 bool HpackHuffmanTable::Initialize(const HpackHuffmanSymbol* input_symbols, |
| 57 size_t symbol_count) { | 58 size_t symbol_count) { |
| 58 CHECK(!IsInitialized()); | 59 CHECK(!IsInitialized()); |
| 60 DCHECK(base::IsValueInRangeForNumericType<uint16>(symbol_count)); |
| 59 | 61 |
| 60 std::vector<Symbol> symbols(symbol_count); | 62 std::vector<Symbol> symbols(symbol_count); |
| 61 // Validate symbol id sequence, and copy into |symbols|. | 63 // Validate symbol id sequence, and copy into |symbols|. |
| 62 for (size_t i = 0; i != symbol_count; i++) { | 64 for (uint16 i = 0; i < symbol_count; i++) { |
| 63 if (i != input_symbols[i].id) { | 65 if (i != input_symbols[i].id) { |
| 64 failed_symbol_id_ = i; | 66 failed_symbol_id_ = i; |
| 65 return false; | 67 return false; |
| 66 } | 68 } |
| 67 symbols[i] = input_symbols[i]; | 69 symbols[i] = input_symbols[i]; |
| 68 } | 70 } |
| 69 // Order on length and ID ascending, to verify symbol codes are canonical. | 71 // Order on length and ID ascending, to verify symbol codes are canonical. |
| 70 std::sort(symbols.begin(), symbols.end(), SymbolLengthAndIdCompare); | 72 std::sort(symbols.begin(), symbols.end(), SymbolLengthAndIdCompare); |
| 71 if (symbols[0].code != 0) { | 73 if (symbols[0].code != 0) { |
| 72 failed_symbol_id_ = 0; | 74 failed_symbol_id_ = 0; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 bits = bits << entry.length; | 316 bits = bits << entry.length; |
| 315 bits_available -= entry.length; | 317 bits_available -= entry.length; |
| 316 } | 318 } |
| 317 peeked_success = in->PeekBits(&bits_available, &bits); | 319 peeked_success = in->PeekBits(&bits_available, &bits); |
| 318 } | 320 } |
| 319 NOTREACHED(); | 321 NOTREACHED(); |
| 320 return false; | 322 return false; |
| 321 } | 323 } |
| 322 | 324 |
| 323 } // namespace net | 325 } // namespace net |
| OLD | NEW |