Tutu7.10 C language code Check auxiliary tool splint

Source: Internet
Author: User
Recently I have been studying C expert programming and mentioned the C language code check tool lint under Ubuntu7.10. Using aptitudesearch, we did not find the lint software package, but found the splint tool. Check the following code (including errors to check splint functions): # define deintmain (intargc, char * argv []) {inta = 100; /* unused variables */intb [

Recently I have been studying C expert programming and mentioned the code check tool for lint in Ubuntu 7.10.

You can use aptitude to search without finding the lint software package. Instead, you can find the splint tool.
Check the following code (including errors to verify the splint function ):

# Include

Int main (int argc, char * argv []) {
Int a = 100;/* unused variable */
Int B [8];
Printf ("Hello c \ n ");
B [9] = 100;/* Apparently out-of-bounds array */

/* Two declared variables c and d/are used/
C = 100;
D = 10;
Return 0;
}

Now we can use splint to check whether the array is out of bounds and use the + bounds option.
Splint hi. c + bounds

Output result:
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
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
Argument declaration. (Use-paramuse to inhibit warning)
Hi. c: 3: 25: Parameter argv not used

Finished checking --- 6 code warnings

Now let's take a closer look at the results:
Check Result 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
Declaration to suppress message. (Use-varuse to inhibit warning)
These variables c and d are not declared by splint.

Check Result 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)
These are checks for the existence of array out-of-bounds, because B [8]'s maximum array number should be 7, rather than 9, so the emergence of requires 7> = 9;

Check Result 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
Argument declaration. (Use-paramuse to inhibit warning)
Hi. c: 3: 25: Parameter argv not used
These indicate that the argc and argv variables are declared but not used. This is not a problem.

If you use splint carefully, it should be very helpful for programming in C language!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.