Enable cppcoreguidelines-pro-type-vararg check
We only had one usage of printf in the code that was in violation of
this rule, so replace it with iostreams, and enable the check.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ie62165b599a996f34893aa5a3f8d1f6e6cbaf903
diff --git a/src/NVMeBasicContext.cpp b/src/NVMeBasicContext.cpp
index ea17c73..0e04b16 100644
--- a/src/NVMeBasicContext.cpp
+++ b/src/NVMeBasicContext.cpp
@@ -61,26 +61,21 @@
static ssize_t execBasicQuery(int bus, uint8_t addr, uint8_t cmd,
std::vector<uint8_t>& resp)
{
- std::array<char, PATH_MAX> devpath{};
+ int rc = 0;
int32_t size = 0;
+ std::string devpath = "/dev/i2c-" + std::to_string(bus);
- ssize_t rc =
- snprintf(devpath.data(), devpath.size(), "/dev/i2c-%" PRIu32, bus);
- if ((size_t)rc > sizeof(devpath))
- {
- std::cerr << "Failed to format device path for bus " << bus << "\n";
- return -EINVAL;
- }
-
- int dev = ::open(devpath.data(), O_RDWR);
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
+ int dev = ::open(devpath.c_str(), O_RDWR);
if (dev == -1)
{
- std::cerr << "Failed to open bus device " << devpath.data() << ": "
+ std::cerr << "Failed to open bus device " << devpath << ": "
<< strerror(errno) << "\n";
return -errno;
}
/* Select the target device */
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
if (::ioctl(dev, I2C_SLAVE, addr) == -1)
{
rc = -errno;