亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        Ubuntu系統(tǒng)下C語言代碼檢查工具(Splint)

        字號(hào):

        看一下下面的代碼(當(dāng)然包括錯(cuò)誤,以檢驗(yàn)splint的功能):
            #include
            int main(int argc,char* argv[]){
            int a=100; /*沒有使用的變量*/
            int b[8];
            printf("Hello c\n");
            b[9]=100; /*明顯數(shù)組越界 */
            /* 用到了兩個(gè)為聲明的變量c和d/
            c=100;
            d=10;
            return 0;
            }
            現(xiàn)在可以用splint來檢查一下,為了檢驗(yàn)是否可以檢測(cè)到數(shù)組越界,使用+bounds選項(xiàng)。
            splint hi.c +bounds
            輸出結(jié)果:
            hi.c: (in function main)
            hi.c:9:2: Unrecognized identifier: c
            Identifier used in code has not been declared. (Use -unrecog to inhibit
            warning)
            hi.c:10:2: Unrecognized identifier: d
            hi.c:4:6: Variable a declared but not used
            A variable is declared but never used. Use /*@unused@*/ in front of
            declaration to suppress message. (Use -varuse to inhibit warning)
            hi.c:7:2: Likely out-of-bounds store:
            b[9]
            Unable to resolve constraint:
            requires 7 >= 9
            needed to satisfy precondition:
            requires maxSet(b @ hi.c:7:2) >= 9
            A memory write may write to an address beyond the allocated buffer. (Use
            -likely-boundswrite to inhibit warning)
            hi.c:3:14: Parameter argc not used
            A function parameter is not used in the body of the function. If the argument
            is needed for type compatibility or future plans, use /*@unused@*/ in the
            argument declaration. (Use -paramuse to inhibit warning)
            hi.c:3:25: Parameter argv not used
            Finished checking --- 6 code warnings
            現(xiàn)在詳細(xì)看一下結(jié)果:
            檢查結(jié)果1:
            hi.c:9:2: Unrecognized identifier: c
            Identifier used in code has not been declared. (Use -unrecog to inhibit
            warning)
            hi.c:10:2: Unrecognized identifier: d
            hi.c:4:6: Variable a declared but not used
            A variable is declared but never used. Use /*@unused@*/ in front of
            declaration to suppress message. (Use -varuse to inhibit warning)
            這些應(yīng)該是splint檢測(cè)到變量c和d沒有聲明。
            檢查結(jié)果2:
            hi.c:7:2: Likely out-of-bounds store:
            b[9]
            Unable to resolve constraint:
            requires 7 >= 9
            needed to satisfy precondition:
            requires maxSet(b @ hi.c:7:2) >= 9
            A memory write may write to an address beyond the allocated buffer. (Use
            -likely-boundswrite to inhibit warning)
            這些是檢查存在數(shù)組越界,因?yàn)榘蒪[8]的數(shù)組序號(hào)應(yīng)該是7,而不是9,所以出現(xiàn)requires 7 >= 9;
            檢查結(jié)果3:
            hi.c:3:14: Parameter argc not used
            A function parameter is not used in the body of the function. If the argument
            is needed for type compatibility or future plans, use /*@unused@*/ in the
            argument declaration. (Use -paramuse to inhibit warning)
            hi.c:3:25: Parameter argv not used
            這些表明argc和argv變量聲明了,但是沒有使用。這個(gè)不是什么問題。
            如果小心使用splint,應(yīng)該對(duì)于c語言的程序編寫有非常大的輔助作用!