ext/oj/fast.c in oj-3.13.9 vs ext/oj/fast.c in oj-3.13.10

- old
+ new

@@ -769,11 +769,11 @@ pi.s = pi.str; doc_init(doc); pi.doc = doc; #if IS_WINDOWS // assume a 1M stack and give half to ruby - pi.stack_min = (void*)((char*)&pi - (512 * 1024)); + pi.stack_min = (void *)((char *)&pi - (512 * 1024)); #else { struct rlimit lim; if (0 == getrlimit(RLIMIT_STACK, &lim) && RLIM_INFINITY != lim.rlim_cur) { @@ -1490,10 +1490,11 @@ if (rb_block_given_p()) { Leaf save_path[MAX_STACK]; Doc doc = self_doc(self); const char *path = 0; size_t wlen; + Leaf * where_orig = doc->where; wlen = doc->where - doc->where_path; if (0 < wlen) { memcpy(save_path, doc->where_path, sizeof(Leaf) * (wlen + 1)); } @@ -1506,13 +1507,17 @@ } if (0 != move_step(doc, path, 1)) { if (0 < wlen) { memcpy(doc->where_path, save_path, sizeof(Leaf) * (wlen + 1)); } + doc->where = where_orig; return Qnil; } } + if (NULL == doc->where || NULL == *doc->where) { + return Qnil; + } if (COL_VAL == (*doc->where)->value_type && 0 != (*doc->where)->elements) { Leaf first = (*doc->where)->elements->next; Leaf e = first; doc->where++; @@ -1523,9 +1528,10 @@ } while (e != first); } if (0 < wlen) { memcpy(doc->where_path, save_path, sizeof(Leaf) * (wlen + 1)); } + doc->where = where_orig; } return Qnil; } /* @overload each_value(path=nil) { |val| ... } => nil