https://bugs.openldap.org/show_bug.cgi?id=8988

--- Comment #27 from [email protected] ---
Unfortunately I can still reproduce this with LMDB 0.9.33.

Repro:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "lmdb.h"

#define VAL(str) {strlen(str), str}
#define CHK(st) if (st != 0) { fprintf(stderr, "fail at %d\n", __LINE__);
abort(); }

int main() {
  MDB_env* lmdb;
  int status;

  status= mdb_env_create(&lmdb);
  CHK(status);

  status = mdb_env_open(lmdb, "/tmp/lmdb_repro", 0, 0644);
  CHK(status);

  MDB_txn* txn;
  status = mdb_txn_begin(lmdb, NULL, 0, &txn);
  CHK(status);

  MDB_dbi dbi;
  status = mdb_dbi_open(txn, NULL, MDB_CREATE | MDB_DUPSORT, &dbi);
  CHK(status);

  MDB_val k = VAL("key");
  MDB_val v1 = VAL("val1");
  status = mdb_put(txn, dbi, &k, &v1, MDB_NODUPDATA);
  CHK(status);

  MDB_val v2 = VAL("val2");
  status = mdb_put(txn, dbi, &k, &v2, MDB_NODUPDATA);
  CHK(status);

  return 0;
}

$ clang -fsanitize=undefined -o repro repro.c mdb.c midl.c
$ mkdir /tmp/lmdb_repro
$ ./repro

Output:

---

mdb.c:7654:26: runtime error: member access within misaligned address
0x561c906b85d3 for type 'MDB_page2' (aka 'struct MDB_page2'), which requires 2
byte alignment
0x561c906b85d3: note: pointer points here
 00  6b 65 79 02 00 00 00 00  00 00 00 00 00 52 00 10  00 2c 00 76 61 6c 31 00 
00 00 00 00 00 00 00
              ^ 
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior mdb.c:7654:26 in 
mdb.c:7654:26: runtime error: load of misaligned address 0x561c906b85df for
type 'indx_t' (aka 'unsigned short'), which requires 2 byte alignment
0x561c906b85df: note: pointer points here
 00 00 52 00 10  00 2c 00 76 61 6c 31 00  00 00 00 00 00 00 00 00  00 00 00 00
00 00 00 00  00 00 00
             ^ 
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior mdb.c:7654:26 in 
mdb.c:7655:3: runtime error: member access within misaligned address
0x561c906b85d3 for type 'MDB_page' (aka 'struct MDB_page'), which requires 8
byte alignment
0x561c906b85d3: note: pointer points here
 00  6b 65 79 02 00 00 00 00  00 00 00 00 00 52 00 10  00 2c 00 76 61 6c 31 00 
00 00 00 00 00 00 00

[...]

---

It appears that some instances of MDB_page2 are not 2-byte aligned.  Is this
expected?

-- 
You are receiving this mail because:
You are on the CC list for the issue.

Reply via email to