0001-json-array-erase-relocate.patch 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. From 07d7c3b2e0f8c6b269ba167117cd3e549df2f342 Mon Sep 17 00:00:00 2001
  2. From: Vinnie Falco <vinnie.falco@gmail.com>
  3. Date: Wed, 13 Apr 2022 05:49:05 -0700
  4. Subject: [PATCH] array::erase relocates correctly
  5. fix #692
  6. Signed-off-by: Michael Nosthoff<buildroot@heine.tech>
  7. [Upstream status: https://github.com/boostorg/json/issues/692]
  8. ---
  9. boost/json/impl/array.ipp | 5 ++++-
  10. test/array.cpp | 16 ++++++++++++++++
  11. 2 files changed, 20 insertions(+), 1 deletion(-)
  12. diff --git a/boost/json/impl/array.ipp b/boost/json/impl/array.ipp
  13. index 4d067fb5..a2c7fd6d 100644
  14. --- a/boost/json/impl/array.ipp
  15. +++ b/boost/json/impl/array.ipp
  16. @@ -491,8 +491,11 @@ erase(
  17. auto const p = &(*t_)[0] +
  18. (pos - &(*t_)[0]);
  19. destroy(p, p + 1);
  20. - relocate(p, p + 1, 1);
  21. --t_->size;
  22. + if(t_->size > 0)
  23. + relocate(p, p + 1,
  24. + t_->size - (p -
  25. + &(*t_)[0]));
  26. return p;
  27. }
  28. diff --git a/libs/json/test/array.cpp b/libs/json/test/array.cpp
  29. index 1cc87566..4516cc78 100644
  30. --- a/libs/json/test/array.cpp
  31. +++ b/libs/json/test/array.cpp
  32. @@ -1269,6 +1269,21 @@ class array_test
  33. array{nullptr, "a", "b"}));
  34. }
  35. + void
  36. + testIssue692()
  37. + {
  38. + array a;
  39. + object obj;
  40. + obj["test1"] = "hello";
  41. + a.push_back(obj);
  42. + a.push_back(obj);
  43. + a.push_back(obj);
  44. + a.push_back(obj);
  45. + a.push_back(obj);
  46. + while(a.size())
  47. + a.erase(a.begin());
  48. + }
  49. +
  50. void
  51. run()
  52. {
  53. @@ -1283,6 +1298,7 @@ class array_test
  54. testExceptions();
  55. testEquality();
  56. testHash();
  57. + testIssue692();
  58. }
  59. };