Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't ignore errors reported by skip_bytes() #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2739,7 +2739,9 @@ bool cmp_skip_object(cmp_ctx_t *ctx, cmp_object_t *obj) {
break;
}

skip_bytes(ctx, size);
if (!skip_bytes(ctx, size)) {
return false;
}
}
}

Expand Down Expand Up @@ -2806,7 +2808,9 @@ bool cmp_skip_object_flat(cmp_ctx_t *ctx, cmp_object_t *obj) {
break;
}

skip_bytes(ctx, size);
if (!skip_bytes(ctx, size)) {
return false;
}
}
}

Expand Down Expand Up @@ -2883,7 +2887,9 @@ bool cmp_skip_object_no_limit(cmp_ctx_t *ctx) {
break;
}

skip_bytes(ctx, size);
if (!skip_bytes(ctx, size)) {
return false;
}
}
}

Expand Down Expand Up @@ -2975,7 +2981,9 @@ bool cmp_skip_object_limit(cmp_ctx_t *ctx, cmp_object_t *obj, uint32_t limit) {
break;
}

skip_bytes(ctx, size);
if (!skip_bytes(ctx, size)) {
return false;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ THE SOFTWARE.

int main(void) {
/* Use the old CMocka API because Travis' latest Ubuntu is Trusty */
const UnitTest tests[17] = {
const UnitTest tests[18] = {
unit_test(test_msgpack),
unit_test(test_fixedint),
unit_test(test_numbers),
Expand All @@ -51,6 +51,7 @@ int main(void) {
#endif

unit_test(test_skipping),
unit_test(test_skip_bytes),
unit_test(test_deprecated_limited_skipping),
unit_test(test_errors),
unit_test(test_version),
Expand Down
31 changes: 31 additions & 0 deletions test/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -4696,6 +4696,37 @@ void test_skipping(void **state) {
teardown_cmp_and_buf(&cmp, &buf);
}

void test_skip_bytes(void **state) {
buf_t buf;
cmp_ctx_t cmp;
cmp_object_t obj;

(void)state;

setup_cmp_and_buf(&cmp, &buf);

M_BufferEnsureCapacity(&buf, 100);

/* Write the string marker but omit the string contents. This should ensure
that skip_bytes() (and thus cmp_skip_object*) will fail when it tries
to skip the string. */
assert_true(cmp_write_str_marker(&cmp, 20));

M_BufferSeek(&buf, 0);
assert_false(cmp_skip_object(&cmp, &obj));

M_BufferSeek(&buf, 0);
assert_false(cmp_skip_object_flat(&cmp, &obj));

M_BufferSeek(&buf, 0);
assert_false(cmp_skip_object_no_limit(&cmp));

M_BufferSeek(&buf, 0);
assert_false(cmp_skip_object_limit(&cmp, &obj, 1));

teardown_cmp_and_buf(&cmp, &buf);
}

void test_deprecated_limited_skipping(void **state) {
buf_t buf;
cmp_ctx_t cmp;
Expand Down
1 change: 1 addition & 0 deletions test/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void test_obj(void **state);
void test_float_flip(void **state);
#endif
void test_skipping(void **state);
void test_skip_bytes(void **state);
void test_deprecated_limited_skipping(void **state);
void test_errors(void **state);
void test_version(void **state);
Expand Down