)]}'
{
  "commit": "53020a5d3361adca1c36b6a79221858f5954c3c1",
  "tree": "e362f9ec449535f650f64727768f4ebaacdae7f7",
  "parents": [
    "73fe5e2fe464313f2e5bd0187d00184e1de4c3a8"
  ],
  "author": {
    "name": "bnc",
    "email": "bnc@google.com",
    "time": "Mon May 16 12:35:34 2022 -0700"
  },
  "committer": {
    "name": "Copybara-Service",
    "email": "copybara-worker@google.com",
    "time": "Mon May 16 12:37:09 2022 -0700"
  },
  "message": "Lazy reserve in SimpleBuffer.\n\nAlso make sure at least kMinimumSimpleBufferSize bytes are allocated, even if\nconstructor with size argument is called with a smaller value.\n\nThis slightly simplifies the implementation, allows removal of QUICH_CHECK in\nSimpleBuffer::SimpleBuffer(int size) (since there is a QUICHE_BUG in Reserve(),\nand QUICHE_BUG is more suitable for API violations than a CHECK anyway), and\nmakes it more obvious in Reserve() that `storage_` may be nullptr.\n\nThe issue that prompted this change is that SimpleBufferTest.ReleaseAsSlice\ncrashes at the memcpy on old line 104 on Envoy CI with ASAN build (which implies\nUBSAN).  This is because ReleaseAsSlice() leaves SimpleBuffer (unless it was\nempy beforehand) in an unusual state of `storage_` being nullptr, on the\nreasonable assumption that the object will probably not be used again.  But it\nis also reasonable to assume that the object is left in a valid state, so that\nit can be read from and written to, and Reserve() will take care of allocating\nstorage if necessary.  Except Reserve() calls memcpy with nullptr (and zero\ncount) in this case.\n\nAnd memcpy must not be called with nullptr, even if count is zero, otherwise\nbehavior is undefined according to\nhttps://en.cppreference.com/w/cpp/string/byte/memcpy.\n\nInstead of applying a Band-aid of special casing `storage_` being nullptr before\nthe memcpy call, and relying on test coverage only in tests that call\nReleaseAsSlice() to put SimpleBuffer in this special case, it is more elegant to\nmake this the default state of SimpleBuffer, so that it is handled more\nprominently in the implementation, and tested more thoroughly.\n\nThe cost is an extra method call and a few branches when the object is first\nused.  The gain is one allocation saved if the initial write is larger than 10\nbytes, and one allocation saved if the object is never used.\n\nAlso make Reserve() call unconditional in Write() for simplicity.  Reserve()\nmakes the same check anyway.\n\nAlso get rid of unnecessary `new_storage_size` local variable, and use\nstd::max() instead of branch.\n\nAlso remove Test prefix from test cases.\n\nPiperOrigin-RevId: 449027799\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "268fca44253a82e17ca56ea5c4ffd94867332f76",
      "old_mode": 33188,
      "old_path": "quiche/balsa/simple_buffer.cc",
      "new_id": "c32f0f094f21b331cfbc50893f6b7699e7079e0b",
      "new_mode": 33188,
      "new_path": "quiche/balsa/simple_buffer.cc"
    },
    {
      "type": "modify",
      "old_id": "d669899d2ccd35a91c9abe33946a1c3222a9641b",
      "old_mode": 33188,
      "old_path": "quiche/balsa/simple_buffer.h",
      "new_id": "fe81e33d4f15e05a83cebd8f828fb6631f3726d4",
      "new_mode": 33188,
      "new_path": "quiche/balsa/simple_buffer.h"
    },
    {
      "type": "modify",
      "old_id": "21e279f1a147a08ff1c25cd2b12ecbb63c1af6f0",
      "old_mode": 33188,
      "old_path": "quiche/balsa/simple_buffer_test.cc",
      "new_id": "0f5bbbbf2979709dd6ed5d6c6c324b93d2bfea75",
      "new_mode": 33188,
      "new_path": "quiche/balsa/simple_buffer_test.cc"
    }
  ]
}
