diff --git a/hdc_rust/src/cffi/bridge.cpp b/hdc_rust/src/cffi/bridge.cpp index e0f5c175..e0b44ff5 100644 --- a/hdc_rust/src/cffi/bridge.cpp +++ b/hdc_rust/src/cffi/bridge.cpp @@ -95,7 +95,7 @@ int HdcBridge::WriteClient(int fd, SerializedBuffer buf) { uint8_t* ptr = reinterpret_cast(buf.ptr); size_t size = static_cast(buf.size); - int cnt = size; + int cnt = static_cast(size); constexpr int intrmax = 1000; int intrcnt = 0; while (cnt > 0) { @@ -116,7 +116,7 @@ int HdcBridge::WriteClient(int fd, SerializedBuffer buf) ptr += rc; cnt -= rc; } - return cnt == 0 ? size : cnt; + return cnt == 0 ? static_cast(size) : cnt; } void HdcBridge::Stop() diff --git a/hdc_rust/src/cffi/bridge.h b/hdc_rust/src/cffi/bridge.h index 30529acb..2b4e415e 100644 --- a/hdc_rust/src/cffi/bridge.h +++ b/hdc_rust/src/cffi/bridge.h @@ -45,8 +45,8 @@ public: void Stop(); private: - int bridgeListenPort; - int bridgeFd; + int bridgeListenPort = 0; + int bridgeFd = 0; }; } #endif \ No newline at end of file diff --git a/hdc_rust/src/cffi/host/ctimer.h b/hdc_rust/src/cffi/host/ctimer.h index 31a9f403..8f7b861d 100644 --- a/hdc_rust/src/cffi/host/ctimer.h +++ b/hdc_rust/src/cffi/host/ctimer.h @@ -31,7 +31,7 @@ public: this->func = func; } virtual ~CTimer() {} - void Start(unsigned int msec, bool immediatelyRun = false); + void Start(unsigned int imsec, bool immediatelyRun = false); void Stop(); void SetExit(bool exit); private: diff --git a/hdc_rust/src/cffi/host/host_usb.h b/hdc_rust/src/cffi/host/host_usb.h index 0b59746c..f298bac0 100644 --- a/hdc_rust/src/cffi/host/host_usb.h +++ b/hdc_rust/src/cffi/host/host_usb.h @@ -127,7 +127,7 @@ public: static void UsbWorkThread(void *arg); // 3rd thread static void WatchUsbNodeChange(void *arg); static void LIBUSB_CALL USBBulkCallback(struct libusb_transfer *transfer); - void CancelUsbIo(HUSB hUsb); + void CancelUsbIo(HUSB hUSB); PersistBuffer ReadUsbIO(HUSB hUsb, int exceptedSize); int WriteUsbIO(HUSB hUsb, SerializedBuffer buf); HUSB GetUsbDevice(std::string connectKey); diff --git a/hdc_rust/src/cffi/sendmsg.cpp b/hdc_rust/src/cffi/sendmsg.cpp index dde01f39..b83ee5ca 100644 --- a/hdc_rust/src/cffi/sendmsg.cpp +++ b/hdc_rust/src/cffi/sendmsg.cpp @@ -30,7 +30,7 @@ extern "C" int SendMsg(int socketFd, int fd, char* data, int size) constexpr int cmsgNullptrError = -5; struct iovec iov; iov.iov_base = data; - iov.iov_len = size; + iov.iov_len = static_cast(size); struct msghdr msg; msg.msg_name = nullptr; msg.msg_namelen = 0; diff --git a/hdc_rust/src/cffi/serial_struct.cpp b/hdc_rust/src/cffi/serial_struct.cpp index 3a256473..0b3dbbc2 100644 --- a/hdc_rust/src/cffi/serial_struct.cpp +++ b/hdc_rust/src/cffi/serial_struct.cpp @@ -235,19 +235,25 @@ extern "C" uint8_t ParseTransferPayload(RustStruct::TransferPayload &value, Seri extern "C" uint8_t ParsePayloadHead(RustStruct::PayloadHead &value, SerializedBuffer buf) { - (void)memcpy_s(&value, buf.size, reinterpret_cast(buf.ptr), buf.size); + if(memcpy_s(&value, buf.size, reinterpret_cast(buf.ptr), buf.size) != EOK) { + return 0; + } return 1; } extern "C" uint8_t ParseUsbHead(RustStruct::USBHead &value, SerializedBuffer buf) { - (void)memcpy_s(&value, sizeof(RustStruct::USBHead), reinterpret_cast(buf.ptr), buf.size); + if(memcpy_s(&value, sizeof(RustStruct::USBHead), reinterpret_cast(buf.ptr), buf.size) != EOK) { + return 0; + } return 1; } extern "C" uint8_t ParseUartHead(RustStruct::UartHead &value, SerializedBuffer buf) { - (void)memcpy_s(&value, sizeof(RustStruct::UartHead), reinterpret_cast(buf.ptr), buf.size); + if(memcpy_s(&value, sizeof(RustStruct::UartHead), reinterpret_cast(buf.ptr), buf.size) != EOK) { + return 0; + } return 1; } diff --git a/hdc_rust/src/cffi/uart.cpp b/hdc_rust/src/cffi/uart.cpp index d3c3bfc7..d8a64dae 100644 --- a/hdc_rust/src/cffi/uart.cpp +++ b/hdc_rust/src/cffi/uart.cpp @@ -96,24 +96,24 @@ bool EnumSerialPort(bool &portChange) #else DIR *dir = opendir("/dev"); dirent *p = nullptr; - while (dir != nullptr && ((p = readdir(dir)) != nullptr)) { + if (dir != nullptr) { + while ((p = readdir(dir)) != nullptr) { #ifdef HOST_LINUX - if (p->d_name[0] != '.' && string(p->d_name).find("tty") != std::string::npos) { + if (p->d_name[0] != '.' && string(p->d_name).find("tty") != std::string::npos) { #else - if (p->d_name[0] != '.' && string(p->d_name).find("serial") != std::string::npos) { + if (p->d_name[0] != '.' && string(p->d_name).find("serial") != std::string::npos) { #endif - string port = "/dev/" + string(p->d_name); - if (port.find("/dev/ttyUSB") == 0 || port.find("/dev/ttySerial") == 0 || port.find("/dev/cu.") == 0) { - newPortInfo.push_back(port); - auto it = std::find(serialPortInfo.begin(), serialPortInfo.end(), port); - if (it == serialPortInfo.end()) { - portChange = true; - WRITE_LOG(LOG_INFO, "new port:%s", port.c_str()); + string port = "/dev/" + string(p->d_name); + if (port.find("/dev/ttyUSB") == 0 || port.find("/dev/ttySerial") == 0 || port.find("/dev/cu.") == 0) { + newPortInfo.push_back(port); + auto it = std::find(serialPortInfo.begin(), serialPortInfo.end(), port); + if (it == serialPortInfo.end()) { + portChange = true; + WRITE_LOG(LOG_INFO, "new port:%s", port.c_str()); + } } } } - } - if (dir != nullptr) { closedir(dir); } #endif @@ -355,6 +355,9 @@ int OpenSerialPort(std::string portName) { // cannot open with O_CLOEXEC, must fcntl fcntl(uartHandle, F_SETFD, FD_CLOEXEC); int flag = fcntl(uartHandle, F_GETFL); + if (flag < 0) { + return -1; + } flag &= ~O_NONBLOCK; fcntl(uartHandle, F_SETFL, flag); diff --git a/hdc_rust/src/cffi/utils.cpp b/hdc_rust/src/cffi/utils.cpp index 69f1bdd3..64d24195 100644 --- a/hdc_rust/src/cffi/utils.cpp +++ b/hdc_rust/src/cffi/utils.cpp @@ -130,7 +130,7 @@ extern "C" { return ERR_BUF_OVERFLOW; } - int fd = open(bufPath, O_RDWR | O_CREAT, 0666); + int fd = open(bufPath, O_RDWR | O_CREAT, 0644); // 0644:-rw-r--r-- if (fd < 0) { return ERR_FILE_OPEN; } diff --git a/hdcd_user_permit/src/main.cpp b/hdcd_user_permit/src/main.cpp index 51d0e525..cf652b19 100644 --- a/hdcd_user_permit/src/main.cpp +++ b/hdcd_user_permit/src/main.cpp @@ -75,13 +75,19 @@ static int GetUserPermit(void) } if (!con->GetShowDialogResult()) { AUTH_LOGE("show dialog failed"); + delete con; + con = nullptr; return USER_PERMIT_ERR_SHOW_DIALOG_FAIL; } if (!WaitDialogResult()) { AUTH_LOGE("wait ability result failed"); + delete con; + con = nullptr; return USER_PERMIT_ERR_WAIT_DIALOG_FAIL; } + delete con; + con = nullptr; return USER_PERMIT_SUCCESS; } diff --git a/src/host/host_usb.cpp b/src/host/host_usb.cpp index d6fb0fd8..3167bb0a 100644 --- a/src/host/host_usb.cpp +++ b/src/host/host_usb.cpp @@ -213,8 +213,8 @@ void HdcHostUSB::ReviewUsbNodeLater(string &nodeKey) void HdcHostUSB::WatchUsbNodeChange(uv_timer_t *handle) { - HdcHostUSB *thisClass = (HdcHostUSB *)handle->data; - HdcServer *ptrConnect = (HdcServer *)thisClass->clsMainBase; + HdcHostUSB *thisClass = static_cast(handle->data); + HdcServer *ptrConnect = static_cast(thisClass->clsMainBase); libusb_device **devs = nullptr; libusb_device *dev = nullptr; // kick zombie