Skip to content

fix(partition): add tolerance to add button enable condition#209

Open
GongHeng2017 wants to merge 1 commit into
linuxdeepin:release/1071from
GongHeng2017:202607011448-re-1071-fix
Open

fix(partition): add tolerance to add button enable condition#209
GongHeng2017 wants to merge 1 commit into
linuxdeepin:release/1071from
GongHeng2017:202607011448-re-1071-fix

Conversation

@GongHeng2017

Copy link
Copy Markdown
Contributor

Add floating-point tolerance when comparing input value with remaining space to prevent disabling the add button due to precision error.

比较输入值与剩余空间时增加浮点容差,避免因精度误差错误禁用添加按钮。

Log: 修复添加按钮在边界值被错误禁用
PMS: BUG-364667
Influence: 修复后用户输入等于剩余空间时添加按钮可正常启用,提升分区创建交互体验。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @GongHeng2017, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@GongHeng2017 GongHeng2017 force-pushed the 202607011448-re-1071-fix branch 2 times, most recently from 69a439b to 5809a1c Compare July 3, 2026 06:21
Add floating-point tolerance when comparing input value with remaining
space to prevent disabling the add button due to precision error.

比较输入值与剩余空间时增加浮点容差,避免因精度误差错误禁用添加按钮。

Log: 修复添加按钮在边界值被错误禁用
PMS: BUG-364667
Influence: 修复后用户输入等于剩余空间时添加按钮可正常启用,提升分区创建交互体验。
@GongHeng2017 GongHeng2017 force-pushed the 202607011448-re-1071-fix branch from 5809a1c to db2cf45 Compare July 3, 2026 06:22
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了浮点数精度导致的分区边界判断错误,但存在魔数未定义的问题
逻辑正确但因缺少常量定义和注释扣5分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

通过在边界判断右侧增加0.01的容差,有效规避了浮点数运算中微小正向误差导致的按钮禁用误判,修复了用户输入最大可用空间时无法点击添加按钮的缺陷
潜在问题:代码中仍保留 value == 0.00 的严格浮点数相等比较,在极端情况下可能存在隐患
建议:将 value == 0.00 改为 value < 0.001 等基于容差的比较方式

  • 2.代码质量(一般)✕

修复代码中直接使用了字面量 0.01,未将其提取为具有语义的常量,且未添加任何注释说明该容差值的物理意义和选择依据
潜在问题:魔数降低了代码可读性和可维护性,后续开发者可能不清楚为何添加0.01
建议:在类中或函数顶部定义常量如 const double kFloatingPointToleranceMB = 0.01; 并添加注释说明其代表0.01MB的容差范围

  • 3.代码性能(无性能问题)✓

仅增加了一次基础的浮点数加法运算,对系统性能和响应时间无任何可感知影响
建议:保持现状

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改仅涉及UI层面的数值边界逻辑判定,不涉及内存操作、外部命令调用、权限变更或敏感数据处理,无安全风险

  • 建议:保持现有的安全状态,无需额外安全加固

■ 【改进建议代码示例】

// 定义浮点数比较容差常量,单位:MB
static constexpr double kPartitionSizeToleranceMB = 0.01;

void PartitionWidget::onSetSliderValue()
{
    m_block = 1;
    m_slider->setValue(static_cast<int>((value / (m_total - (sumValue() / 1024))) * 100));
    m_currentEditSize = QString::number(value * 1024, 'f', 4);
    
    // 使用容差解决浮点数精度丢失问题,避免在最大可用空间边界误判
    if (value < kPartitionSizeToleranceMB || value > (m_total - sumValue() / 1024) + kPartitionSizeToleranceMB) {
        m_addButton->setEnabled(false);
    } else {
        m_addButton->setEnabled(true);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants