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/.clang-tidy b/.clang-tidy index 9c541aa..c8fe523 100644 --- a/.clang-tidy +++ b/.clang-tidy
@@ -187,6 +187,7 @@ clang-analyzer-webkit.RefCntblBaseVirtualDtor, cppcoreguidelines-avoid-c-arrays, cppcoreguidelines-init-variables, +cppcoreguidelines-pro-type-vararg, misc-misplaced-const, misc-redundant-expression, misc-static-assert,
diff --git a/src/ADCSensor.cpp b/src/ADCSensor.cpp index 0638b7d..a8287b4 100644 --- a/src/ADCSensor.cpp +++ b/src/ADCSensor.cpp
@@ -54,11 +54,19 @@ maxVoltageReading / scaleFactor, minVoltageReading / scaleFactor, conn, readState), std::enable_shared_from_this<ADCSensor>(), objServer(objectServer), - inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), path(path), - scaleFactor(scaleFactor), + inputDev(io), waitTimer(io), path(path), scaleFactor(scaleFactor), sensorPollMs(static_cast<unsigned int>(pollRate * 1000)), bridgeGpio(std::move(bridgeGpio)), thresholdTimer(io) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + int fd = open(path.c_str(), O_RDONLY); + if (fd < 0) + { + std::cerr << "unable to open acd device \n"; + } + + inputDev.assign(fd); + sensorInterface = objectServer.add_interface( "/xyz/openbmc_project/sensors/voltage/" + name, "xyz.openbmc_project.Sensor.Value"); @@ -183,6 +191,8 @@ { (*bridgeGpio).set(0); } + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) int fd = open(path.c_str(), O_RDONLY); if (fd < 0) {
diff --git a/src/CPUSensor.cpp b/src/CPUSensor.cpp index 6154b6f..0fdb2f4 100644 --- a/src/CPUSensor.cpp +++ b/src/CPUSensor.cpp
@@ -117,6 +117,8 @@ if (readingStateGood()) { inputDev.close(); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) int fd = open(path.c_str(), O_RDONLY); if (fd >= 0) {
diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp index fd9e543..4f377aa 100644 --- a/src/CPUSensorMain.cpp +++ b/src/CPUSensorMain.cpp
@@ -463,6 +463,8 @@ for (CPUConfig& config : cpuConfigs) { std::string peciDevPath = peciDev + std::to_string(config.bus); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) auto file = open(peciDevPath.c_str(), O_RDWR | O_CLOEXEC); if (file < 0) { @@ -474,6 +476,8 @@ struct peci_ping_msg msg {}; msg.addr = config.addr; + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) if (!ioctl(file, PECI_IOC_PING, &msg)) { bool dimmReady = false; @@ -485,6 +489,8 @@ msg.index = PECI_MBX_INDEX_DDR_DIMM_TEMP; msg.param = rank; msg.rx_len = 4; + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) if (!ioctl(file, PECI_IOC_RD_PKG_CFG, &msg)) { if (msg.pkg_config[0] || msg.pkg_config[1] ||
diff --git a/src/ChassisIntrusionSensor.cpp b/src/ChassisIntrusionSensor.cpp index 4b89709..9b35da2 100644 --- a/src/ChassisIntrusionSensor.cpp +++ b/src/ChassisIntrusionSensor.cpp
@@ -80,12 +80,15 @@ { std::string i2cBus = "/dev/i2c-" + std::to_string(busId); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) int fd = open(i2cBus.c_str(), O_RDWR | O_CLOEXEC); if (fd < 0) { std::cerr << "unable to open i2c device \n"; return -1; } + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) if (ioctl(fd, I2C_SLAVE_FORCE, slaveAddr) < 0) { std::cerr << "unable to set device address\n"; @@ -94,6 +97,8 @@ } unsigned long funcs = 0; + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) if (ioctl(fd, I2C_FUNCS, &funcs) < 0) { std::cerr << "not support I2C_FUNCS \n";
diff --git a/src/HwmonTempSensor.cpp b/src/HwmonTempSensor.cpp index 09fb33f..6577739 100644 --- a/src/HwmonTempSensor.cpp +++ b/src/HwmonTempSensor.cpp
@@ -52,11 +52,20 @@ false, thisSensorParameters.maxValue, thisSensorParameters.minValue, conn, powerState), std::enable_shared_from_this<HwmonTempSensor>(), objServer(objectServer), - inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), path(path), + inputDev(io), waitTimer(io), path(path), offsetValue(thisSensorParameters.offsetValue), scaleValue(thisSensorParameters.scaleValue), sensorPollMs(static_cast<unsigned int>(pollRate * 1000)) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + int fd = open(path.c_str(), O_RDONLY); + if (fd < 0) + { + std::cerr << "HwmonTempSensor " << sensorName << " failed to open " + << path << "\n"; + } + inputDev.assign(fd); + sensorInterface = objectServer.add_interface( "/xyz/openbmc_project/sensors/" + thisSensorParameters.typeName + "/" + name, @@ -164,6 +173,8 @@ responseStream.clear(); inputDev.close(); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) int fd = open(path.c_str(), O_RDONLY); if (fd < 0) {
diff --git a/src/MCUTempSensor.cpp b/src/MCUTempSensor.cpp index ede2a5e..4653bc8 100644 --- a/src/MCUTempSensor.cpp +++ b/src/MCUTempSensor.cpp
@@ -102,8 +102,9 @@ int MCUTempSensor::getMCURegsInfoWord(uint8_t regs, int16_t* pu16data) { std::string i2cBus = "/dev/i2c-" + std::to_string(busId); - int fd = open(i2cBus.c_str(), O_RDWR); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + int fd = open(i2cBus.c_str(), O_RDWR); if (fd < 0) { std::cerr << " unable to open i2c device" << i2cBus << " err=" << fd @@ -111,6 +112,7 @@ return -1; } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) if (ioctl(fd, I2C_SLAVE_FORCE, mcuAddress) < 0) { std::cerr << " unable to set device address\n"; @@ -119,6 +121,7 @@ } unsigned long funcs = 0; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) if (ioctl(fd, I2C_FUNCS, &funcs) < 0) { std::cerr << " not support I2C_FUNCS\n";
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;
diff --git a/src/PSUEvent.cpp b/src/PSUEvent.cpp index 44275a3..7813741 100644 --- a/src/PSUEvent.cpp +++ b/src/PSUEvent.cpp
@@ -157,6 +157,8 @@ { eventPollMs = static_cast<unsigned int>(pollRate * 1000); } + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) fd = open(path.c_str(), O_RDONLY); if (fd < 0) {
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp index 99845b5..bbc0d2f 100644 --- a/src/PSUSensor.cpp +++ b/src/PSUSensor.cpp
@@ -65,6 +65,7 @@ sensorPollMs = static_cast<unsigned int>(pollRate * 1000); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) fd = open(path.c_str(), O_RDONLY | O_NONBLOCK); if (fd < 0) {
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp index d0051a0..f609410 100644 --- a/src/TachSensor.cpp +++ b/src/TachSensor.cpp
@@ -53,10 +53,17 @@ objectType, false, false, limits.second, limits.first, conn, powerState), objServer(objectServer), redundancy(redundancy), - presence(std::move(presenceSensor)), - inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), path(path), - led(ledIn) + presence(std::move(presenceSensor)), inputDev(io), waitTimer(io), + path(path), led(ledIn) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + int fd = open(path.c_str(), O_RDONLY); + if (fd < 0) + { + std::cerr << "Tach sensor failed to open file\n"; + } + inputDev.assign(fd); + sensorInterface = objectServer.add_interface( "/xyz/openbmc_project/sensors/fan_tach/" + name, "xyz.openbmc_project.Sensor.Value"); @@ -162,6 +169,8 @@ } responseStream.clear(); inputDev.close(); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) int fd = open(path.c_str(), O_RDONLY); if (fd < 0) {
diff --git a/tests/test_Utils.cpp b/tests/test_Utils.cpp index 63fcde8..a66b70c 100644 --- a/tests/test_Utils.cpp +++ b/tests/test_Utils.cpp
@@ -65,7 +65,7 @@ p != fs::recursive_directory_iterator(); ++p) { std::string path = p->path().string(); - fprintf(stderr, "%s\n", path.c_str()); + std::cerr << path << "\n"; if (p.depth() >= 6) { p.disable_recursion_pending();