Skip to content

Commit f872bd4

Browse files
committed
MB-47166: Fix undefined behaviour in iterator_functional_test
As identified during testing for AArch64 support, iterator_functional_test has a number of instances of undefined behaviour: 1. iterator_functional_test.cc:776:16: runtime error: null pointer passed as argument 1, which is declared to never be null The test is trying to use memcmp (as used in implementaiton of TEST_CMP macro on a nullptr). In this case the length should be zero so just check that explicitly. 2. iterator_functional_test.cc:1206:29: runtime error: load of address 0xffffe75d46f8 with insufficient space for an object of type 'int' The test is trying to access the 31st element in a 30-element array. This actually causes the unit-tests to reliably fail on AArch64 - I assume because we end up with a different undefined value compared to what x86 (normally) sees and hence it ends up failing a chec on how many iterations have been performed. Fix the for() loop termination so it doesn't access off the end. With this patch AArch64 passes all unit tests. Change-Id: I31184f0fe8c781575c61864cda2bdfc6c3457e1e Reviewed-on: http://review.couchbase.org/c/forestdb/+/159305 Reviewed-by: James H <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent def701c commit f872bd4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tests/functional/iterator_functional_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ void iterator_seek_test()
773773

774774
TEST_CMP(rdoc->key, doc[i]->key, rdoc->keylen);
775775
TEST_CMP(rdoc->meta, doc[i]->meta, rdoc->metalen);
776-
TEST_CMP(rdoc->body, doc[i]->body, rdoc->bodylen);
776+
TEST_CHK(rdoc->bodylen == 0);
777777
fdb_doc_free(rdoc);
778778
rdoc = NULL;
779779

@@ -1198,7 +1198,7 @@ void iterator_complete_test(int insert_opt, int delete_opt)
11981198
}
11991199

12001200
if (mask & 0x100000) {
1201-
for (i=0;i<n;++i){
1201+
for (i=0;i<n-1;++i){
12021202
sprintf(key, keystr_mid, (int)i);
12031203
s = fdb_iterator_seek(fit, key, strlen(key)+1, 0x0);
12041204
(void)s;
@@ -1222,7 +1222,7 @@ void iterator_complete_test(int insert_opt, int delete_opt)
12221222
}
12231223

12241224
if (mask & 0x1000000) {
1225-
for (i=0;i<n;++i){
1225+
for (i=0;i<n-1;++i){
12261226
sprintf(key, keystr_mid, (int)i);
12271227
s = fdb_iterator_seek(fit, key, strlen(key)+1, 0x0);
12281228
(void)s;

0 commit comments

Comments
 (0)