Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HUST CSE] a variable is used directly without assigning an initial value #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cospine
Copy link

@cospine cospine commented Apr 18, 2023

1.这个PR修复的是什么问题?

源码 :

static void RNG_BasicConfig()
{
    int32_t i;
    int32_t timeout = 0x1000000;

    /* Enable TRNG & PRNG */
    CLK->AHBCLK0 |= CLK_AHBCLK0_CRPTCKEN_Msk;
    CLK->APBCLK1 |= CLK_APBCLK1_TRNGCKEN_Msk;

    /* Use LIRC as TRNG engine clock */
    CLK->PWRCTL |= CLK_PWRCTL_LIRCEN_Msk;
    while ((CLK->STATUS & CLK_STATUS_LIRCSTB_Msk) == 0)
    {
        if (i++ > timeout) break; /* Wait LIRC time-out */
    }
    CLK->CLKSEL2 = (CLK->CLKSEL2 & (~CLK_CLKSEL2_TRNGSEL_Msk)) | CLK_CLKSEL2_TRNGSEL_LIRC;

}

本段中,i未赋初值即进行i++操作

2.这个PR不修复具体会带来什么后果?

i在未赋初值的情况下执行i++,存在较大风险

3.PR修复方案的依据是什么?

在原函数的基础上,添加i的初值,保证了代码的安全性:
i = 0

4. 在什么环境下测试或者验证过?

all

@cospine cospine changed the title A variable is used directly without assigning an initial value [HUST CSE] a variable is used directly without assigning an initial value Apr 18, 2023
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.

1 participant