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

cJSON_Print trapped in an infinite loop when elements are added a certain way

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

メンテナーはふだん 12 日以内に返信

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
c
領域
backend

調査の方向性

まず最小限の C スニペットをコンパイルして実行し、cJSON_Print でハングする問題を再現します。messages 配列と、再利用される system ノードおよび message ノードの走査を追跡し、印刷が有効な JSON で終了することと、クリーンアップのシーケンスが安全なままであることを確認します。

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

説明

Here is a strange behavior of cJSON_Print. When the subtree it is transversing contains a node referenced by an ancestor node, it ends up in an infinite loop. The only way this can happen is if leaf nodes link back to their parents and cJSON_Print tries to transverse this path, resulting in a circular dep. Even this assumption doesn't hold up considering that when the order of placing objects message and system into the messages array is swapped (i.e., adding system before message), printing works perfectly.

Here is a minimal snippet to reproduce this behavior.

#include <stdio.h>
#include <stdlib.h>
#include "../cJSON/cJSON.h"
int main() {
    cJSON *bin = cJSON_CreateArray();
    cJSON *root = cJSON_CreateObject();
    cJSON *system = cJSON_CreateObject();
    cJSON *message = cJSON_CreateObject();
    cJSON *messages = cJSON_CreateArray();

    cJSON_AddItemToArray(bin, root);
    cJSON_AddItemToArray(bin, system);
    cJSON_AddItemToArray(bin, message);
    cJSON_AddItemToArray(messages, message);
    cJSON_AddItemToArray(messages, system);
    cJSON_AddItemToObject(root, "messages", messages);

    char *json_string = cJSON_Print(root);
    printf("%s\n", json_string);
    free(json_string);

cleanup:     
    cJSON_DetachItemFromArray(bin, 0);
    cJSON_DetachItemFromArray(bin, 0);
    cJSON_DetachItemFromArray(bin, 0);    
    cJSON_Delete(root);
    cJSON_Delete(bin);

    return 0;
}

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

環境構築

はじめの一歩

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

DaveGamble/cJSON のほかの issue

DaveGamble/cJSON の issue をすべて見る

似ている issue

C の issue をもっと見る

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

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