pw_kvs: Switch log format strings from %z to %u

Switch KVS print to not use the %z format for size_t due to
incompatibility with some libc/printf implementations.

Change-Id: If81052b0f9fefdf13c101ef11e1c19c20d451713
diff --git a/pw_kvs/entry.cc b/pw_kvs/entry.cc
index 0429455..801a636 100644
--- a/pw_kvs/entry.cc
+++ b/pw_kvs/entry.cc
@@ -237,14 +237,14 @@
 
 void Entry::DebugLog() const {
   PW_LOG_DEBUG("Entry [%s]: ", deleted() ? "tombstone" : "present");
-  PW_LOG_DEBUG("   Address      = 0x%zx", size_t(address_));
-  PW_LOG_DEBUG("   Transaction  = %zu", size_t(transaction_id()));
-  PW_LOG_DEBUG("   Magic        = 0x%zx", size_t(magic()));
-  PW_LOG_DEBUG("   Checksum     = 0x%zx", size_t(header_.checksum));
-  PW_LOG_DEBUG("   Key length   = 0x%zx", size_t(key_length()));
-  PW_LOG_DEBUG("   Value length = 0x%zx", size_t(value_size()));
-  PW_LOG_DEBUG("   Entry size   = 0x%zx", size_t(size()));
-  PW_LOG_DEBUG("   Alignment    = 0x%zx", size_t(alignment_bytes()));
+  PW_LOG_DEBUG("   Address      = 0x%x", unsigned(address_));
+  PW_LOG_DEBUG("   Transaction  = %u", unsigned(transaction_id()));
+  PW_LOG_DEBUG("   Magic        = 0x%x", unsigned(magic()));
+  PW_LOG_DEBUG("   Checksum     = 0x%x", unsigned(header_.checksum));
+  PW_LOG_DEBUG("   Key length   = 0x%x", unsigned(key_length()));
+  PW_LOG_DEBUG("   Value length = 0x%x", unsigned(value_size()));
+  PW_LOG_DEBUG("   Entry size   = 0x%x", unsigned(size()));
+  PW_LOG_DEBUG("   Alignment    = 0x%x", unsigned(alignment_bytes()));
 }
 
 span<const byte> Entry::CalculateChecksum(const string_view key,
diff --git a/pw_kvs/fake_flash_memory.cc b/pw_kvs/fake_flash_memory.cc
index 9443836..95987f3 100644
--- a/pw_kvs/fake_flash_memory.cc
+++ b/pw_kvs/fake_flash_memory.cc
@@ -58,17 +58,17 @@
 Status FakeFlashMemory::Erase(Address address, size_t num_sectors) {
   if (address % sector_size_bytes() != 0) {
     PW_LOG_ERROR(
-        "Attempted to erase sector at non-sector aligned boundary; address %zx",
-        size_t(address));
+        "Attempted to erase sector at non-sector aligned boundary; address %x",
+        unsigned(address));
     return Status::INVALID_ARGUMENT;
   }
   const size_t sector_id = address / sector_size_bytes();
   if (address / sector_size_bytes() + num_sectors > sector_count()) {
     PW_LOG_ERROR(
         "Tried to erase a sector at an address past flash end; "
-        "address: %zx, sector implied: %zu",
-        size_t(address),
-        sector_id);
+        "address: %x, sector implied: %u",
+        unsigned(address),
+        unsigned(sector_id));
     return Status::OUT_OF_RANGE;
   }
 
