-3

越界写。 存在溢出错误。

    > #define FLOORSNUMBER             128 
    > #define ILAFLOORSNUMBER          40
    > #else
    > #define ILAFLOORSNUMBER          40
    > 
    > uint8 downCallSide[ILAFLOORSNUMBER]; extern uint16  
    > callLightTimerAside[FLOORSNUMBER]; extern uint16  
    > callLightTimerBside[FLOORSNUMBER];



    for(i = 0;i <= FLOORSNUMBER;i++)
              {
                    
    **CID 18019 (#1 of 3): Out-of-bounds write (OVERRUN)
     overrun-local: Overrunning array ilaByPass.downCallSide of 40 bytes at byte offset 128 using index i (which evaluates to 128)**

ilaByPass.downCallSide[i] = OFFSTATE;
             
        #ifndef NA 
            
        **CID 17746 (#1 of 3): Out-of-bounds write (OVERRUN)**
        **overrun-local: Overrunning array callLightTimerAside of 128 2-byte elements at element index 128 (byte offset 257) using index i (which evaluates to 128).**

callLightTimerAside[i] = OFFSTATE;
                

我知道当我们尝试 downcallside[i] 时存在溢出,因为 i 的值上升到 128,而 downcallside 的大小仅为 40。我该如何解决?

对于 callLightTimerAside[i],大小似乎与 floornumber 相同,但仍有超限。

4

1 回答 1

0

这是一些看起来很奇怪的 C。不太确定发生了什么,但是

for(i = 0;i <= 楼层数;i++)

这几乎可以肯定是一个错误。您循环通过索引 0-128,而您声明的数组长度为 128,索引为 0-127。第 128 个索引不存在。

尝试

for (i = 0; i < FLOORSNUMBER; i++)
于 2021-10-07T05:48:45.137 回答