Chromium Code Reviews| 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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 return size_t(1) << indexed_length; | 49 return size_t(1) << indexed_length; |
| 50 } | 50 } |
| 51 | 51 |
| 52 HpackHuffmanTable::HpackHuffmanTable() {} | 52 HpackHuffmanTable::HpackHuffmanTable() {} |
| 53 | 53 |
| 54 HpackHuffmanTable::~HpackHuffmanTable() {} | 54 HpackHuffmanTable::~HpackHuffmanTable() {} |
| 55 | 55 |
| 56 bool HpackHuffmanTable::Initialize(const HpackHuffmanSymbol* input_symbols, | 56 bool HpackHuffmanTable::Initialize(const HpackHuffmanSymbol* input_symbols, |
| 57 size_t symbol_count) { | 57 size_t symbol_count) { |
| 58 CHECK(!IsInitialized()); | 58 CHECK(!IsInitialized()); |
| 59 if (symbol_count > std::numeric_limits<uint16>::max()) | |
| 60 return false; | |
|
Bence
2014/12/01 18:18:38
Could this be a DCHECK to document requirements?
Peter Kasting
2014/12/02 02:13:55
Changed to a DCHECK and added a note to the declar
| |
| 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 |