@@ -92,34 +92,34 @@
                                       span<const std::byte> data) {
   if (address % alignment_bytes() != 0 ||
       data.size() % alignment_bytes() != 0) {
-    PW_LOG_ERROR("Unaligned write; address %zx, size %zu B, alignment %zu",
-                 size_t(address),
-                 data.size(),
-                 alignment_bytes());
+    PW_LOG_ERROR("Unaligned write; address %x, size %u B, alignment %u",
+                 unsigned(address),
+                 unsigned(data.size()),
+                 unsigned(alignment_bytes()));
     return StatusWithSize::INVALID_ARGUMENT;
   }
 
   if (data.size() > sector_size_bytes() - (address % sector_size_bytes())) {
-    PW_LOG_ERROR("Write crosses sector boundary; address %zx, size %zu B",
-                 size_t(address),
-                 data.size());
+    PW_LOG_ERROR("Write crosses sector boundary; address %x, size %u B",
+                 unsigned(address),
+                 unsigned(data.size()));
     return StatusWithSize::INVALID_ARGUMENT;
   }
 
   if (address + data.size() > sector_count() * sector_size_bytes()) {
     PW_LOG_ERROR(
-        "Write beyond end of memory; address %zx, size %zu B, max address %zx",
-        size_t(address),
-        data.size(),
-        sector_count() * sector_size_bytes());
+        "Write beyond end of memory; address %x, size %u B, max address %x",
+        unsigned(address),
+        unsigned(data.size()),
+        unsigned(sector_count() * sector_size_bytes()));
     return StatusWithSize::OUT_OF_RANGE;
   }
 
   // Check in erased state
   for (unsigned i = 0; i < data.size(); i++) {
     if (buffer_[address + i] != kErasedValue) {
-      PW_LOG_ERROR("Writing to previously written address: %zx",
-                   size_t(address));
+      PW_LOG_ERROR("Writing to previously written address: %x",
+                   unsigned(address));
       return StatusWithSize::UNKNOWN;
     }
   }
diff --git a/pw_kvs/flash_memory.cc b/pw_kvs/flash_memory.cc
index f25ec68..242f13e 100644
--- a/pw_kvs/flash_memory.cc
+++ b/pw_kvs/flash_memory.cc
@@ -113,10 +113,10 @@
 
 Status FlashPartition::CheckBounds(Address address, size_t length) const {
   if (address + length > size_bytes()) {
-    PW_LOG_ERROR("Attempted out-of-bound flash memory access (address: %" PRIu32
-                 " length: %zu)",
-                 address,
-                 length);
+    PW_LOG_ERROR(
+        "Attempted out-of-bound flash memory access (address: %u length: %u)",
+        unsigned(address),
+        unsigned(length));
     return Status::OUT_OF_RANGE;
   }
   return Status::OK;
diff --git a/pw_kvs/key_value_store.cc b/pw_kvs/key_value_store.cc
index 50b025b..84cc4cf 100644
--- a/pw_kvs/key_value_store.cc
+++ b/pw_kvs/key_value_store.cc
@@ -63,10 +63,10 @@
 
   INF("Initializing key value store");
   if (partition_.sector_count() > sectors_.max_size()) {
-    ERR("KVS init failed: kMaxUsableSectors (=%zu) must be at least as "
-        "large as the number of sectors in the flash partition (=%zu)",
-        sectors_.max_size(),
-        partition_.sector_count());
+    ERR("KVS init failed: kMaxUsableSectors (=%u) must be at least as "
+        "large as the number of sectors in the flash partition (=%u)",
+        unsigned(sectors_.max_size()),
+        unsigned(partition_.sector_count()));
     return Status::FAILED_PRECONDITION;
   }
 
@@ -74,10 +74,10 @@
 
   // TODO: investigate doing this as a static assert/compile-time check.
   if (sector_size_bytes > SectorDescriptor::max_sector_size()) {
-    ERR("KVS init failed: sector_size_bytes (=%zu) is greater than maximum "
-        "allowed sector size (=%zu)",
-        sector_size_bytes,
-        SectorDescriptor::max_sector_size());
+    ERR("KVS init failed: sector_size_bytes (=%u) is greater than maximum "
+        "allowed sector size (=%u)",
+        unsigned(sector_size_bytes),
+        unsigned(SectorDescriptor::max_sector_size()));
     return Status::FAILED_PRECONDITION;
   }
 
@@ -112,12 +112,12 @@
     }
   }
 
