2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
28 # include "splintMacros.nf"
36 ** from the CC man page:
38 ** -Idir Search for #include files whose names do not begin with a
39 ** slash (/) in the following order: (1) in the directory of
40 ** the dir argument, (2) in the directories specified by -I
41 ** options, (3) in the standard directory (/usr/include).
44 /* needed for string literals literals */
48 /*@null@*/ /*@observer@*/ char *name;
49 /*@null@*/ /*@observer@*/ char *describe;
52 static flagcatinfo categories[] =
54 { FK_ABSTRACT, "abstract", "abstraction violations, representation access" } ,
55 { FK_ALIAS, "aliasing", "unexpected or dangerous aliasing" } ,
56 { FK_USE, "alluse", "all declarations are used" } ,
57 { FK_ANSI, "ansi", "violations of constraints imposed by ANSI/ISO standard" } ,
58 { FK_ARRAY, "arrays", "special checking involving arrays" } ,
59 { FK_BOOL, "booleans", "checking and naming of boolean types" } ,
60 { FK_COMMENTS, "comments", "warnings about (normal) comments" } ,
61 { FK_SYNCOMMENTS, "syncomments", "interpretation of annotation comments" } ,
62 { FK_COMPLETE, "complete", "completely defined, used, or specified system" } ,
63 { FK_CONTROL, "controlflow", "suspicious control structures" } ,
64 { FK_DEBUG, "debug", "flags for debugging splint" } ,
65 { FK_DECL, "declarations", "consistency of declarations" } ,
66 { FK_DEF, "definition", "undefined storage errors" } ,
67 { FK_DIRECT, "directories", "set directores" } ,
68 { FK_DISPLAY, "display", "control what is displayed" } ,
69 { FK_EFFECT, "effect", "statements with no effects" } ,
70 { FK_ERRORS, "errors", "control expected errors, summary reporting" } ,
71 { FK_EXPORT, "export", "control what may be exported" } ,
72 { FK_EXPOSURE, "exposure", "representation exposure" } ,
73 { FK_EXTENSIBLE, "extensible", "user-defined checks and annotations" },
74 { FK_FILES, "files", "control system files" } ,
75 { FK_FORMAT, "format", "control format of warning messages" } ,
76 { FK_GLOBALS, "globals", "use of global and file static variables" },
77 { FK_HEADERS, "headers", "control inclusion and generation of header files" },
78 { FK_HELP, "help", "on-line help" },
79 { FK_BOUNDS, "memorybounds", "out-of-bounds memory accesses" },
80 { FK_HINTS, "hints", "control display of warning hints" },
81 { FK_SYSTEMFUNCTIONS, "systemfunctions", "special properties of exit and main" },
82 { FK_IMPLICIT, "implicit", "control implicit annotations and interpretations" } ,
83 { FK_INIT, "initializations", "initialization files" } ,
84 { FK_ITER, "iterators", "checking iterator definitions and uses" } ,
85 { FK_LEAK, "leaks", "memory leaks" } ,
86 { FK_LIBS, "libraries", "loading and dumping of user and standard libraries" } ,
87 { FK_LIMITS, "limits", "violations of set limits" } ,
88 { FK_MACROS, "macros", "expansion, definition and use of macros" },
89 { FK_MEMORY, "memory", "memory management" } ,
90 { FK_MODIFIES, "modification", "modification errors" } ,
91 { FK_NAMES, "names", "naming conventions and limits" } ,
92 { FK_NULL, "null", "misuses of null pointers" } ,
93 { FK_NUMBERS, "numbers", "control type-checking of numeric types" } ,
94 { FK_OPS, "operations", "checking of primitive operations" } ,
95 { FK_PARAMS, "parameters", "function and macro parameters" } ,
96 { FK_SPEED, "performance", "speeding up checking" } ,
97 { FK_POINTER, "pointers", "pointers" } ,
98 { FK_PRED, "predicates", "condition test expressions" } ,
99 { FK_PREFIX, "prefixes", "set naming prefixes and control checking" } ,
100 { FK_PREPROC, "preproc", "defines and undefines for the preprocessor" } ,
101 { FK_PROTOS, "prototypes", "function prototypes" } ,
102 { FK_DEAD, "released", "using storage that has been deallocated" } ,
103 { FK_IGNORERET, "returnvals", "ignored return values" },
104 { FK_SECURITY, "security", "possible security vulnerability" },
105 { FK_SPEC, "specifications", "checks involving .lcl specifications" } ,
106 { FK_SUPPRESS, "suppress", "local and global suppression of messages" } ,
107 { FK_TYPEEQ, "typeequivalence", "control what types are equivalent" } ,
108 { FK_BEHAVIOR, "undefined", "code with undefined or implementation-defined behavior" } ,
109 { FK_UNRECOG, "unrecognized", "unrecognized identifiers" } ,
110 { FK_UNSPEC, "unconstrained", "checking in the presence of unconstrained functions" } ,
111 { FK_WARNUSE, "warnuse", "use of possibly problematic function" } ,
112 { FK_ITS4, "its4", "its4 compatibility flags (report warnings for uses of possibly insecure functions)" } ,
113 { FK_SYNTAX, NULL, NULL } ,
114 { FK_TYPE, NULL, NULL } ,
115 { FK_SECRET, NULL, NULL } ,
116 { FK_OBSOLETE, NULL, NULL } ,
117 { FK_NONE, NULL, NULL } /* must be last */
122 ARG_NUMBER, /* number */
124 ARG_STRING, /* string */
125 ARG_FILE, /* filename (also a string) */
126 ARG_DIRECTORY, /* directory (also a string) */
131 static /*@observer@*/ cstring argcode_unparse (argcode arg)
135 case ARG_STRING: return cstring_makeLiteralTemp ("string");
136 case ARG_FILE: return cstring_makeLiteralTemp ("filename");
137 case ARG_DIRECTORY: return cstring_makeLiteralTemp ("directory");
138 case ARG_PATH: return cstring_makeLiteralTemp ("path");
139 case ARG_NUMBER: return cstring_makeLiteralTemp ("number");
140 case ARG_CHAR: return cstring_makeLiteralTemp ("character");
147 /* Make Microsoft VC++ happy */
148 # pragma warning (disable:4715)
153 # pragma warning (enable:4715)
159 bool isSpecial; /* setting this flag may set other flags (or values) */
160 bool isIdem; /* idempotent - always sets to TRUE */
161 bool isGlobal; /* cannot be set locally (using control comments) */
162 bool isModeFlag; /* set by modes */
164 /*@observer@*/ char *flag;
166 /*@observer@*/ /*@null@*/ char *desc;
172 typedef fflag flaglist[];
174 # include "flags.def"
176 /*@iter allFlags (yield observer fflag f); @*/
177 # define allFlags(m_f) \
178 { /*@+enumint@*/ flagcode m_i; for (m_i = 0; m_i < NUMFLAGS; m_i++) { fflag m_f = flags[m_i]; /*@=enumint@*/
179 # define end_allFlags }}
181 static bn_mstring mode_names[] =
183 "weak", "standard", "checks", "strict", NULL,
186 /*@iter allModes (yield bn_mstring modename)@*/
187 # define allModes(m_m) \
188 { int m_ii = 0; while (mstring_isDefined (mode_names[m_ii])) \
189 { bn_mstring m_m = mode_names[m_ii]; m_ii++;
191 # define end_allModes }}
195 static cstring getFlagModeSettings (flagcode p_flag) /*@modifies internalState@*/ ;
196 static cstring describeFlagCode (flagcode p_flag) /*@*/ ;
197 static cstringSList sortedFlags (void) /*@*/ ;
198 static /*@observer@*/ cstring categoryName (flagkind p_kind) /*@*/ ;
200 static flagcode flags_identifyFlagAux (cstring p_s, bool p_quiet) /*@modifies g_warningstream@*/ ;
203 static /*@unused@*/ cstring listModes (void) /*@*/ ;
206 bool flagcode_isSpecialFlag (flagcode f)
208 return (flags[f].isSpecial);
211 bool flagcode_isGlobalFlag (flagcode f)
213 return (flags[f].isGlobal);
216 bool flagcode_isIdemFlag (flagcode f)
218 return (flags[f].isIdem);
221 bool flagcode_isModeFlag (flagcode f)
223 return (flags[f].isModeFlag);
226 bool flagcode_isNameChecksFlag (flagcode f)
228 return (flags[f].main == FK_NAMES);
231 bool flagcode_isHelpFlag (flagcode f)
233 return f == FLG_HELP;
236 bool flagcode_isMessageControlFlag (flagcode f)
239 ** True if opt controls the display of messages.
240 ** These flags must be processed first.
243 return (f == FLG_SHOWSCAN
245 || f == FLG_PARENFILEFORMAT
246 || f == FLG_MESSAGESTREAMSTDERR
247 || f == FLG_MESSAGESTREAMSTDOUT
248 || f == FLG_WARNINGSTREAMSTDERR
249 || f == FLG_WARNINGSTREAMSTDOUT
250 || f == FLG_ERRORSTREAMSTDERR
251 || f == FLG_ERRORSTREAMSTDOUT
252 || f == FLG_MESSAGESTREAM
253 || f == FLG_WARNINGSTREAM
254 || f == FLG_ERRORSTREAM
255 || f == FLG_STREAMOVERWRITE);
259 ** Internal consistency check on the flags.
262 void flags_initMod ()
267 if (flags[code].code != code)
270 "*** ERROR: inconsistent flag %s / %d / %d",
272 flags[code].code, code);
274 llbug (message ("*** ERROR: inconsistent flag %s / %d / %d",
275 cstring_fromChars (flags[code].flag),
276 flags[code].code, code));
289 char *buf = mstring_create (128);
293 if (f.nreported > 0 || f.nsuppressed > 0)
295 int nrep = f.nreported;
296 int nsup = f.nsuppressed;
297 cstring fs = cstring_fill (cstring_fromChars (f.flag), 23);
301 llmsgplain (cstring_makeLiteral
302 ("\nError Type Reported Suppressed\n"
303 "=================== ======== ========="));
307 (void) snprintf (buf, 128, "%s%7d %9d", cstring_toCharsSafe (fs), nrep, nsup);
313 llmsg (cstring_copy (cstring_fromChars (buf)));
319 cstring ts = cstring_fill (cstring_makeLiteralTemp ("Total"), 23);
321 llmsglit (" ======== =========");
323 (void) snprintf (buf, 128, "%s%7d %9d", cstring_toCharsSafe (ts), sumrep, sumsup);
325 llmsgplain (cstring_copy (cstring_fromChars (buf)));
334 flagcode_recordError (flagcode f)
336 if (f != INVALID_FLAG)
338 if (f == FLG_WARNFLAGS)
340 ; /* don't count these */
344 flags[f].nreported = flags[f].nreported + 1;
349 llcontbug (message ("flagcode_recordError: invalid flag: %d", (int) f));
354 flagcode_recordSuppressed (flagcode f)
356 llassertprint (f != INVALID_FLAG, ("flagcode: %s", flagcode_unparse (f)));
358 flags[f].nsuppressed = flags[f].nsuppressed + 1;
362 flagcode_numReported (flagcode f)
364 llassert (f != INVALID_FLAG);
366 return (flags[f].nreported);
369 /*@observer@*/ cstring
370 flagcodeHint (flagcode f)
372 llassert (f != INVALID_FLAG);
374 if (mstring_isDefined (flags[f].hint))
376 return (cstring_fromChars (flags[f].hint));
380 return (cstring_fromChars (flags[f].desc));
384 static int categorySize (flagkind kind) /*@*/
391 if (f.main == kind || f.sub == kind)
400 flagkind identifyCategory (cstring s)
404 for (i = 0; categories[i].kind != FK_NONE; i++)
406 if (mstring_isDefined (categories[i].name))
408 if (cstring_equalLit (s, categories[i].name))
410 return categories[i].kind;
418 static /*@observer@*/ cstring categoryName (flagkind kind)
422 for (i = 0; categories[i].kind != FK_NONE; i++)
424 if (categories[i].kind == kind)
426 return (cstring_fromChars (categories[i].name));
430 return (cstring_makeLiteralTemp ("<No Category>"));
433 static int categoryIndex (flagkind kind)
437 for (i = 0; categories[i].kind != FK_NONE; i++)
439 if (categories[i].kind == kind)
448 void printCategory (flagkind kind)
450 int index = categoryIndex (kind);
452 llassert (index >= 0);
453 llmsg (message ("%s (%d flags)\n\3%s\n\n",
454 cstring_fromChars (categories[index].name),
456 cstring_fromChars (categories[index].describe)));
460 if (f.main == kind || f.sub == kind)
462 llmsg (message (" %s\n\6%q", cstring_fromChars (f.flag),
463 describeFlagCode (f.code)));
469 listAllCategories (void)
473 for (i = 0; categories[i].kind != FK_NONE; i++)
475 flagkind kind = categories[i].kind ;
477 if (categories[i].describe != NULL)
479 llmsg (message ("%s (%d flags)\n\3%s",
482 cstring_fromChars (categories[i].describe)));
488 printAllFlags (bool desc, bool full)
492 cstringSList fl = sortedFlags ();
494 cstringSList_elements (fl, el)
496 /*@i22@*/ /*find out why this is necessary*/
498 tmp = cstring_copy(el);
499 llmsg (message ("%q\n\n", describeFlag (tmp)));
501 } end_cstringSList_elements ;
503 cstringSList_free (fl);
509 if (f.code != INVALID_FLAG && f.main != FK_OBSOLETE)
511 if (mstring_isDefined (f.desc))
515 llmsg (message ("%s --- %s", cstring_fromChars (f.flag),
516 cstring_fromChars (f.desc)));
525 printFlagManual (bool html)
528 ** Prints all flags by category, in order they appear in flags.def
531 flagkind lastCategory = FK_NONE;
535 cstring flagtype = cstring_undefined;
537 if (f.main != lastCategory)
541 llmsg (message ("\n<h4>%s</h4>\n", categoryName (f.main)));
545 llmsg (message ("\n%s\n%s\n",
546 categoryName (f.main),
547 cstring_makeLiteralTemp ("===================================")));
550 lastCategory = f.main;
553 if (f.argtype == ARG_NONE || f.argtype == ARG_SPECIAL)
557 flagname = message ("<tt>%s</tt>", cstring_fromChars (f.flag));
561 flagname = cstring_fromCharsNew (f.flag);
566 if (flagcode_hasString (f.code))
570 flagname = message ("<tt>%s <em><%s></em></tt>",
571 cstring_fromChars (f.flag), argcode_unparse (f.argtype));
575 flagname = message ("%s <%s>", cstring_fromChars (f.flag), argcode_unparse (f.argtype));
578 if (cstring_isDefined (context_getString (f.code)))
582 flagname = message ("%q <font color=\"blue\">[%s]</font>", flagname,
583 context_getString (f.code));
587 flagname = message ("%q [%s]", flagname,
588 context_getString (f.code));
592 else if (f.argtype == ARG_CHAR)
596 flagname = message ("<tt>%s <em><%s></em></tt> <font color=\"blue\">[%c]</font>",
597 cstring_fromChars (f.flag), argcode_unparse (f.argtype),
598 (char) context_getValue (f.code));
602 flagname = message ("%s <%s> [%c]", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
603 (char) context_getValue (f.code));
608 llassert (f.argtype == ARG_NUMBER);
612 flagname = message ("<tt>%s <em><%s></em> <font color=\"blue\">[%d]</font>",
613 cstring_fromChars (f.flag), argcode_unparse (f.argtype),
614 context_getValue (f.code));
618 flagname = message ("%s <%s> [%d]", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
619 context_getValue (f.code));
628 flagtype = message("%q<font color=\"green\">-</font>", flagtype);
632 flagtype = message("%q<->", flagtype);
640 flagtype = message ("%q<font color=\"green\"><em>global</em></font>", flagtype);
644 flagtype = message ("%q<G>", flagtype);
652 flagtype = message ("%q<font color=\"orange\"><em>shortcut</em></font>", flagtype);
656 flagtype = message("%q<S>", flagtype);
664 flagtype = message ("%q mode:<tt>%q</tt>>", flagtype, getFlagModeSettings (f.code));
668 flagtype = message ("%q<M:%q>", flagtype, getFlagModeSettings (f.code));
671 else /* its a plain flag */
675 flagtype = message ("%q plain:<tt>%s</tt>", flagtype,
676 cstring_makeLiteralTemp (context_getFlag (f.code) ? "+" : "-"));
680 flagtype = message ("%q<P:%s>", flagtype,
681 cstring_makeLiteralTemp (context_getFlag (f.code) ? "+" : "-"));
685 llmsg (message ("%s: %s", flagname, flagtype));
689 llgenindentmsgnoloc (cstring_makeLiteral ("<blockquote>"));
692 if (mstring_isDefined (f.hint))
694 llgenindentmsgnoloc (cstring_fromCharsNew (f.hint));
698 llgenindentmsgnoloc (message ("%q.", cstring_capitalize (cstring_fromChars (f.desc))));
703 llgenindentmsgnoloc (cstring_makeLiteral ("</blockquote>"));
709 describeFlagCode (flagcode flag)
711 cstring ret = cstring_undefined;
714 if (flagcode_isInvalid (flag))
716 return (cstring_makeLiteral ("<invalid>"));
719 context_resetAllFlags ();
722 ret = cstring_copy (cstring_fromChars (f.desc));
724 if (f.sub != FK_NONE)
726 ret = message ("%q\nCategories: %s, %s",
728 categoryName (f.main),
729 categoryName (f.sub));
733 if (f.main != FK_NONE)
735 cstring cname = categoryName (f.main);
737 if (cstring_isDefined (cname))
739 ret = message ("%q\nCategory: %s",
747 ret = message ("%q\nMode Settings: %q",
748 ret, getFlagModeSettings (flag));
752 ret = message ("%q\nDefault Setting: %s",
754 cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
759 ret = message("%q\nSet globally only", ret);
763 ret = message("%q\nSet locally", ret);
772 ret = message("%q\nNumeric Argument. Default: %d",
774 context_getValue (flag));
777 ret = message("%q\nCharacter Argument. Default: %h",
778 ret, (char) context_getValue (flag));
785 if (cstring_isDefined (context_getString (flag)))
787 ret = message("%q\n%q argument. Default: %s",
789 cstring_capitalize (argcode_unparse (f.argtype)),
790 context_getString (flag));
794 ret = message("%q\n%s argument. No default.",
796 cstring_capitalize (argcode_unparse (f.argtype)));
802 if (mstring_isDefined (f.hint))
804 ret = message("%q\n\3%s", ret, cstring_fromChars (f.hint));
810 static cstring getFlagModeSettings (flagcode flag)
812 cstring res = cstring_undefined;
816 context_setModeNoWarn (cstring_fromChars (mname));
818 res = message ("%q%s", res, cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
825 describeFlag (cstring flagname)
827 cstring oflagname = cstring_copy (flagname);
828 flagcode f = flags_identifyFlag (flagname);
830 if (flagcode_isSkip (f))
832 cstring_free (oflagname);
833 return cstring_undefined;
835 else if (flagcode_isValid (f))
837 if (cstring_equal (flagname, oflagname))
839 cstring_free (oflagname);
840 return (message ("%s\n\3%q", flagname, describeFlagCode (f)));
844 return (message ("%q (standardized name: %s)\n\3%q",
845 oflagname, flagname, describeFlagCode (f)));
850 if (flags_isModeName (flagname))
852 cstring_free (oflagname);
855 (message ("%s: predefined mode (see Manual for information)",
860 return (message ("%q: <invalid flag>", oflagname));
868 cstringSList s = cstringSList_new ();
874 s = cstringSList_add (s, cstring_fromChars (f.flag));
878 cstringSList_alphabetize (s);
883 void printAlphaFlags ()
885 cstringSList fl = sortedFlags ();
887 cstringSList_printSpaced (fl, 3, 1, context_getLineLen () - 25);
888 cstringSList_free (fl);
891 /*@observer@*/ cstring
892 flagcode_unparse (flagcode code)
894 if (code == INVALID_FLAG)
896 return cstring_makeLiteralTemp ("<invalid flag>");
899 return cstring_fromChars (flags[code].flag);
903 ** Transforms a flag into its cannonical form.
905 ** The following transformations are made:
911 ** parameter -> param
912 ** unrecognized -> unrecog
914 ** declaration -> decl
915 ** globalias -> (no change)
923 ** unconstrained -> unspec
929 static /*@only@*/ cstring
930 canonicalizeFlag (cstring s)
933 cstring res = cstring_copy (s);
934 static bn_mstring transform[] =
940 "parameter", "param",
941 "unrecognized", "unrecog",
943 "declaration", "decl",
951 "unconstrained", "uncon",
961 while ((current = transform[i]) != NULL)
963 if (cstring_containsLit (res, current))
965 cstring_replaceLit (res, current, transform[i+1]);
970 /* remove whitespace, -'s, and _'s */
971 cstring_stripChars (res, " -_");
976 flags_identifyFlag (cstring s)
978 return flags_identifyFlagAux (s, FALSE);
982 flags_identifyFlagQuiet (cstring s)
984 return flags_identifyFlagAux (s, TRUE);
988 flags_identifyFlagAux (cstring s, bool quiet)
993 if (cstring_length (s) == 0) {
994 /* evs 2000-06-25: A malformed flag. */
998 if (cstring_firstChar (s) == 'I')
1000 return FLG_INCLUDEPATH; /* no space required after -I */
1003 if (cstring_firstChar (s) == 'S')
1005 return FLG_SPECPATH; /* no space required after -S */
1008 if (cstring_firstChar (s) == 'D')
1010 return FLG_DEFINE; /* no space required after -D */
1013 if (cstring_firstChar (s) == 'U')
1015 return FLG_UNDEFINE; /* no space required after -D */
1018 cflag = canonicalizeFlag (s);
1023 if (cstring_equal (cstring_fromChars (f.flag), cflag))
1030 if (res == INVALID_FLAG)
1036 if (cstring_equalLit (cflag, "pred"))
1040 else if (cstring_equalLit (cflag, "modobserverstrict"))
1042 res = FLG_MODOBSERVERUNCON;
1044 else if (cstring_equalLit (cflag, "czechnames"))
1048 else if (cstring_equalLit (cflag, "slovaknames"))
1052 else if (cstring_equalLit (cflag, "czechoslovaknames"))
1054 res = FLG_CZECHOSLOVAK;
1056 else if (cstring_equalLit (cflag, "globunspec")
1057 || cstring_equalLit (cflag, "globuncon"))
1059 res = FLG_GLOBUNSPEC;
1061 else if (cstring_equalLit (cflag, "modglobsunspec")
1062 || cstring_equalLit (cflag, "modglobsuncon")
1063 || cstring_equalLit (cflag, "modglobsnomods"))
1065 res = FLG_MODGLOBSUNSPEC;
1067 else if (cstring_equalLit (cflag, "export"))
1069 res = FLG_EXPORTANY;
1071 else if (cstring_equalLit (cflag, "macrospec"))
1073 res = FLG_MACRODECL;
1075 else if (cstring_equalLit (cflag, "ansireservedlocal"))
1077 res = FLG_ISORESERVEDLOCAL;
1079 else if (cstring_equalLit (cflag, "warnposix"))
1081 res = FLG_WARNPOSIX;
1083 else if (cstring_equalLit (cflag, "defuse"))
1087 else if (cstring_equalLit (cflag, "macroundef"))
1089 res = FLG_MACROUNDEF;
1091 else if (cstring_equalLit (cflag, "showcol"))
1095 else if (cstring_equalLit (cflag, "intbool"))
1099 else if (cstring_equalLit (cflag, "intchar"))
1103 else if (cstring_equalLit (cflag, "intenum"))
1107 else if (cstring_equalLit (cflag, "intlong"))
1111 else if (cstring_equalLit (cflag, "intshort"))
1116 ** Backwards compatibility for our American friends...
1119 else if (cstring_equalLit (cflag, "ansilib"))
1123 else if (cstring_equalLit (cflag, "ansistrictlib"))
1125 res = FLG_STRICTLIB;
1127 else if (cstring_equalLit (cflag, "skipansiheaders"))
1129 res = FLG_SKIPISOHEADERS;
1131 else if (cstring_equalLit (cflag, "ansireserved"))
1133 res = FLG_ISORESERVED;
1135 else if (cstring_equalLit (cflag, "ansireservedinternal"))
1137 res = FLG_ISORESERVEDLOCAL;
1144 else if (cstring_equalLit (cflag, "accessunspec"))
1149 (cstring_makeLiteral
1150 ("accessunspec flag is no longer supported. It has been replaced by accessmodule, accessfile and "
1151 "accessfunction to provide more precise control of accessibility "
1152 "of representations. For more information, "
1153 "see splint -help accessmodule"));
1158 else if (cstring_equalLit (cflag, "ansilimits"))
1161 (cstring_makeLiteral
1162 ("ansilimits flag is no longer supported. It has been replaced by ansi89limits and "
1163 "iso99limits to select either the lower translation limits imposed by the ANSI89 "
1164 "standard or the typically higher limits prescribed by ISO C99."));
1168 else if (cstring_equalLit (cflag, "staticmods"))
1173 (cstring_makeLiteral
1174 ("staticmods flag is obsolete. You probably "
1175 "want impcheckmodstatics. For more information, "
1176 "see splint -help impcheckmodstatics"));
1181 else if (cstring_equalLit (cflag, "bool"))
1186 (cstring_makeLiteral ("bool flag is obsolete. It never really "
1187 "made sense in the first place."));
1192 else if (cstring_equalLit (cflag, "shiftsigned"))
1197 (cstring_makeLiteral ("shiftsigned flag is obsolete. You probably "
1198 "want bitwisesigned, shiftnegative or shiftimplementation."));
1203 else if (cstring_equalLit (cflag, "ansi"))
1208 (cstring_makeLiteral ("ansi flag is obsolete. You probably "
1209 "want noparams and/or oldstyle."));
1214 else if (cstring_equalLit (cflag, "usestderr"))
1219 (cstring_makeLiteral
1220 ("usestderr flag is obsolete. This has been replaced "
1221 "by more precise flags for controlling the warning, "
1222 "status message and fatal error streams independently: message-stream-stdout, "
1223 "message-stream-stderr, message-stream <file>, "
1224 "warning-stream-stdout, warning-stream-stderr, warning-stream <file>, "
1225 "error-stream-stdout, error-stream-stderr, error-stream <file>."));
1231 else if (cstring_equalLit (cflag, "stdio"))
1236 (cstring_makeLiteral
1237 ("stdio flag is obsolete. You may "
1238 "want strictlib or one of the gloabls "
1239 "checking flags. For more information, "
1240 "see splint -help strictlib or splint -help flags globals"));
1245 else if (flags_isModeName (cflag))
1247 res = MODENAME_FLAG;
1255 cstring_free (cflag);
1259 void flags_setValueFlag (flagcode opt, cstring arg)
1267 case FLG_INDENTSPACES:
1268 case FLG_LOCINDENTSPACES:
1270 case FLG_EXTERNALNAMELEN:
1271 case FLG_INTERNALNAMELEN:
1272 case FLG_CONTROLNESTDEPTH:
1273 case FLG_STRINGLITERALLEN:
1274 case FLG_NUMSTRUCTFIELDS:
1275 case FLG_NUMENUMMEMBERS:
1276 case FLG_INCLUDENEST:
1278 int val = cstring_toPosInt (arg);
1285 ("Flag %s must be followed by a positive number number. "
1287 flagcode_unparse (opt), arg));
1291 context_setValueAndFlag (opt, val);
1295 case FLG_COMMENTCHAR:
1297 if (cstring_length (arg) != 1)
1301 ("Flag %s should be followed by a single character. Followed by %s",
1302 flagcode_unparse (opt), arg));
1306 context_setCommentMarkerChar (cstring_firstChar (arg));
1314 void flags_setStringFlag (flagcode opt, /*@only@*/ cstring arg)
1320 if (cstring_lastChar (arg) == CONNECTCHAR)
1322 context_setString (opt, arg);
1326 context_setString (opt, cstring_appendChar (arg, CONNECTCHAR));
1332 context_setString (opt, arg);
1341 cstring s = cstring_makeLiteral ("Flag ");
1342 cstringSList sflags = sortedFlags ();
1346 s = message ("%q%9s", s, cstring_fromChars (modename));
1349 s = message ("%q\n", s);
1351 cstringSList_elements (sflags, flagname)
1353 flagcode code = flags_identifyFlag (flagname);
1354 fflag currentflag = flags[code];
1356 if (mstring_isDefined (currentflag.desc) && flagcode_isModeFlag (code))
1358 s = message ("%q\n%27s", s,
1359 cstring_fromChars (currentflag.flag));
1363 context_setMode (cstring_fromChars (modename));
1365 if (context_getFlag (code))
1367 s = message ("%q%9s", s, cstring_makeLiteralTemp ("+"));
1371 s = message ("%q%9s", s, cstring_makeLiteralTemp (" "));
1374 context_resetModeFlags ();
1377 } end_cstringSList_elements;
1379 cstringSList_free (sflags);
1381 s = cstring_appendChar (s, '\n');
1387 static /*@unused@*/ cstring
1390 cstring s = cstring_makeLiteral ("\t");
1395 if (i != 0 && (i % 4 == 0))
1397 s = message ("%q\n\t%15s", s, cstring_fromChars (modename));
1401 s = message ("%q%15s", s, cstring_fromChars (modename));
1411 flags_isModeName (cstring s)
1415 if (mstring_isDefined (modename))
1417 if (cstring_equalLit (s, modename))
1427 extern bool flagcode_hasArgument (flagcode f)
1429 return (flags[f].argtype != ARG_NONE);
1432 extern bool flagcode_hasNumber (flagcode f)
1434 return (flags[f].argtype == ARG_NUMBER);
1437 extern bool flagcode_hasChar (flagcode f)
1439 return (flags[f].argtype == ARG_CHAR);
1442 extern bool flagcode_hasString (flagcode f)
1444 return (flags[f].argtype == ARG_STRING
1445 || flags[f].argtype == ARG_FILE
1446 || flags[f].argtype == ARG_DIRECTORY
1447 || flags[f].argtype == ARG_PATH);
1450 extern int flagcode_valueIndex (flagcode f)
1452 /*@unchecked@*/ static bool initialized = FALSE;
1454 /*@unchecked@*/ static flagcode valueFlags[NUMVALUEFLAGS];
1462 if (flagcode_hasNumber (code) || flagcode_hasChar (code))
1464 llassert (nv < NUMVALUEFLAGS);
1465 DPRINTF (("Value flag: %s [%d]", flagcode_unparse (code), (int) code));
1466 valueFlags[nv] = code;
1471 llassertprint (nv == NUMVALUEFLAGS,
1472 ("Number of value flags: %d (expected %d)",
1473 nv, (int) NUMVALUEFLAGS));
1477 for (i = 0; i < NUMVALUEFLAGS; i++)
1479 /* static valueFlags must be defined */
1481 if (f == valueFlags[i]) /*@=usedef@*/
1487 fprintf (stderr, "Cannot find value flag: %d", (int) f);
1488 exit (EXIT_FAILURE);
1489 /* Cannot do this...might call recursively...
1490 llfatalbug (message ("Cannot fine value flag: %d", (int) f));
1495 extern int flagcode_stringIndex (flagcode f)
1497 /*@unchecked@*/ static bool initialized = FALSE;
1498 /*@unchecked@*/ static flagcode stringFlags[NUMSTRINGFLAGS];
1508 if (flagcode_hasString (code))
1510 llassertprint (nv < NUMSTRINGFLAGS, ("Incorrect number of string flags: %d (need at least %d)", NUMSTRINGFLAGS, nv));
1511 stringFlags[nv] = code;
1516 llassertprint (nv == NUMSTRINGFLAGS,
1517 ("number of string flags: %d (expected %d)",
1518 nv, NUMSTRINGFLAGS));
1522 for (i = 0; i < NUMSTRINGFLAGS; i++)
1524 /*@-usedef@*/ if (f == stringFlags[i]) /*@=usedef@*/
1530 llbug (message ("Bad string flag: %s", flagcode_unparse (f)));
1534 bool flagcode_isNamePrefixFlag (flagcode f)
1538 case FLG_MACROVARPREFIX:
1540 case FLG_ENUMPREFIX:
1541 case FLG_FILESTATICPREFIX:
1542 case FLG_GLOBPREFIX:
1543 case FLG_TYPEPREFIX:
1544 case FLG_EXTERNALPREFIX:
1545 case FLG_LOCALPREFIX:
1546 case FLG_UNCHECKEDMACROPREFIX:
1547 case FLG_CONSTPREFIX:
1548 case FLG_ITERPREFIX:
1549 case FLG_DECLPARAMPREFIX:
1556 static cstring findLarchPathFile (/*@temp@*/ cstring s)
1561 status = osd_getPath (context_getLarchPath (), s, &pathName);
1563 if (status == OSD_FILEFOUND)
1567 else if (status == OSD_FILENOTFOUND)
1570 lldiagmsg (message ("Cannot find file on LARCH_PATH: %s", s));
1572 else if (status == OSD_PATHTOOLONG)
1574 /* Directory and filename are too long. Report error. */
1575 llbuglit ("soure_getPath: Filename plus directory from search path too long");
1582 return cstring_undefined;
1585 static void addLarchPathFile (fileIdList files, /*@temp@*/ cstring s)
1587 cstring pathName = findLarchPathFile (s);
1589 if (cstring_isDefined (pathName))
1591 if (fileTable_exists (context_fileTable (), pathName))
1594 lldiagmsg (message ("File listed multiple times: %s", pathName));
1595 cstring_free (pathName);
1599 fileIdList_add (files, fileTable_addFileOnly (context_fileTable (), pathName));
1605 static void addFile (fileIdList files, /*@only@*/ cstring s)
1607 if (fileTable_exists (context_fileTable (), s))
1610 lldiagmsg (message ("File listed multiple times: %s", s));
1615 fileIdList_add (files, fileTable_addFileOnly (context_fileTable (), s));
1619 static void addXHFile (fileIdList files, /*@temp@*/ cstring s)
1621 cstring pathName = findLarchPathFile (s);
1623 if (cstring_isDefined (pathName))
1625 if (fileTable_exists (context_fileTable (), pathName))
1628 lldiagmsg (message ("File listed multiple times: %s", s));
1632 fileIdList_add (files, fileTable_addXHFile (context_fileTable (), pathName));
1636 cstring_free (pathName);
1640 flags_processFlags (bool inCommandLine,
1643 fileIdList lclfiles,
1645 cstringList *passThroughArgs,
1646 int argc, char **argv)
1649 cstringSList fl = cstringSList_undefined;
1651 for (i = 0; i < argc; i++)
1655 llassert (argv != NULL);
1658 DPRINTF (("process thisarg [%d]: %s", i, thisarg));
1660 if (*thisarg == '-' || *thisarg == '+')
1662 bool set = (*thisarg == '+');
1663 cstring flagname = cstring_fromChars (thisarg + 1); /* skip '-' or '+' */
1664 flagcode opt = flags_identifyFlag (flagname);
1666 DPRINTF (("Flag [%s]: %s", flagname, flagcode_unparse (opt)));
1668 if (flagcode_isInvalid (opt))
1670 DPRINTF (("Error!"));
1671 voptgenerror (FLG_BADFLAG,
1672 message ("Unrecognized option: %s",
1673 cstring_fromChars (thisarg)),
1676 else if (flagcode_isHelpFlag (opt))
1680 voptgenerror (FLG_BADFLAG,
1681 message ("Help flag must be first on the command line: %s",
1682 cstring_fromChars (thisarg)),
1687 voptgenerror (FLG_BADFLAG,
1688 message ("Help flags can only be used on the command line: %s",
1689 cstring_fromChars (thisarg)),
1693 else if (flagcode_isPassThrough (opt)) /* preprocessor flag: -D or -U */
1696 ** Following space is optional, don't include the -
1699 *passThroughArgs = cstringList_add (*passThroughArgs,
1700 cstring_fromCharsNew (thisarg + 1));
1702 else if (opt == FLG_INCLUDEPATH || opt == FLG_SPECPATH)
1704 if (mstring_length (thisarg) < 2) {
1707 if (mstring_equal (thisarg, "-I-")) {
1708 cppAddIncludeDir (cstring_fromChars (thisarg)); /* Need to handle this specially. */
1710 cstring dir = cstring_suffix (cstring_fromChars (thisarg), 2); /* skip over -I */
1712 DPRINTF (("Length of thisarg [%s] %d", thisarg, cstring_length (thisarg)));
1714 if (cstring_length (dir) == 0) {
1715 DPRINTF (("space after directory: "));
1717 dir = cstring_fromChars (argv[i]);
1722 ("Flag %s must be followed by a directory name",
1723 flagcode_unparse (opt)),
1728 DPRINTF (("Got directory: [%s]", dir));
1732 case FLG_INCLUDEPATH:
1733 cppAddIncludeDir (dir);
1734 /*@switchbreak@*/ break;
1737 g_localSpecPath = cstring_toCharsSafe
1739 cstring_fromChars (g_localSpecPath),
1743 /*@switchbreak@*/ break;
1749 else if (flagcode_isModeName (opt))
1751 context_setMode (flagname);
1753 else if (inCommandLine && flagcode_isMessageControlFlag (opt))
1756 ** Processed on first pass
1759 if (flagcode_hasArgument (opt))
1767 ** A normal control flag
1770 context_userSetFlag (opt, set);
1772 if (flagcode_hasArgument (opt))
1774 if (flagcode_hasNumber (opt))
1778 flags_setValueFlag (opt, cstring_fromCharsNew (argv[i]));
1785 ("Flag %s must be followed by a number",
1786 flagcode_unparse (opt)),
1790 else if (flagcode_hasChar (opt))
1794 flags_setValueFlag (opt, cstring_fromCharsNew (argv[i]));
1801 ("Flag %s must be followed by a character",
1802 flagcode_unparse (opt)),
1806 else if (flagcode_hasString (opt)
1807 || opt == FLG_INIT || opt == FLG_OPTF)
1812 Changed this because arg can be freed when it's passed to
1813 lslinit_setInitFile and freeing argv[i] causes a seg fault
1815 cstring arg = cstring_fromCharsNew (argv[i]);
1817 if (opt == FLG_OPTF)
1821 ; /* -f already processed */
1825 (void) rcfiles_read (arg, passThroughArgs, TRUE);
1828 else if (opt == FLG_INIT)
1830 lslinit_setInitFile (inputStream_create
1832 cstring_makeLiteralTemp (LCLINIT_SUFFIX),
1838 DPRINTF (("String flag: %s / %s",
1839 flagcode_unparse (opt), arg));
1840 if (opt == FLG_MTSFILE)
1843 ** arg identifies mts files
1845 cstring tmp = message ("%s%s", arg, MTS_EXTENSION);
1846 addLarchPathFile (mtfiles, tmp);
1848 tmp = message ("%s%s", arg, XH_EXTENSION);
1849 addXHFile (xfiles, tmp);
1854 flags_setStringFlag (opt, cstring_copy (arg));
1863 ("Flag %s must be followed by a string",
1864 flagcode_unparse (opt)),
1875 else /* its a filename */
1877 DPRINTF (("Adding filename: %s", thisarg));
1878 fl = cstringSList_add (fl, cstring_fromChars (thisarg));
1883 ** create lists of C and LCL files
1888 cstringSList_elements (fl, current)
1890 cstring ext = fileLib_getExtension (current);
1892 if (cstring_isUndefined (ext))
1894 /* no extension --- both C and LCL with default extensions */
1896 addFile (cfiles, message ("%s%s", current, C_EXTENSION));
1897 addFile (lclfiles, message ("%s%s", current, LCL_EXTENSION));
1899 else if (cstring_equal (ext, XH_EXTENSION))
1901 addXHFile (xfiles, current);
1903 else if (cstring_equal (ext, PP_EXTENSION))
1905 if (!context_getFlag (FLG_NOPP))
1908 (FLG_FILEEXTENSIONS,
1909 message ("File extension %s used without +nopp flag (will be processed as C source code): %s",
1914 addFile (cfiles, cstring_copy (current));
1916 else if (cstring_equal (ext, LCL_EXTENSION))
1918 addFile (lclfiles, cstring_copy (current));
1920 else if (fileLib_isCExtension (ext))
1922 addFile (cfiles, cstring_copy (current));
1924 else if (cstring_equal (ext, MTS_EXTENSION))
1926 addLarchPathFile (mtfiles, current);
1931 (FLG_FILEEXTENSIONS,
1932 message ("Unrecognized file extension: %s (assuming %s is C source code)",
1936 addFile (cfiles, cstring_copy (current));
1938 } end_cstringSList_elements;
1942 if (cstringSList_size (fl) != 0)
1944 /* Cannot list files in .splintrc files */
1945 voptgenerror (FLG_BADFLAG,
1946 message ("Cannot list files in .splintrc files: %s (probable missing + or -)",
1947 cstringSList_unparse (fl)),
1952 cstringSList_free (fl); /* evans 2002-07-12: why wasn't this reported!?? */
1955 int flagcode_priority (/*@unused@*/ flagcode code)
1958 ** For now, we do a really simple prioritization: all are 1