@nxtedition/rocksdb 16.0.1 → 16.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,12 +22,16 @@ int compareRev(const rocksdb::Slice& a, const rocksdb::Slice& b) {
22
22
  const std::size_t endA = 1 + std::min<std::size_t>(static_cast<unsigned char>(a[0]), a.size() - 1);
23
23
  const std::size_t endB = 1 + std::min<std::size_t>(static_cast<unsigned char>(b[0]), b.size() - 1);
24
24
 
25
- // Compare the revision number
25
+ // Compare the revision number. Compare bytes as unsigned char: rocksdb::Slice
26
+ // operator[] returns (signed-on-most-platforms) char, so a byte >= 0x80 would
27
+ // otherwise sort as negative and order opposite to the JS comparator, which
28
+ // reads bytes as unsigned (Buffer[i] in 0..255). Keeping both sides unsigned
29
+ // ensures the in-memory ordering and this durable maxRev merge agree.
26
30
  auto result = 0;
27
31
  const auto end = std::min(endA, endB);
28
32
  while (indexA < end && indexB < end) {
29
- const auto ac = a[indexA++];
30
- const auto bc = b[indexB++];
33
+ const unsigned char ac = static_cast<unsigned char>(a[indexA++]);
34
+ const unsigned char bc = static_cast<unsigned char>(b[indexB++]);
31
35
 
32
36
  if (ac == '-') {
33
37
  if (bc == '-') {
@@ -47,10 +51,10 @@ int compareRev(const rocksdb::Slice& a, const rocksdb::Slice& b) {
47
51
  return result;
48
52
  }
49
53
 
50
- // Compare the rest
54
+ // Compare the rest (unsigned, for the same reason as the loop above).
51
55
  while (indexA < end && indexB < end) {
52
- const auto ac = a[indexA++];
53
- const auto bc = b[indexB++];
56
+ const unsigned char ac = static_cast<unsigned char>(a[indexA++]);
57
+ const unsigned char bc = static_cast<unsigned char>(b[indexB++]);
54
58
  if (ac != bc) {
55
59
  return ac < bc ? -1 : 1;
56
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "16.0.1",
3
+ "version": "16.0.2",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",