cJSON_Print trapped in an infinite loop when elements are added a certain way
メンテナーはふだん 12 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず最小限の 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 はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
DaveGamble/cJSON のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DaveGamble/cJSON#1106 ·
メンテナーはふだん 12 日以内に返信
-
Undefined-Behavior in function cJSON_SetNumberHelper対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
DaveGamble/cJSON#1100 · リアクション 1 件 ·
メンテナーはふだん 12 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
DaveGamble/cJSON#1094 · コメント 9 件 · リアクション 1 件 ·
メンテナーはふだん 12 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DaveGamble/cJSON#1093 ·
メンテナーはふだん 12 日以内に返信
-
Use-after-free in cJSONUtils_ApplyPatches when a patch removes the patch array対応中かも @iliasabk が 28 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
DaveGamble/cJSON#1082 ·
メンテナーはふだん 12 日以内に返信
DaveGamble/cJSON の issue をすべて見る
似ている issue
-
category:port-update
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 8 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
native-cpu: -Wreturn-type in skainet_row_threads.c:150 (worker fn has no return)対応中かも @Doomguy-BFG9000 が今日担当しました。 オープンgood first issue size:xs skill:native
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
SKaiNET-developers/SKaiNET#1358 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信