Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Detecting errors in String operations

オープン
#186 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp
領域
api, embedded-iot

調査の方向性

この issue には setup()、wasteAlmostAllMemory()、returnLongString() の C++ 例が示されていますが、実装ファイルやテストは指定されていません。まず Arduino String の実装と、連結、代入、返される文字列に使用されているパスを見つけてください。提供された失敗チェックが部分的な出力やコントローラーのクラッシュなしにエラーを一貫して検出し、回帰テストのカバレッジがあることが完了の条件です。

索引モデルが issue の本文から書いたものです。

説明

Hello,

If a String creation fails it is possible to detect this error in the code, like:

String s = "abc";
if (!s) ... // error, out of heap or something ...

However the error detection doesn't work with String expressions:

#define howLarge 5000
String *strArray = new String [howLarge]; 

void wasteAlmostAllMemory () {
  for (int i = 0; i < howLarge; i++) strArray [i] = " wasted memory ";
  while (true)
    for (int i = 0; i < howLarge; i++)
      if (!strArray [i].concat (" more wasted memory "))
        return;
} 

String returnLongString () {
  return "This is a long string, much longer than fits into free memory, although not right now.";
}

void setup () {
    Serial.begin (115200);

    String longString = returnLongString ();

    Serial.printf ("Wasting memory, please wait ... ");
    wasteAlmostAllMemory ();
    Serial.printf ("memory successfuly wasted\n");

    String resultString;

    // 1.
      resultString = longString;
      if (!resultString)
        Serial.printf ("Could not create a long String s.\n"); // error detected successfuly
      else { Serial.print ("'"); Serial.print (resultString); Serial.println ("'"); }

    // 2.
      resultString = "ABC " + longString + " DEF";
      if (!resultString)
        Serial.printf ("Could not calculate a String s.\n"); // error goes by undetected
      else { Serial.print ("'"); Serial.print (resultString); Serial.println ("'"); } // the output is: ' DEF' 

    // 3.
      resultString = returnLongString (); // failure to create the return String crashes the controller
}

void loop () {

}

My proposal is that each string expression that contains string in "error state" result in string also in "error state", so success could be tested only once even after several String operations. Something like this:

    String s = "abc";
    for (int i = 1; i < 1000; i++)
      s += s.substring (1, 1);
    if (!s) ... // error

Thank you.

主要言語
C++
スター
306
フォーク
150
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

arduino/ArduinoCore-API のほかの issue

arduino/ArduinoCore-API の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。