diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-18 23:22:33 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-18 23:22:33 +0000 |
commit | 5368d6fd2781f457d25b16e59c13bd6b70baed93 (patch) | |
tree | 5f516c667ed9eeb69fb3e7aef12bbc051fcc1cc1 | |
parent | 2ef7e2abebd1d702ff22cac67a0dd7f2660fd875 (diff) | |
download | chromium_src-5368d6fd2781f457d25b16e59c13bd6b70baed93.zip chromium_src-5368d6fd2781f457d25b16e59c13bd6b70baed93.tar.gz chromium_src-5368d6fd2781f457d25b16e59c13bd6b70baed93.tar.bz2 |
Refactor so checking for number error is done by ParseChunkSize() rather than the caller of ParseChunkSize().
Review URL: http://codereview.chromium.org/132037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18768 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/http/http_chunked_decoder.cc | 12 | ||||
-rw-r--r-- | net/http/http_chunked_decoder.h | 6 |
2 files changed, 12 insertions, 6 deletions
diff --git a/net/http/http_chunked_decoder.cc b/net/http/http_chunked_decoder.cc index 6ecdcad..71f7554 100644 --- a/net/http/http_chunked_decoder.cc +++ b/net/http/http_chunked_decoder.cc @@ -125,8 +125,7 @@ int HttpChunkedDecoder::ScanForChunkRemaining(const char* buf, int buf_len) { if (index_of_semicolon != StringPiece::npos) buf_len = static_cast<int>(index_of_semicolon); - if (!ParseChunkSize(buf, buf_len, &chunk_remaining_) || - chunk_remaining_ < 0) { + if (!ParseChunkSize(buf, buf_len, &chunk_remaining_)) { DLOG(ERROR) << "Failed parsing HEX from: " << std::string(buf, buf_len); return ERR_INVALID_CHUNKED_ENCODING; @@ -185,7 +184,14 @@ bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) { if (StringPiece(start, len).find_first_not_of("0123456789abcdefABCDEF")!= StringPiece::npos) return false; - return HexStringToInt(std::string(start, len), out); + + int parsed_number; + bool ok = HexStringToInt(std::string(start, len), &parsed_number); + if (ok && parsed_number >= 0) { + *out = parsed_number; + return true; + } + return false; } } // namespace net diff --git a/net/http/http_chunked_decoder.h b/net/http/http_chunked_decoder.h index 1eb3ea0..f87ae5e 100644 --- a/net/http/http_chunked_decoder.h +++ b/net/http/http_chunked_decoder.h @@ -84,14 +84,14 @@ class HttpChunkedDecoder { int FilterBuf(char* buf, int buf_len); private: - // Scan |buf| for the next chunk delimiter. This method returns the number + // Scans |buf| for the next chunk delimiter. This method returns the number // of bytes consumed from |buf|. If found, |chunk_remaining_| holds the // value for the next chunk size. int ScanForChunkRemaining(const char* buf, int buf_len); - // Convert string |start| of length |len| to a numeric value. + // Converts string |start| of length |len| to a numeric value. // |start| is a string of type "chunk-size" (hex string). - // If the conversion succeeds, return true and place the result in |out|. + // If the conversion succeeds, returns true and places the result in |out|. static bool ParseChunkSize(const char* start, int len, int* out); // Indicates the number of bytes remaining for the current chunk. |