Go to main content
Oracle Developer Studio 12.6 Man Pages

Exit Print View

Updated: June 2017
 
 

lint(1)

Name

lint - a C program checker

Synopsis

lint [-#]  [-###]  [-a] [-b] [-Cfilename] [-c] [-dirout=dir]
   [-err=warn]  [-errchk=l]  [-errfmt=f]   [-errhdr=h]   [-erroff=t]
   [-errsecurity=v]    [-errtags=a]    [-errwarn=t]    [-F]    [-fd]
   [-flagsrc=file] [-h] [-Idir] [-k] [-Ldir] [-lx] [-m]  [-m32|-m64]
     -errhdr=h[-n] [-ox] [-p] [-Rfile] [-s] [-u] [-V]
   [-v]  [-Wfile]  [-Xarch=amd64]  [-Xarch=v9]   [-Xalias_level[=l]]
   [-XCC=a]   [-Xc99[=o]]   [-Xkeeptmp=a]   [-Xtemp=dir]  [-Xtime=a]
   [-Xtransition=a] [-Xustr={ascii_utf16_ushort|no}] [-x] [-y] files

Description

lint detects features of C program files which are likely to be bugs, non-portable, or wasteful.

lint also checks type usage more strictly than the compiler. lint issues error and warning messages. Among the things it detects are:

  • Unreachable statements

  • Loops not entered at the top

  • Automatic variables declared and not used

  • Logical expressions whose value is constant.

lint checks for functions that return values in some places and not in others, functions called with varying numbers or types of arguments, and functions whose values are not used or whose values are used but none returned.

Arguments whose names end with .c are taken to be C source files; arguments ending in .i are taken to be preprocessor output files (produced with the -P option to the compiler).

Arguments whose names end with .ln are taken to be the result of an earlier invocation of lint with either the -C, -c, or the -o option used. The .ln files are analogous to .o (object) files that are produced by the cc(1) command when given a .c file as input. Files with other suffixes are warned about and ignored.

lint takes all the .c, .i, .ln, and llib-lx.ln (specified by -lx) files and processes them in their command-line order. By default, lint appends the standard C lint library (llib-lc.ln) to the end of the list of files. When the -C or -c option is used, the .ln and the llib-lx.ln files are ignored. When the -C or -c option is not used, the second pass of lint checks the .ln and the llib-lx.ln list of files for mutual compatibility.

Any number of lint options may be used, in any order, intermixed with file-name arguments.

User-Supplied Default Compiler Options Startup File

The default compiler options file enables the user to specify a set of default options that are applied to all compiles, unless otherwise overridden. For example, the file could specify that all compiles default at -xO2, or automatically include the file setup.il.

The default options file can also be used with lint.

At startup, the compiler searches for a default options file listing default options it should include for all compiles. The environment variable SPRO_DEFAULTS_PATH specifies a colon-separated list of directories to search for the the defaults file.

If the environment variable is not set, a standard set of defaults is used. If the environment variable is set but is empty, no defaults are used.

The defaults file name must be of the form compiler.defaults, where compiler is one of the following: cc, c89, c99, CC, ftn, or lint. For example, the defaults for lint would be lint.defaults.

If a defaults file for the compiler is found in the directories listed in SPRO_DEFAULTS_PATH, the compiler will read the file and process the options prior to processing the options on the command line. The first defaults file found will be used and the search terminated.

System administrators may create system-wide default files in Studio-install-path/prod/etc/config. If the environment variable is set, the installed defaults file will not be read.

The format of a defaults file is similar to the command line. Each line of the file may contain one or more compiler options separated by white space. Shell expansions, such as wild cards and substitutions, will not be applied to the options in the defaults file.

The value of the SPRO_DEFAULTS_PATH and the fully expanded command line will be displayed in the verbose output produced by options -#, -###, and -dryrun.

Options specified by the user on the command line will usually override options read from the defaults file. For example, if the defaults file specifies compiling with -xO4 and the user specifies -xO2 on the command line, -xO2 will be used.

Some options appearing in the default options file will be appended after the options specified on the command line. These are the preprocessor option -I, linker options -B, -L, -R, and -l, and all file arguments, such as source files, object files, archives, and shared objects.

The interface stability of the default options file is uncommitted. The order of option processing is subject to change in a future release.

Options

The lint options are:

-#

Show each component as it is invoked (verbose mode).

-###

Show each component as it is invoked, but, unlike the -# option, do not actually execute.

-a

Suppress complaints about assignments of long values to variables that are not long.

-b

Suppress complaints about statements not reached for unreachable break and empty statements.

-Cfilename

Produce a .ln file with the file name specified by filename. These .ln files are the product of lint's first pass only. filename can be a complete path name.

-c

Cause lint to produce a .ln file for every .c file on the command line. These .ln files are the product of lint's first pass only, and are not checked for inter-function compatibility.

-dirout=dir

Set a directory name where all lint output files be will be placed. This option affects the -c option.

-err=warn

This is a macro for -errwarn=%all.

-errchk=l

Check structural arguments passed by value; Check portability to environment for which the size of long integers and pointers is 64 bits.

The values may be a comma separated list such as -errchk=longptr64,structarg.

The default is -errchk=%none. Specifying -errchk is equivalent to specifying -errchk=%all.

l is a comma-separated list of checks that consists of one or more of the following:

[no%]locfmtchk

Use this option when you want lint to check printf-like format strings during its first pass. Regardless of whether or not you use -errchk=locfmtchk, lint always checks for printf-like format strings in its second pass.

[no%]parentheses

Use this option to enhance the maintainability of code. If -errchk=parentheses returns a warning, consider using additional parentheses to clearly signify the precedence of operations within the code.

[no%]signext

This option produces error messages when the normal ANSI/ISO C value-preserving rules allow the extension of the sign of a signed-integral value in an expression of unsigned-integral type. This option only produces error messages when you specify -errchk=longptr64 as well.

[no%]sizematch

Warn when a larger integer is assigned to a smaller integer. These warnings will also be issued for assignment between same size integers which differ in signedness; for example, unsigned int = signed int.

[no%]structarg

Check structural arguments passed by value and report the cases when formal parameter type is not known.

[no%]longptr64

Check portability to environment for which the size of long integers and pointers is 64 bits and the size of plain integers is 32 bits. Check assignments of pointer expressions and long integer expressions to plain integers, even when explicit cast is used.

Note that system header files define types intended to manipulate pointers. With the -m32 flag those types may be defined as base types like int that cannot safely manipulate a pointer, thus leading to false warnings. For example, usages of size_t:

#include <stdlib.h>
size_t
myfiunk(uint32_t param)
{
        return sizeof(uint64_t) * param;
}
.
$ lint -m32 -mux -errchk=longptr64 bug.c
(5) warning: assignment of 64-bit integer to 32-bit integer
$
%all

Perform all of errchk's checks.

%none

Perform none of errchk's checks. This is the default.

-errfmt=f

Specify the format of lint output. f can be one of the following: macro, simple, src, or tab.

macro

Display the source code, the line number, and the place of the error, with macro unfolding.

simple

Display the line number and the place number, in brackets, of the error, for one-line (simple) diagnostic messages. Similar to the -s option, but includes error-position information.

src

Display the source code, the line number, and the place of the error (no macro unfolding).

tab

Display in tabular format.

The default is -errfmt = tab . Specifying -errfmt is equivalent to specifying -errfmt = tab.

If more than one format is specified, the last format specified is used, and lint warns about the unused formats.

-errhdr=h

Enables the reporting of certain messages for header files. h is a comma-separated list that consists of one or more of the following: %all, %none, %user.

%all

Check all used header files.

%none

Do not check header files. This is the default.

%user

Default. Checks all the user header files. Does not check system include files, those in /usr/include and its subdirectories. Does not check system header files supplied by the compiler.

-erroff=t

Suppress or enable lint error messages. t is a comma-separated list that consists of one or more of the following: tag, no%tag, %all, %none.

[no%]tag

Suppress the message specified by this tag.

%all

Suppress all messages.

%none

Enable all messages. This is the default.

The default is -erroff=%none. Specifying -erroff is equivalent to specifying -erroff=%all.

-errsecurity=v

Use the -errsecurity option to check your code for security loopholes. v must be one of the following: core, standard, extended, or %none.

If you do not specify a setting for -errsecurity, lint sets it to -errsecurity=%none. If you specify -errsecurity without a flag, lint sets it to -errsecurity=standard.

core

This level checks for source code constructs that are almost always either unsafe or difficult to verify. Checks at this level include:

  • Use of variable format strings with the printf() and scanf() family of functions

  • Use of unbounded string (%s) formats in scanf() functions

  • Use of functions with no safe usage: gets(), cftime(), ascftime(), creat()

  • Incorrect use of open() with O_CREAT

Consider source code that produces warnings at this level to be a bug. The source code in question should be changed. In all cases, straightforward safer alternatives are available.

standard

This level includes all checks from the core level plus checks for constructs that may be safe, but have better alternatives available. This level is well suited for newly-written code. Additional checks at this level include:

  • Use of string copy functions other than strlcpy()

  • Use of weak random number functions

  • Use of unsafe functions to generate temporary files

  • Use of fopen() to create files

  • Use of functions that invoke the shell

Replace source code that produces warnings at this level with new or significantly modified code. Balance addressing these warnings in legacy code against the risks of destabilizing the application.

extended

This level contains the most complete set of checks, including everything from the core and standard levels. In addition, a number of warnings are generated about constructs that may be unsafe in some situations. The checks at this level are useful as an aid in reviewing code, but need not be used as a standard with which acceptable source code must comply. Additional checks at this level include:

  • Calls to getc() or fgetc() inside a loop

  • Use of functions prone to pathname race conditions

  • Use of the exec family of functions

  • Race conditions between stat() and other functions

Review source code which produces warnings at this level to determine if the potential security issue is present.

-errtags=a

Displays the message tag for each error message. a can be either yes or no. The default is -errtags=no. Specifying -errtags is equivalent to -errtags=yes.

Works with all -errfmt options.

-errwarn=t

If the indicated warning message is issued, lint exits with a failure status. t is a comma-separated list that consists of one or more of the following:

tag

Cause lint to exit with a fatal status if the message specified by tag is issued as a warning message. Has no effect if tag is not issued.

no%tag

Prevent lint from exiting with a fatal status if the message specified by tag is issued only as a warning message. Has no effect if tag is not issued. Use this option to revert a warning message that was previously specified by this option with tag or %all from causing lint to exit with a fatal status when issued as a warning message.

%all

Cause lint to exit with a fatal status if any warning messages are issued. %all can be followed by no%tag to exempt specific warning messages from this behavior.

%none

Prevents any warning messages from causing lint to exit with a fatal status should any warning tag be issued. This is the default.

-F

Print path names of files. lint normally prints the file name without the path.

-fd

Report about old-style function definitions and declarations.

-flagsrc=file

Execute lint with options contained in the file file. Multiple options can be specified in file, one per line.

-h

Do not apply heuristic tests that attempt to intuit bugs, improve style, and reduce waste.

-Idir

Search for included header files in the directory dir before searching the current directory and/or the standard place.

-k

Alter the behavior of /*LINTED [message]*/ directives or NOTE(LINTED(message)) annotations. Normally, lint suppresses warning messages for the code following these directives. Instead of suppressing the messages, lint prints an additional message containing the comment inside the directive or annotation.

-Ldir

Search for lint libraries in dir before searching the standard place.

-lx

Include the lint library llib-lx.ln. For example, you can include a lint version of the math library llib-lm.ln by inserting -lm on the command line. This argument does not suppress the default use of llib-lc.ln. These lint libraries must be in the assumed directory. This option can be used to reference local lint libraries and is useful in the development of multi-file projects.

-m

Suppress complaints about external symbols that could be declared static.

-m32
-m64

Specifies the memory model for the program being analyzed. Also searches for lint libraries that correspond to the selected memory model (32-bit/64-bit). –m64 is the default, except on Oracle Solaris 10 and 11 where –m32 is the default.

Use -m32 to verify 32-bit C programs and -m64 to verify 64-bit C programs.

-n

Do not check compatibility against the standard C lint library.

-ox

Cause lint to create a lint library with the name llib-lx.ln. This library is created from all the .ln files that lint used in its second pass. The -c option nullifies any use of the -o option. To produce a llib-lx.ln without extraneous messages, you can use the -x option. The -v option is useful if the source file(s) for the lint library are just external interfaces. The lint library produced can be used later if lint is invoked with the -lx option.

-p

Attempt to check portability to other dialects of C. Along with stricter checking, this option causes all non-external names to be truncated to eight characters and all external names to be truncated to six characters and one case.

-Rfile

Write a .ln file to file, for use by cxref(1).

-s

Produce simple diagnostics with "warning:" or "error:" prefixes. By default lint buffers some messages to produce compound output.

-u

Suppress complaints about functions and external variables used and not defined, or defined and not used. This option is suitable for running lint on a subset of files of a larger program.

-V

Write to standard error the product name and release.

-v

Suppress complaints about unused arguments in functions.

-Wfile

Write a .ln file to file, for use by cflow(1).

-Xalias_level[=l]

l is one of any, basic, weak, layout, strict, std, or strong. See the C User's Guide for more information.

If you do not specify -Xalias_level, the default of the flag is -Xalias_level=any. This means that there is no type-based alias-analysis. If you specify -Xalias_level but do not supply a level, the default is -Xalias_level=layout.

Be sure to run lint at a level of disambiguation that is no more strict than the level at which you ran the compiler. If you run lint at a level of disambiguation that is more strict than the level at which you compiled, the results will be difficult to interpret and possibly misleading.

-Xarch=amd64

Deprecated. Do not use. See -m32 | -m64.

-Xarch=v9

Deprecated. Do not use. See -m32 | -m64.

-XCC=a

Accept C++-style comments. a can be either yes or no. In particular, / can be used to indicate the start of a comment. The default is -XCC=no; specifying -XCC is equivalent to specifying -XCC=yes.

Note: You only need to use this option if you use -xc99=%none. Under -xc99=%all (the default), lint accepts comments which are indicated by //.

-Xc99=o

The -Xc99 flag controls compiler recognition of the implemented features from the C99 standard (ISO/IEC 9899:1999, Programming Language - C).

o can be one of the following: all, none.

-Xc99=none turns off recognition of C99 features. -Xc99=all turns on recognition of supported C99 features. Specifying -Xc99 without any arguments is the same as -Xc99=all.

Note: Though the compiler support-level defaults to the language features of the C99 standard, the standard headers provided by Solaris 8 and Solaris 9 software in /usr/include do not conform with the 1999 ISO/IEC C standard. If you encounter error messages, try using -Xc99=none to obtain the 1990 ISO/IEC C standard behavior for these headers.

-Xkeeptmp=a

Keep temporary files created during linting instead of deleting them automatically. a can be either yes or no. The default is -Xkeeptmp=no; specifying -Xkeeptmp is equivalent to specifying -Xkeeptmp=yes.

-Xtemp=dir

Set the directory for temporary files to dir. Without this option, temporary files go into /tmp.

-Xtime=a

Report the execution time for each lint pass. a can be either yes or no. The default is -Xtime=no; specifying -Xtime is equivalent to specifying -Xtime=yes.

-Xtransition=a

Issue warnings for the differences between K&R C and Sun ANSI C. a can be either yes or no. The default is -Xtransition=no; specifying -Xtransition is equivalent to specifying -Xtransition=yes.

-Xustr={ascii_utf16_ushort|no}

This option enables recognition of string literals of the form U"ASCII_string" as an array of unsigned short int. Since such strings are not yet part of any standard, this option enables recognition of non-standard C.

You can turn off lint recognition of U"ASCII_string" string literals by specifying -Xustr=no. The rightmost instance of this option on the command line overrides all previous instances.

The default is -Xustr=no. If you specify -Xustr without an argument, the compiler won't accept it and instead issues a warning. The default can change if the C or C++ standards define a meaning for the syntax.

You can specify -Xustr=ascii_ustf16_ushort without also specifying a U"ASCII_string" string literal. It is not an error to do so.

See the explanation for -xustr in the cc(1) man page for a code example that shows a string prepended by U.

-x

Do not report variables referred to by external declarations but never used.

-y

Specify that the file being linted be treated as if the /*LINTLIBRARY*/ directive or the NOTE(LINTLIBRARY) annotation had been used. A lint library is normally created by using the /*LINTLIBRARY*/ directive or the NOTE(LINTLIBRARY) annotation.

lint recognizes many cc (1) command-line options, including -A, -D, -E, -g, -H, -O, -P, -U, -ansi, -std=value, -pedantic, -Xa, -Xc, -Xs, -Xt , and -Y , although -g and -O are ignored. Unrecognized options are warned about and ignored. The predefined macro lint is defined to allow certain questionable code to be altered or removed for lint. Thus, the symbol lint should be thought of as a reserved word for all code that is planned to be checked by lint.

lint provides the following predefinition predicate by default (not valid in -Xc mode):

#assert lint (on)

The lint token is predefined, along with those listed in the cc(1) man page.

Certain conventional comments in the C source change the behavior of lint:

/*ARGSUSEDn*/

Makes lint check only the first n arguments for usage; a missing n is taken to be 0 (this directive acts like the -v option for the next function).

/*CONSTCOND*/ or /*CONSTANTCONDITION*/

suppresses complaints about constant operands for the conditional expression.

/*EMPTY*/

suppresses complaints about a null statement consequent on an if statement. This directive should be placed after the test expression, and before the semicolon. This directive is supplied to support empty if statements when a valid else statement follows. It suppresses messages on an empty else consequent.

/*FALLTHRU*/ or /*FALLTHROUGH*/

suppresses complaints about fall through to a case or default labelled statement. This directive should be placed immediately preceding the label.

/*LINTED [message]\(**/

Suppresses any intra-file warning (those issued by lint pass 1) except those dealing with unused variables or functions. Messages that require inter-file analysis and are issued by lint pass 2 cannot be suppress with the LINTED directive, and a warning message that the LINTED suppression directive was not used is usually given to indicateso. This directive should be placed on the line immediately preceding where the lint warning occurred. The -k option alters the way in which lint handles this directive. Instead of suppressing messages, lint prints an additional message, if any, contained in the comments. This directive is useful in conjunction with the -s option for post-lint filtering.

/*LINTLIBRARY*/

when -o is invoked, writes to a library .ln file only definitions in the .c file it heads. This directive suppresses complaints about unused functions and function arguments in this file.

/*NOTREACHED*/

at appropriate points stops comments about unreachable code. [This comment is typically placed just after calls to functions like exit(2)].

/*PRINTFLIKEn*/

makes lint check the first (n-1) arguments as usual. The nth argument is interpreted as a printf format string that is used to check the remaining arguments.

/*PROTOLIBn*/

causes lint to treat function declaration prototypes as function definitions if n is non-zero. This directive can only be used in conjunction with the /* LINTLIBRARY */ directive. If n is zero, function prototypes are treated normally.

/*SCANFLIKEn*/

makes lint check the first (n-1) arguments as usual. The nth argument is interpreted as a scanf format string that is used to check the remaining arguments.

/*VARARGSn*/

suppresses the usual checking for variable numbers of arguments in the following function declaration. The data types of the first n arguments are checked; a missing n is taken to be 0. The use of the ellipsis terminator (...) in the definition is suggested in new or updated code.

lint directives can also be specified in the form of source code annotations, by including the file note.h, for example:

#include <note.h>
 
NOTE(ARGSUSED(n))
NOTE(CONSTANTCONDITION)
NOTE(EMPTY)
NOTE(FALLTHROUGH)
NOTE(LINTLIBRARY)
NOTE(LINTED(message))
NOTE(NOTREACHED)
NOTE(PRINTFLIKE(n))
NOTE(PRINTFLIKE(func_name,n))
NOTE(PROTOLIB(n))
NOTE(SCANFLIKE(n))
NOTE(SCANFLIKE(func_name,n))
NOTE(VARARGS(n))
NOTE(VARARGS(func_name,n))
     
      

The following two directives can be used only as annotations:

NOTE(ALIGNMENT(func_name, n))

n=1,2,4,8,16,32,64,128

Makes lint set following function result alignment in n bytes. For example, malloc() is defined as returning a "char *" or "void *" when in fact it really returns pointers that are word (or even doubleword) aligned.

NOTE(ARGUNUSED(par_name[,par_name]))

makes lint not check the mentioned arguments for usage (this option acts only for the next function).

lint can, with certain options, show precise source file lines with pointers to the line position where the error occurred. The option enabling this feature is -errfmt=[macro|simple|src|tab]. Under this option, lint provides the following information:

  • Source line(s) and position(s)

  • Macro unfolding

  • Error-prone stack(s)

lint produces its first output on a per-source-file basis. Complaints regarding included files are collected and printed after all source files have been processed, if -s is not specified. Finally, if the -C or -c option is not used, information gathered from all input files is collected and checked for consistency. At this point, if it is not clear whether a complaint stems from a given source file or from one of its included files, the source filename is printed followed by a question mark.

The behavior of the -C, -c, and the -o options allows for incremental use of lint on a set of C source files. Generally, one invokes lint once for each source file with the -C or -c option. Each of these invocations produces a .ln file that corresponds to the .c file, and prints all messages that are about just that source file. After all the source files have been separately run through lint, it is invoked once more (without the -C or -c option), listing all the .ln files with the needed -lx options. This prints all the inter-file inconsistencies. This scheme works well with make; it allows make to be used to lint only the source files that have been modified since the last time the set of source files were linted.

Environment Variables

LINT_OPTIONS

A default set of options to lint. LINT_OPTIONS is interpreted by lint as if its value had been placed on the command line, immediately following the name used to invoke lint, as in:

lint $LINT_OPTIONS ... other-arguments ...
TMPDIR

Usually /tmp but can be redefined by setting the environment variable TMPDIR [see tempnam in tmpnam(3S)].

NOTEPATH

Colon separated paths of directories containing note definition files (see C User's Guide).

Files

lint1

first pass

lint2, lint2n

second pass

llib-lc.ln

declarations for C Library functions (binary format)

TMPDIR/*lint*

temporaries

See Also

cc(1), cflow(1), cxref(1), exit(2), make(1S)

See the lint chapter in the C User's Guide.