#!/bin/sh # # lintNullPointers-- look for misuses if null pointers, and # for variables assumed to be initialized to zero # Common on Sequent and Vaxen. # # Runs lint, looks for the following messages: # E_P_FREE_NULL deallocating NULL pointer :: %s%s%s # E_P_FREE_NULL_PSBL deallocating a pointer that could be NULL :: %s%s%s # E_P_FREE_NULL_PSBL_TITLE deallocating a pointer that could be NULL # E_P_FREE_NULL_TITLE deallocating NULL pointer # E_P_FREE_SUSP deallocating a pointer produced in a questionable way :: %s%s%s # E_P_FREE_SUSP_PSBL deallocating a pointer that could be produced in a questionable way :: %s%s%s # E_P_FREE_SUSP_PSBL_TITLE deallocating a pointer that could be produced in a questionable way # E_P_FREE_SUSP_TITLE deallocating a pointer produced in a questionable way # E_P_FREE_UNINI deallocating uninitialized pointer :: %s%s # E_P_FREE_UNINI_PSBL deallocating a pointer that could be an uninitialized value :: %s%s # E_P_FREE_UNINI_PSBL_TITLE deallocating a pointer that could be an uninitialized value # E_P_FREE_UNINI_TITLE deallocating uninitialized pointer # E_P_REF_NULL reference using a NULL pointer :: %s%s%s # E_P_REF_NULL_PSBL possible reference using NULL pointer :: %s%s%s # E_P_REF_NULL_PSBL_TITLE possible reference using NULL pointer # E_P_REF_NULL_TITLE reference using a NULL pointer # E_P_REF_SUSP reference using a pointer produced in a questionable way :: %s%s%s # E_P_REF_SUSP_PSBL possible reference using a pointer produced in a questionable way :: %s%s%s # E_P_REF_SUSP_PSBL_TITLE possible reference using a pointer produced in a questionable way # E_P_REF_SUSP_TITLE reference using a pointer produced in a questionable way # E_P_REF_UNINI reference using a pointer that is an uninitialized value :: %s%s # E_P_REF_UNINI_PSBL possible reference using an uninitialized pointer :: %s%s # E_P_REF_UNINI_PSBL_TITLE possible reference using an uninitialized pointer # E_P_REF_UNINI_TITLE reference using a pointer that is an uninitialized value # E_P_USE_DEALLOC use of a pointer to deallocated memory :: %s%s%s%s # E_P_USE_DEALLOC_PSBL possible use of a pointer to deallocated memory :: %s%s%s%s # E_P_USE_DEALLOC_PSBL_TITLE possible use of a pointer to deallocated memory # E_P_USE_DEALLOC_TITLE use of a pointer to deallocated memory # E_P_USE_NULL illegal use of NULL pointer :: %s%s%s # E_P_USE_NULL_PSBL possible illegal use of NULL pointer :: %s%s%s # E_P_USE_NULL_PSBL_TITLE possible illegal use of NULL pointer # E_P_USE_NULL_TITLE illegal use of NULL pointer # E_P_USE_SUSP use of a pointer produced in a questionable way :: %s%s%s # E_P_USE_SUSP_PSBL possible use of a pointer produced in a questionable way :: %s%s%s # E_P_USE_SUSP_PSBL_TITLE possible use of a pointer produced in a questionable way # E_P_USE_SUSP_TITLE use of a pointer produced in a questionable way # E_P_USE_UNINI use of a pointer that is an uninitialized value :: %s%s # E_P_USE_UNINI_PSBL use of a pointer that could be an uninitialized value :: %s%s # E_P_USE_UNINI_PSBL_TITLE use of a pointer that could be an uninitialized value # E_P_USE_UNINI_TITLE use of a pointer that is an uninitialized value # E_P_WRT_NULL modification using a NULL pointer :: %s%s%s # E_P_WRT_NULL_PSBL modification using a pointer that could be NULL :: %s%s%s # E_P_WRT_NULL_PSBL_TITLE modification using a pointer that could be NULL # E_P_WRT_NULL_TITLE modification using a NULL pointer # E_P_WRT_SUSP modification using a pointer produced in a questionable way :: %s%s%s # E_P_WRT_SUSP_PSBL modification using a pointer that could be produced in a questionable way :: %s%s%s # E_P_WRT_SUSP_PSBL_TITLE modification using a pointer that could be produced in a questionable way # E_P_WRT_SUSP_TITLE modification using a pointer produced in a questionable way # E_P_WRT_UNINI modification using a pointer that is an uninitialized value :: %s%s # E_P_WRT_UNINI_PSBL modification using a pointer that could be an uninitialized value :: %s%s # E_P_WRT_UNINI_PSBL_TITLE modification using a pointer that could be an uninitialized value # E_P_WRT_UNINI_TITLE modification using a pointer that is an uninitialized value # E_UNEXPECTED_UINT_PROMOTION promotion of an unsigned integer type to a larger integer type or to the size of a pointer may have # E_UNEXPECTED_UINT_PROMOTION_SUB promotion of an unsigned integer to the size of a pointer during subscript evaluation may have u # #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_P_FREE|E_P_REF|E_PTR_USE|E_P_WRT|E_UNEXPECTED_UINT_P/) { # 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 "$@"