| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/media/cast_remoting_connector_messaging.h" | 5 #include "chrome/browser/media/cast_remoting_connector_messaging.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 // static | 44 // static |
| 45 int32_t CastRemotingConnectorMessaging::GetStreamIdFromStartedMessage( | 45 int32_t CastRemotingConnectorMessaging::GetStreamIdFromStartedMessage( |
| 46 base::StringPiece message, base::StringPiece specifier) { | 46 base::StringPiece message, base::StringPiece specifier) { |
| 47 auto start = message.find(specifier); | 47 auto start = message.find(specifier); |
| 48 if (start == std::string::npos) | 48 if (start == std::string::npos) |
| 49 return -1; | 49 return -1; |
| 50 start += specifier.size(); | 50 start += specifier.size(); |
| 51 if (start + 1 >= message.size()) | 51 if (start + 1 >= message.size()) |
| 52 return -1; // Must be at least one hex digit following the specifier. | 52 return -1; // Must be at least one hex digit following the specifier. |
| 53 const auto length = message.find(kMessageFieldSeparator, start) - start; |
| 53 int parsed_value; | 54 int parsed_value; |
| 54 if (!base::HexStringToInt( | 55 if (!base::HexStringToInt(message.substr(start, length), &parsed_value) || |
| 55 message.substr(start, message.find(kMessageFieldSeparator, start)), | |
| 56 &parsed_value) || | |
| 57 parsed_value < 0 || | 56 parsed_value < 0 || |
| 58 parsed_value > std::numeric_limits<int32_t>::max()) { | 57 parsed_value > std::numeric_limits<int32_t>::max()) { |
| 59 return -1; // Non-hex digits, or outside valid range. | 58 return -1; // Non-hex digits, or outside valid range. |
| 60 } | 59 } |
| 61 return static_cast<int32_t>(parsed_value); | 60 return static_cast<int32_t>(parsed_value); |
| 62 } | 61 } |
| OLD | NEW |