-  INF("KeyValueStore init complete: active keys %zu, deleted keys %zu, sectors "
-      "%zu, logical sector size %zu bytes",
-      size(),
-      (entry_cache_.total_entries() - size()),
-      sectors_.size(),
-      partition_.sector_size_bytes());
+  INF("KeyValueStore init complete: active keys %u, deleted keys %u, sectors "
+      "%u, logical sector size %u bytes",
+      unsigned(size()),
+      unsigned(entry_cache_.total_entries() - size()),
+      unsigned(sectors_.size()),
+      unsigned(partition_.sector_size_bytes()));
 
   // Report any corruption was not repaired.
   if (error_detected_) {
@@ -203,9 +203,9 @@
       sector.mark_corrupt();
       error_detected_ = true;
 
-      WRN("Sector %u contains %zuB of corrupt data",
+      WRN("Sector %u contains %uB of corrupt data",
           sectors_.Index(sector),
-          sector_corrupt_bytes);
+          unsigned(sector_corrupt_bytes));
     }
 
     if (sector.Empty(sector_size_bytes)) {
@@ -273,18 +273,18 @@
     error_detected_ = true;
 
     if (!other_errors && entry_copies_missing == entry_cache_.total_entries()) {
-      INF("KVS configuration changed to redundancy of %zu total copies per key",
-          redundancy());
+      INF("KVS configuration changed to redundancy of %u total copies per key",
+          unsigned(redundancy()));
       return Status::OUT_OF_RANGE;
     }
   }
 
   if (error_detected_) {
-    WRN("Corruption detected. Found %zu corrupt bytes, %zu corrupt entries, "
-        "and %zu keys missing redundant copies.",
-        total_corrupt_bytes,
-        corrupt_entries,
-        entry_copies_missing);
+    WRN("Corruption detected. Found %u corrupt bytes, %u corrupt entries, "
+        "and %u keys missing redundant copies.",
+        unsigned(total_corrupt_bytes),
+        unsigned(corrupt_entries),
+        unsigned(entry_copies_missing));
     return Status::FAILED_PRECONDITION;
   }
   return Status::OK;
