诸暨麻将添加redis
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

100 lines
3.7 KiB

  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #ifndef GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__
  31. #define GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__
  32. #include <google/protobuf/stubs/logging.h>
  33. #include <google/protobuf/stubs/common.h>
  34. #include <google/protobuf/io/coded_stream.h>
  35. #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
  36. #include <google/protobuf/arena.h>
  37. namespace google {
  38. namespace protobuf {
  39. template <typename T, bool use_arena>
  40. void TestParseCorruptedString(const T& message) {
  41. int success_count = 0;
  42. std::string s;
  43. {
  44. // Map order is not deterministic. To make the test deterministic we want
  45. // to serialize the proto deterministically.
  46. io::StringOutputStream output(&s);
  47. io::CodedOutputStream out(&output);
  48. out.SetSerializationDeterministic(true);
  49. message.SerializePartialToCodedStream(&out);
  50. }
  51. const int kMaxIters = 900;
  52. const int stride = s.size() <= kMaxIters ? 1 : s.size() / kMaxIters;
  53. const int start = stride == 1 || use_arena ? 0 : (stride + 1) / 2;
  54. for (int i = start; i < s.size(); i += stride) {
  55. for (int c = 1 + (i % 17); c < 256; c += 2 * c + (i & 3)) {
  56. s[i] ^= c;
  57. Arena arena;
  58. T* message = Arena::CreateMessage<T>(use_arena ? &arena : nullptr);
  59. if (message->ParseFromString(s)) {
  60. ++success_count;
  61. }
  62. if (!use_arena) {
  63. delete message;
  64. }
  65. s[i] ^= c; // Restore s to its original state.
  66. }
  67. }
  68. // This next line is a low bar. But getting through the test without crashing
  69. // due to use-after-free or other bugs is a big part of what we're checking.
  70. GOOGLE_CHECK_GT(success_count, 0);
  71. }
  72. namespace internal {
  73. class NoHeapChecker {
  74. public:
  75. NoHeapChecker() { capture_alloc.Hook(); }
  76. ~NoHeapChecker();
  77. private:
  78. class NewDeleteCapture {
  79. public:
  80. // TOOD(xiaofeng): Implement this for opensource protobuf.
  81. void Hook() {}
  82. void Unhook() {}
  83. int alloc_count() { return 0; }
  84. int free_count() { return 0; }
  85. } capture_alloc;
  86. };
  87. } // namespace internal
  88. } // namespace protobuf
  89. } // namespace google
  90. #endif // GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__