diff --git a/pw_fastboot/fastboot_device.cc b/pw_fastboot/fastboot_device.cc index 380627876..0d0ff3d66 100644 --- a/pw_fastboot/fastboot_device.cc +++ b/pw_fastboot/fastboot_device.cc @@ -109,10 +109,10 @@ bool Device::HandleData(bool read, char* data, size_t size) { return false; } if (static_cast(read_write_data_size) != size) { - PW_LOG_ERROR("%s expected %lu bytes, got %u", + PW_LOG_ERROR("%s expected %zu bytes, got %zu", (read ? "read" : "write"), - (long unsigned int)size, - read_write_data_size); + static_cast(size), + static_cast(read_write_data_size)); return false; } return true; @@ -137,7 +137,7 @@ void Device::ExecuteCommands() { std::vector args; std::string cmd_name; - if (cmd_name.starts_with("oem ")) { + if (stringutils::StartsWith(cmd_name, "oem ")) { args = {command}; cmd_name = FB_CMD_OEM; } else { diff --git a/pw_fastboot/lib/stringutils/public/stringutils/strings.h b/pw_fastboot/lib/stringutils/public/stringutils/strings.h index 7cd26a137..cd29e0b20 100644 --- a/pw_fastboot/lib/stringutils/public/stringutils/strings.h +++ b/pw_fastboot/lib/stringutils/public/stringutils/strings.h @@ -85,4 +85,6 @@ bool ParseUint(const char* s, T* out, T max = std::numeric_limits::max()) { std::string StringPrintf(const char* fmt, ...) __attribute__((__format__(FORMAT_ARCHETYPE, 1, 2))); +bool StartsWith(std::string_view s, std::string_view prefix); + } // namespace stringutils diff --git a/pw_fastboot/lib/stringutils/strings.cc b/pw_fastboot/lib/stringutils/strings.cc index d33f85f74..d01f5f213 100644 --- a/pw_fastboot/lib/stringutils/strings.cc +++ b/pw_fastboot/lib/stringutils/strings.cc @@ -92,4 +92,8 @@ void StringAppendF(std::string* dst, const char* format, ...) { va_end(ap); } +bool StartsWith(std::string_view s, std::string_view prefix) { + return s.substr(0, prefix.size()) == prefix; +} + } // namespace stringutils \ No newline at end of file