@@ -405,14 +405,14 @@
 
 Status KeyValueStore::PutBytes(string_view key, span<const byte> value) {
   TRY(CheckWriteOperation(key));
-  DBG("Writing key/value; key length=%zu, value length=%zu",
-      key.size(),
-      value.size());
+  DBG("Writing key/value; key length=%u, value length=%u",
+      unsigned(key.size()),
+      unsigned(value.size()));
 
   if (Entry::size(partition_, key, value) > partition_.sector_size_bytes()) {
-    DBG("%zu B value with %zu B key cannot fit in one sector",
-        value.size(),
-        key.size());
+    DBG("%u B value with %u B key cannot fit in one sector",
+        unsigned(value.size()),
+        unsigned(key.size()));
     return Status::INVALID_ARGUMENT;
   }
 
@@ -421,9 +421,9 @@
 
   if (status.ok()) {
     // TODO: figure out logging how to support multiple addresses.
-    DBG("Overwriting entry for key 0x%08" PRIx32 " in %zu sectors including %u",
-        metadata.hash(),
-        metadata.addresses().size(),
+    DBG("Overwriting entry for key 0x%08x in %u sectors including %u",
+        unsigned(metadata.hash()),
+        unsigned(metadata.addresses().size()),
         sectors_.Index(metadata.first_address()));
     return WriteEntryForExistingKey(metadata, EntryState::kValid, key, value);
   }
@@ -442,9 +442,9 @@
   TRY(FindExisting(key, &metadata));
 
   // TODO: figure out logging how to support multiple addresses.
-  DBG("Writing tombstone for key 0x%08" PRIx32 " in %zu sectors including %u",
-      metadata.hash(),
-      metadata.addresses().size(),
+  DBG("Writing tombstone for key 0x%08x in %u sectors including %u",
+      unsigned(metadata.hash()),
+      unsigned(metadata.addresses().size()),
       sectors_.Index(metadata.first_address()));
   return WriteEntryForExistingKey(metadata, EntryState::kDeleted, key, {});
 }
@@ -570,7 +570,9 @@
   TRY_ASSIGN(const size_t actual_size, ValueSize(metadata));
 
   if (actual_size != size_bytes) {
-    DBG("Requested %zu B read, but value is %zu B", size_bytes, actual_size);
+    DBG("Requested %u B read, but value is %u B",
+        unsigned(size_bytes),
+        unsigned(actual_size));
     return Status::INVALID_ARGUMENT;
   }
 
@@ -626,8 +628,8 @@
 Status KeyValueStore::WriteEntryForNewKey(string_view key,
                                           span<const byte> value) {
   if (entry_cache_.full()) {
-    WRN("KVS full: trying to store a new entry, but can't. Have %zu entries",
-        entry_cache_.total_entries());
+    WRN("KVS full: trying to store a new entry, but can't. Have %u entries",
+        unsigned(entry_cache_.total_entries()));
     return Status::RESOURCE_EXHAUSTED;
   }
 
@@ -767,7 +769,7 @@
   }
 
   if (!result.ok()) {
-    WRN("Unable to find sector to write %zu B", entry_size);
+    WRN("Unable to find sector to write %u B", unsigned(entry_size));
   }
   return result;
 }
@@ -790,10 +792,10 @@
   SectorDescriptor& sector = sectors_.FromAddress(entry.address());
 
   if (!result.ok()) {
-    ERR("Failed to write %zu bytes at %#zx. %zu actually written",
-        entry.size(),
-        size_t(entry.address()),
-        result.size());
+    ERR("Failed to write %u bytes at %#x. %u actually written",
+        unsigned(entry.size()),
+        unsigned(entry.address()),
+        unsigned(result.size()));
     TRY(MarkSectorCorruptIfNotOk(result.status(), &sector));
   }
 
@@ -979,8 +981,8 @@
 
   if (sector_to_gc.valid_bytes() != 0) {
     ERR("  Failed to relocate valid entries from sector being garbage "
-        "collected, %zu valid bytes remain",
-        sector_to_gc.valid_bytes());
+        "collected, %u valid bytes remain",
+        unsigned(sector_to_gc.valid_bytes()));
     return Status::INTERNAL;
   }
 
@@ -1231,16 +1233,16 @@
   DBG("====================== KEY VALUE STORE DUMP =========================");
   DBG(" ");
   DBG("Flash partition:");
-  DBG("  Sector count     = %zu", partition_.sector_count());
-  DBG("  Sector max count = %zu", sectors_.max_size());
-  DBG("  Sectors in use   = %zu", sectors_.size());
-  DBG("  Sector size      = %zu", sector_size_bytes);
-  DBG("  Total size       = %zu", partition_.size_bytes());
-  DBG("  Alignment        = %zu", partition_.alignment_bytes());
+  DBG("  Sector count     = %u", unsigned(partition_.sector_count()));
+  DBG("  Sector max count = %u", unsigned(sectors_.max_size()));
+  DBG("  Sectors in use   = %u", unsigned(sectors_.size()));
+  DBG("  Sector size      = %u", unsigned(sector_size_bytes));
+  DBG("  Total size       = %u", unsigned(partition_.size_bytes()));
+  DBG("  Alignment        = %u", unsigned(partition_.alignment_bytes()));
   DBG(" ");
   DBG("Key descriptors:");
-  DBG("  Entry count     = %zu", entry_cache_.total_entries());
-  DBG("  Max entry count = %zu", entry_cache_.max_entries());
+  DBG("  Entry count     = %u", unsigned(entry_cache_.total_entries()));
+  DBG("  Max entry count = %u", unsigned(entry_cache_.max_entries()));
   DBG(" ");
   DBG("      #     hash        version    address   address (hex)");
   size_t count = 0;
