Fix ASAN reported bug
authorAngelo Failla <pallotron@fb.com>
Tue, 18 Apr 2017 07:10:48 +0000 (00:10 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 18 Apr 2017 07:19:51 +0000 (00:19 -0700)
Reviewed By: yfeldblum

Differential Revision: D4898404

fbshipit-source-id: 82256ae3dcd76444dc1b192d3bb6d50f142cee81

folly/IPAddressV6.cpp

index c7a93efef96224f3564caedf787b85187b7b7665..57d00aa4b71f416d25dd8d04cc56ba2fd19dca0a 100644 (file)
@@ -186,14 +186,14 @@ IPAddressV6 IPAddressV6::fromInverseArpaName(const std::string& arpaname) {
     throw IPAddressFormatException(sformat("Invalid input. Got '{}'", piece));
   }
   std::array<char, IPAddressV6::kToFullyQualifiedSize> ip;
-  int pos = 0;
+  size_t pos = 0;
   int count = 0;
   for (int p = pieces.size() - 1; p >= 0; p--) {
     ip[pos] = pieces[p][0];
     pos++;
     count++;
     // add ':' every 4 chars
-    if (count == 4) {
+    if (count == 4 && pos < ip.size()) {
       ip[pos++] = ':';
       count = 0;
     }