Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Merge requests
  • !524

Delete the copy constructor and copy assignment operators for StaticJsonBufferBase.

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/Keenwawa/disallow-buffer-copying into master Jun 12, 2017
  • Overview 1
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: luisrayas3

These are always invalid, regardless of usage of objects created in the buffer(s). The root of the problem with using the default copy operators is that the _buffer pointer is copied as well, which means that the copied-to buffer now points to the copied-from buffer's memory.

Consider the clearing example at the bottom of https://arduinojson.org/faq/how-to-reuse-a-jsonbuffer/

StaticJsonBuffer<200> buf{};

JsonObject& obj = buf.createObject();
// Use obj, etc.

buf = StaticJsonBuffer<200>();
// StaticJsonBufferBase::_buffer points to deallocated memory of the temporary

JsonObject& new_obj = buf.createObject();
// Even if I never touch `obj` again, new_obj can easily become corrupted.

Properly implemented copy operators will have to be provided by the concrete buffer types (e.g. StaticJsonBuffer) and something sensible needs to be done about mis-matched capacities.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/Keenwawa/disallow-buffer-copying