@@ -1273,7 +1275,7 @@
     std::array<byte, 500> raw_sector_data;  // TODO!!!
     StatusWithSize sws =
         partition_.Read(sector_id * sector_size_bytes, raw_sector_data);
-    DBG("Read: %zu bytes", sws.size());
+    DBG("Read: %u bytes", unsigned(sws.size()));
 
     DBG("  base    addr  offs   0  1  2  3  4  5  6  7");
     for (size_t i = 0; i < sector_size_bytes; i += 8) {
@@ -1302,24 +1304,24 @@
 }
 
 void KeyValueStore::LogSectors() const {
-  DBG("Sector descriptors: count %zu", sectors_.size());
+  DBG("Sector descriptors: count %u", unsigned(sectors_.size()));
   for (auto& sector : sectors_) {
-    DBG("  - Sector %u: valid %zu, recoverable %zu, free %zu",
+    DBG("  - Sector %u: valid %u, recoverable %u, free %u",
         sectors_.Index(sector),
-        sector.valid_bytes(),
-        sector.RecoverableBytes(partition_.sector_size_bytes()),
-        sector.writable_bytes());
+        unsigned(sector.valid_bytes()),
+        unsigned(sector.RecoverableBytes(partition_.sector_size_bytes())),
+        unsigned(sector.writable_bytes()));
   }
 }
 
 void KeyValueStore::LogKeyDescriptor() const {
-  DBG("Key descriptors: count %zu", entry_cache_.total_entries());
+  DBG("Key descriptors: count %u", unsigned(entry_cache_.total_entries()));
   for (const EntryMetadata& metadata : entry_cache_) {
-    DBG("  - Key: %s, hash %#zx, transaction ID %zu, first address %#zx",
+    DBG("  - Key: %s, hash %#x, transaction ID %u, first address %#x",
         metadata.state() == EntryState::kDeleted ? "Deleted" : "Valid",
-        static_cast<size_t>(metadata.hash()),
-        static_cast<size_t>(metadata.transaction_id()),
-        static_cast<size_t>(metadata.first_address()));
+        unsigned(metadata.hash()),
+        unsigned(metadata.transaction_id()),
+        unsigned(metadata.first_address()));
   }
 }
 
diff --git a/pw_kvs/sectors.cc b/pw_kvs/sectors.cc
index d639c7d..d36e01c 100644
--- a/pw_kvs/sectors.cc
+++ b/pw_kvs/sectors.cc
@@ -60,8 +60,8 @@
     temp_sectors_to_skip_[sectors_to_skip++] = &FromAddress(address);
   }
 
-  DBG("Find sector with %zu bytes available, starting with sector %u, %s",
-      size,
+  DBG("Find sector with %u bytes available, starting with sector %u, %s",
+      unsigned(size),
       Index(last_new_),
       (find_mode == kAppendEntry) ? "Append" : "GC");
   for (size_t i = 0; i < sectors_to_skip; ++i) {
@@ -143,9 +143,9 @@
   // bytes
   if (non_empty_least_reclaimable_sector != nullptr) {
     *found_sector = non_empty_least_reclaimable_sector;
-    DBG("  Found a usable sector %u, with %zu B recoverable, in GC",
+    DBG("  Found a usable sector %u, with %u B recoverable, in GC",
         Index(*found_sector),
-        (*found_sector)->RecoverableBytes(sector_size_bytes));
+        unsigned((*found_sector)->RecoverableBytes(sector_size_bytes)));
     return Status::OK;
   }
 
@@ -218,9 +218,9 @@
   }
 
   if (sector_candidate != nullptr) {
-    DBG("Found sector %u to Garbage Collect, %zu recoverable bytes",
+    DBG("Found sector %u to Garbage Collect, %u recoverable bytes",
         Index(sector_candidate),
-        sector_candidate->RecoverableBytes(sector_size_bytes));
+        unsigned(sector_candidate->RecoverableBytes(sector_size_bytes)));
   } else {
     DBG("Unable to find sector to garbage collect!");
   }