Fix: improve QProcess usage for Qt6 compatibility#621
Fix: improve QProcess usage for Qt6 compatibility#621deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors QProcess usage in CommonTools::parseEDID to use the program/arguments API instead of shell command strings, adds basic error/empty-output handling, and ensures standard output is decoded via QString::fromLocal8Bit for more robust and Qt6-aligned process execution. Sequence diagram for updated parseEDID QProcess interactionsequenceDiagram
participant Caller as Caller
participant CommonTools as CommonTools
participant QProcess as QProcess
Caller->>CommonTools: parseEDID(allEDIDS, input, isHW)
loop for each edid in allEDIDS
alt isHW
CommonTools->>QProcess: start("hexdump", [edid])
else not isHW
CommonTools->>QProcess: start("hexdump", ["-C", edid])
end
CommonTools->>QProcess: waitForFinished(-1)
alt waitForFinished indicates failure
CommonTools-->>Caller: log qCritical("Failed to hexdump edid file!")
CommonTools-->>CommonTools: continue to next edid
else process finished successfully
CommonTools->>QProcess: readAllStandardOutput()
QProcess-->>CommonTools: QByteArray rawOutput
CommonTools-->>CommonTools: deviceInfo = QString::fromLocal8Bit(rawOutput)
alt deviceInfo is empty
CommonTools-->>Caller: log qWarning("The edid file is empty!", edid)
CommonTools-->>CommonTools: continue to next edid
else deviceInfo not empty
CommonTools-->>CommonTools: parse lines and update edidStr
end
end
end
CommonTools-->>Caller: return
Class diagram for CommonTools::parseEDID and QProcess usageclassDiagram
class CommonTools {
+void parseEDID(QStringList allEDIDS, QString input, bool isHW)
}
class QProcess {
+void start(QString program, QStringList arguments)
+bool waitForFinished(int msecs)
+QByteArray readAllStandardOutput()
}
CommonTools ..> QProcess : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
if (process.waitForFinished(-1))checks are inverted:waitForFinishedreturnstrueon success, so the error path should be taken when it returnsfalse. - When logging failures to run
hexdump, consider includingprocess.error()orreadAllStandardError()to aid debugging instead of only a generic message.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `if (process.waitForFinished(-1))` checks are inverted: `waitForFinished` returns `true` on success, so the error path should be taken when it returns `false`.
- When logging failures to run `hexdump`, consider including `process.error()` or `readAllStandardError()` to aid debugging instead of only a generic message.
## Individual Comments
### Comment 1
<location path="deepin-devicemanager/src/Tool/commontools.cpp" line_range="202" />
<code_context>
- process.start(QString("hexdump %1").arg(edid));
- process.waitForFinished(-1);
+ process.start("hexdump", QStringList() << edid);
+ if (process.waitForFinished(-1)) {
+ qCritical() << "Failed to hexdump edid file!";
+ continue;
</code_context>
<issue_to_address>
**issue (bug_risk):** The success check for waitForFinished is inverted, so failures are silently ignored and successes are treated as errors.
`QProcess::waitForFinished(-1)` returns true on success and false on failure. Here, a successful finish logs an error and continues, while failures are ignored. This should be inverted, e.g. `if (!process.waitForFinished(-1)) { ... }`, so actual hexdump failures are handled.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Note
详情{
"deepin-devicemanager/src/Tool/commontools.cpp": [
{
"line": " return \"https://driver.uniontech.com/api/v1/drive/search\";",
"line_number": 177,
"rule": "S35",
"reason": "Url link | 162cef9d4a"
},
{
"line": " return \"https://driver.uniontech.com/api/v1/drive/search\";",
"line_number": 182,
"rule": "S35",
"reason": "Url link | 162cef9d4a"
},
{
"line": " return \"https://drive-pre.uniontech.com/api/v1/drive/search\";",
"line_number": 185,
"rule": "S35",
"reason": "Url link | 0e010283c1"
}
]
} |
e933af3 to
f03c2cf
Compare
|
Note
详情{
"deepin-devicemanager/src/Tool/commontools.cpp": [
{
"line": " return \"https://driver.uniontech.com/api/v1/drive/search\";",
"line_number": 177,
"rule": "S35",
"reason": "Url link | 162cef9d4a"
},
{
"line": " return \"https://driver.uniontech.com/api/v1/drive/search\";",
"line_number": 182,
"rule": "S35",
"reason": "Url link | 162cef9d4a"
},
{
"line": " return \"https://drive-pre.uniontech.com/api/v1/drive/search\";",
"line_number": 185,
"rule": "S35",
"reason": "Url link | 0e010283c1"
}
]
} |
- Refactored QProcess::start() calls in parseEDID() to use the modern API by separating program name and arguments instead of shell string concatenation. - Added return value validation for waitForFinished() to handle process execution failures gracefully. - Applied QString::fromLocal8Bit() to standard output reading to ensure proper text encoding handling. - These changes improve code robustness, security (avoiding shell injection risks), and compatibility with Qt6 best practices. Log: fix issue Bug: https://pms.uniontech.com/bug-view-353603.html
f03c2cf to
949a9dd
Compare
deepin pr auto review这段代码的修改主要针对 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
5. 进一步优化建议
总结这段代码的改进显著提升了安全性、健壮性和可维护性。通过使用参数列表启动进程、设置超时时间、显式处理编码和添加错误日志,代码的质量和安全性得到了明显提升。进一步优化可以减少重复代码并提高灵活性。 |
|
Note
详情{
"deepin-devicemanager/src/Tool/commontools.cpp": [
{
"line": " return \"https://driver.uniontech.com/api/v1/drive/search\";",
"line_number": 177,
"rule": "S35",
"reason": "Url link | 162cef9d4a"
},
{
"line": " return \"https://driver.uniontech.com/api/v1/drive/search\";",
"line_number": 182,
"rule": "S35",
"reason": "Url link | 162cef9d4a"
},
{
"line": " return \"https://drive-pre.uniontech.com/api/v1/drive/search\";",
"line_number": 185,
"rule": "S35",
"reason": "Url link | 0e010283c1"
}
]
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
Log: fix issue
Bug: https://pms.uniontech.com/bug-view-353603.html
Summary by Sourcery
Improve EDID parsing by hardening external hexdump invocation and output handling for Qt6 compatibility.
Bug Fixes:
Enhancements: