File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ JSON 数组存储零至多个元素,最简单就是使用 C 语言的数组。
3535
3636我见过一些 JSON 库选择了链表,而这里则选择了数组。我们将会通过之前在解析字符串时实现的堆栈,来解决解析 JSON 数组时未知数组大小的问题。
3737
38- 决定之后,我们在 ` kept_value ` 的 ` union ` 中加入数组的结构:
38+ 决定之后,我们在 ` lept_value ` 的 ` union ` 中加入数组的结构:
3939
4040~~~ c
4141typedef struct lept_value lept_value;
@@ -220,7 +220,7 @@ static int lept_parse_value(lept_context* c, lept_value* v) {
220220
2212212 . 现时的测试结果应该是失败的,因为 ` lept_parse_array() ` 里没有处理空白字符,加进合适的 ` lept_parse_whitespace() ` 令测试通过。
222222
223- 3 . 使用第四单元介绍的检测内存泄漏工具 ,会发现测试中有内存泄漏。很明显在 ` lept_parse_array() ` 中使用到 ` malloc() ` 分配内存,但却没有对应的 ` free() ` 。应该在哪里释放内存?修改代码,使工具不再检测到相关的内存泄漏。
223+ 3 . 使用 [ 第三单元解答篇 ] ( ../tutorial03_answer/tutorial03_answer.md ) 介绍的检测内存泄漏工具 ,会发现测试中有内存泄漏。很明显在 ` lept_parse_array() ` 中使用到 ` malloc() ` 分配内存,但却没有对应的 ` free() ` 。应该在哪里释放内存?修改代码,使工具不再检测到相关的内存泄漏。
224224
2252254 . 开启 test.c 中两处被 ` #if 0 ... #endif ` 关闭的测试,本来 ` test_parse_array() ` 已经能处理这些测试。然而,运行时会发现 ` Assertion failed: (c.top == 0) ` 断言失败。这是由于,当错误发生时,仍然有一些临时值在堆栈里,既没有放进数组,也没有被释放。修改 ` test_parse_array() ` ,当遇到错误时,从堆栈中弹出并释放那些临时值,然后才返回错误码。
226226
You can’t perform that action at this time.
0 commit comments