diff --git a/test/unittest/vibrator/native/vibrator_agent_test.cpp b/test/unittest/vibrator/native/vibrator_agent_test.cpp index 2800b5f9f012fbe377c1456a06bd9305df6b0881..d9bac5004e76ed2d92ec67ee424669340479e542 100644 --- a/test/unittest/vibrator/native/vibrator_agent_test.cpp +++ b/test/unittest/vibrator/native/vibrator_agent_test.cpp @@ -2841,7 +2841,7 @@ HWTEST_F(VibratorAgentTest, PlayPatternBySessionId_001, TestSize.Level1) MISC_HILOGI("PlayPatternBySessionId_001 in"); VibratorPattern pattern; int32_t ret = PlayPatternBySessionId(0, pattern); - ASSERT_NE(ret, PARAMETER_ERROR); + ASSERT_EQ(ret, PARAMETER_ERROR); } HWTEST_F(VibratorAgentTest, PlayPatternBySessionId_002, TestSize.Level1) @@ -2890,7 +2890,7 @@ HWTEST_F(VibratorAgentTest, PlayPackageBySessionId_001, TestSize.Level1) MISC_HILOGI("PlayPatternBySessionId_001 in"); VibratorPackage package; int32_t ret = PlayPackageBySessionId(0, package); - ASSERT_NE(ret, PARAMETER_ERROR); + ASSERT_EQ(ret, PARAMETER_ERROR); } HWTEST_F(VibratorAgentTest, PlayPackageBySessionId_002, TestSize.Level1) @@ -2930,7 +2930,7 @@ HWTEST_F(VibratorAgentTest, StopVibrateBySessionId_001, TestSize.Level1) { MISC_HILOGI("StopVibrateBySessionId_001 in"); int32_t ret = StopVibrateBySessionId(0); - ASSERT_NE(ret, PARAMETER_ERROR); + ASSERT_EQ(ret, PARAMETER_ERROR); } HWTEST_F(VibratorAgentTest, StopVibrateBySessionId_002, TestSize.Level1) diff --git a/utils/common/src/file_utils.cpp b/utils/common/src/file_utils.cpp index 78419ef27dea35150a1778e5fbc700fcd5ea0ea6..fff2eacc41fa6d20e4977c3e3dc98ebaefb379ec 100755 --- a/utils/common/src/file_utils.cpp +++ b/utils/common/src/file_utils.cpp @@ -187,16 +187,23 @@ std::string ReadFd(const RawFileDescriptor &rawFd) int64_t fdSize = GetFileSize(rawFd.fd); if ((rawFd.offset < 0) || (rawFd.offset > fdSize)) { MISC_HILOGE("offset is invalid, offset:%{public}" PRId64, rawFd.offset); - close(rawFd.fd); return {}; } if ((rawFd.length <= 0) || (rawFd.length > fdSize - rawFd.offset)) { MISC_HILOGE("length is invalid, length:%{public}" PRId64, rawFd.length); - close(rawFd.fd); return {}; } - FILE *fp = fdopen(rawFd.fd, "r"); - CHKPS(fp); + int dupFd = dup(rawFd.fd); + if (dupFd < 0) { + MISC_HILOGE("dup fd failed, fd:%{public}d, errno:%{public}d", rawFd.fd, errno); + return {}; + } + FILE *fp = fdopen(dupFd, "r"); + if (fp == nullptr) { + MISC_HILOGE("fdopen failed, fd:%{public}d, errno:%{public}d", dupFd, errno); + close(dupFd); + return {}; + } if (fseek(fp, rawFd.offset, SEEK_SET) != 0) { MISC_HILOGE("fseek failed, errno:%{public}d", errno); if (fclose(fp) != 0) {