Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

String move() and String(String &&rval) breaks operation of reserve()

Open
#161 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
embedded-iot

Research direction

Locate the C++11 String implementation and inspect move(), operator=, the String(String &&rval) constructor, and reserve() behavior. Verify how a reserved destination behaves during a move, then confirm that the constructor follows the intended move path and that moved-from strings remain valid.

Written by the indexing model from the issue text.

Description

When #if __cplusplus >= 201103L || defined(GXX_EXPERIMENTAL_CXX0X)
operator = uses move() to just update the buffer pointer of the destination
This ignores any reserve() the user has made to ensure the memory is not unnecessarily fragmented.
String(String &&rval) has a similar problem

move() should first check the capacity of the destination and if there is sufficient space copy the source to the destination
String(String &&rval) should use move()

A suggested move() is

void String::move(String &rhs) {
	if (this != &rhs) {
           if (capacity > rhs.size) {
               copy(rhs.buffer,rhs.size);
             } else {
		free(buffer);
		buffer = rhs.buffer;
		len = rhs.len;
		capacity = rhs.capacity;
             }
		rhs.buffer = NULL;
		rhs.len = 0;
		rhs.capacity = 0;
	}
}
Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from arduino/ArduinoCore-API

All issues in arduino/ArduinoCore-API

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.