#!/bin/sh # # flintNullPointers-- look for misuses of null pointers, and # for variables assumed to be initialized to zero. # Common on Sequent and Vaxen. # # Runs flint, looks for the following messages: # 32 Field size (member 'Symbol') should not be zero -- The # 54 Division by 0 -- The constant 0 was used on the right # 84 sizeof object is zero or object is undefined -- A sizeof # 85 Array 'Symbol' has dimension 0 -- An array (named Symbol) # 413 Likely use of null pointer 'Symbol' in [left/right] # 414 Possible division by 0 -- The second argument to either # 415 access of out-of-bounds pointer ('Integer' beyond end of # 416 creation of out-of-bounds pointer ('Integer' beyond end of # 418 Passing null pointer to function 'Symbol', Context # 419 Apparent data overrun for function 'Symbol', argument # 420 Apparent access beyond array for function 'Symbol', # 423 Creation of memory leak in assignment to variable 'Symbol' # 530 Symbol 'Symbol' (Location) not initialized -- An auto # 553 Undefined preprocessor variable 'Name', assumed 0 -- The # 564 variable 'Symbol' depends on order of evaluation -- The # 603 Symbol 'Symbol' (Location) not initialized -- The address # 613 Possible use of null pointer 'Symbol' in [left/right] # 644 Variable 'Symbol' (Location) may not have been initialized # 645 Symbol 'Symbol' (Location) may not have been initialized # 661 possible access of out-of-bounds pointer ('Integer' beyond # 662 possible creation of out-of-bounds pointer ('Integer' # 668 Possibly passing a null pointer to function 'Symbol', # 669 Possible data overrun for function 'Symbol', argument # 670 Possible access beyond array for function 'Symbol', # 671 Possibly passing to function 'Symbol' a negative value # 672 Possible memory leak in assignment to pointer 'Symbol' -- # 673 Possibly inappropriate deallocation (Name1) for 'Name2' # 727 Symbol 'Symbol' (Location) not explicitly initialized -- # 728 Symbol 'Symbol' (Location) not explicitly initialized -- # 729 Symbol 'Symbol' (Location) not explicitly initialized -- # 738 Symbol 'Symbol' (Location) not explicitly initialized -- # 771 Symbol 'Symbol' (Location) conceivably not initialized -- # 772 Symbol 'Symbol' (Location) conceivably not initialized -- # 778 Constant expression evaluates to 0 in operation: String # 780 Vacuous array element -- A declaration of an array looks # 784 Nul character truncated from string -- During # 794 Conceivable use of null pointer 'Symbol' in [left/right] # 795 Conceivable division by 0 -- In a division or modulus # 796 Conceivable access of out-of-bounds pointer ('Integer' # 797 Conceivable creation of out-of-bounds pointer ('Integer' # 802 Conceivably passing a null pointer to function 'Symbol', # 803 Conceivable data overrun for function 'Symbol', argument # 804 Conceivable access beyond array for function 'Symbol', # 941 Result 0 due to operand(s) equaling 0 in operation # 1008 Expected '0' to follow '=', text ignored -- Some # 1401 member symbol 'Symbol' (Location) not initialized by # 1402 member 'Symbol' (Location) not initialized -- The # 1403 member 'Symbol' (Location) not initialized -- The # 1501 data member 'Symbol' has zero size -- A data member had # 1532 Symbol 'Symbol' not checking argument for NULL -- This # 1541 member 'Symbol' (Location) possibly not initialized by # 1542 member 'Symbol' (Location) possibly not initialized -- # 1543 member 'Symbol' (Location) possibly not initialized -- # 1741 member 'Symbol' (Location) conceivably not initialized by # 1742 member 'Symbol' (Location) conceivably not initialized -- # 1743 member 'Symbol' (Location) conceivably not initialized -- # 1744 member 'Symbol' (Location) possibly not initialized by # set -x ProgName=`basename $0` Verbose=1 # Turn on filename/linenumbers, use one-line errors for greping. FLINTOPTS='-hF1 -b' main() { if [ $# -lt 1 ]; then say "$ProgName error: you must supply at least one c or c++ file" say "Usage: $0 [-v] file" exit 1 fi if [ "$1" = "-v" ]; then Verbose=1 shift fi name=$1 flint $FLINTOPTS "$@" 2>&1 |\ if [ $Verbose -eq 1 ]; then cat else postprocess fi } # # postprocess -- filter for interesting lines. # # Inputs are of the form: # imaVax.c 22 Error 322: Unable to open # include file 'stdio.h' # postprocess() { egrep -v -e '^---' |\ nawk ' BEGIN { prev = ""; } /^[ \t]+/ { # A second line. print prev " " $0; prev = ""; next; } /.*/ { # A first line. if (prev == "") { prev = $0 } else { print prev } } END { print prev; } ' | nawk ' $4 ~ /^32:|^54:|^84:|^85:|^413:|^414:|^415:|^416:|^418:|^419:|^420:/ \ || $4 ~ /^423:|^530:|^553:|^564:|^603:|^613:|^644:|^645:|^661:|^662:/ \ || $4 ~ /^668:|^669:|^670:|^671:|^672:|^673:|^727:|^728:|^729:/ \ || $4 ~ /^738:|^771:|^772:|^778:|^780:|^784:|^794:|^795:|^796:/ \ || $4 ~ /^797:|^802:|^803:|^804:|^941:|^1008:|^1401:|^1402:|^1403:/ \ || $4 ~ /^1501:|^1532:|^1541:|^1542:|^1543:|^1741:|^1742:|^1743:/ \ || $4 ~ /^1744:/ { print $0; } ' } say() { echo "$@" 1>&2 } main "$@"