#!/bin/sh # # lint32bit-- look for misuses of 32/64-bit data # # Runs lint, looks for the following messages: # E_BAD_POINTER_SUBTRACTION improper pointer subtraction # E_BAD_PTR_CAST pointer casts may be troublesome # E_BAD_PTR_CAST_ALIGN pointer cast may result in improper alignment # E_BAD_PTR_CAST_ALIGN_TITLE pointer cast may result in improper alignment # E_BAD_PTR_CAST_TITLE pointer casts may be troublesome # E_BAD_PTR_INT_COMB_ARG improper pointer/integer combination: arg #%d # E_BAD_PTR_INT_COMBINATION improper pointer/integer combination: op "%s" # E_CAST_TO_PTR_FROM_INT cast to pointer from %d-bit integer # E_CNV_CNST_FP_LONG_DBL_OUTRANGE conversion of floating-point constant to # long double out of range # E_CONST_PROMOTED_LONG constant promoted to long # E_CONST_PROMOTED_LONG_LONG constant promoted to long long # E_CONST_PROMOTED_UNSIGNED_LL constant promoted to unsigned long long # E_CONST_PROMOTED_UNSIGNED_LONG constant promoted to unsigned long # E_OPERANDS_INCOMPAT_PTR_TYPES operands have incompatible pointer types: # E_PTR_ARITH_MUST_KNOW_SIZE cannot do pointer arithmetic on operand of # unknown size # E_PTR_CONV_LOSES_BITS conversion of pointer loses bits # E_SIGN_EXTENSION_PSBL sign extension from %d-bit to %d-bit integer # E_UNEXPECTED_UINT_PROMOTION promotion of an unsigned integer type to a # larger integer type or to the size of a pointer #set -x ProgName=`basename $0` Verbose=0 # Turn on almost everything, but use one-line errors for greping. LINTOPTS='-errchk -errhdr -s -errsecurity -Nlevel=3 -Ncheck=macro -XCC -Xtransition -errtags' main() { if [ $# -lt 1 ]; then say "$ProgName error: you must supply at least one C file" say "Usage: $0 [-v] file" exit 1 fi if [ "$1" = "-v" ]; then Verbose=1 shift fi name=$1 lint $LINTOPTS "$@" 2>&1 |\ if [ $Verbose -eq 1 ]; then cat else postprocess fi } # # postprocess -- make multi-line message single-line and filter. # postprocess() { nawk ' BEGIN { prev = ""; } /.*/ { # print ">>> " $0; if ( $0 ~ /^lint/) { # print "<<< lint error" # Lint error, print it print $0; prev = ""; } else if ($0 ~ /E_BAD_POINTER_SUBTRACTION|E_BAD_PTR_CAST|E_BAD_PTR_CAST_ALIGN|E_BAD_PTR_CAST_ALIGN_TITLE|E_BAD_PTR_CAST_TITLE|E_BAD_PTR_INT_COMB_ARG|E_BAD_PTR_INT_COMBINATION|E_CAST_TO_PTR_FROM_INT|E_CNV_CNST_FP_LONG_DBL_OUTRANGE|E_CONST_PROMOTED_LONG|E_CONST_PROMOTED_LONG_LONG|E_CONST_PROMOTED_UNSIGNED_LL|E_CONST_PROMOTED_UNSIGNED_LONG|E_OPERANDS_INCOMPAT_PTR_TYPES|E_PTR_ARITH_MUST_KNOW_SIZE|E_PTR_CONV_LOSES_BITS|E_SIGN_EXTENSION_PSBL|E_UNEXPECTED_UINT_PROMOTION/) { # print "<<< matched" # Matched, see if it was multi-line if ($0 !~ /^"/ && prev != "") { # print "<<< multi-line"; printf("%s ", prev); prev = ""; } # print "<<< the matched line"; print $0; } else if ($0 ~ /^"/) { # beginning of a possible multi-line message # print "<<< saved for possible multi-line"; prev = $0; } } ' } say() { echo "$@" 1>&2 } main "$@"