2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 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
27 ** error reporting procedures
30 # include "splintMacros.nf"
35 # include "cpperror.h"
36 # include "Headers/version.h" /* Visual C++ finds a different version.h on some path! */
38 /* Don't allow possibly-recursive assertion failures. */
40 # define llassert llassertprotect
42 static void printIndentMessage (FILE *p_stream, /*@only@*/ cstring p_sc, int p_indent)
43 /*@modifies *p_stream@*/ ;
46 static int lclerrors = 0;
49 static int lastfileloclen = 10;
50 static /*@only@*/ cstring lastmsg = cstring_undefined;
51 static int mcount = 0;
52 static /*@only@*/ cstring saveOneMessage = cstring_undefined;
53 static /*@only@*/ fileloc lastparseerror = fileloc_undefined;
54 static /*@only@*/ fileloc lastbug = fileloc_undefined;
55 static bool llgenerrorreal (char *p_srcFile, int p_srcLine,
56 /*@only@*/ cstring p_s, fileloc p_fl, bool p_iserror, bool p_indent)
57 /*@modifies g_msgstream@*/ ;
58 static bool llgenerroraux (char *p_srcFile, int p_srcLine,
59 /*@only@*/ cstring p_s, fileloc p_fl, bool p_iserror, bool p_indent)
60 /*@modifies g_msgstream@*/ ;
62 static void printError (FILE *p_stream, /*@only@*/ cstring p_sc)
63 /*@globals lastfileloclen @*/
64 /*@modifies *p_stream@*/ ;
65 static void printMessage (FILE *p_stream, /*@only@*/ cstring p_s)
66 /*@modifies *p_stream@*/ ;
68 static void llgenhint (/*@only@*/ cstring p_s) /*@modifies g_msgstream@*/ ;
70 static void showSourceLoc (char *srcFile, int srcLine)
71 /*@modifies g_msgstream@*/
73 if (context_getFlag (FLG_SHOWSOURCELOC)) {
74 llgenhint (message ("%s:%d: Source code error generation point.",
75 cstring_fromChars (srcFile), srcLine));
80 static /*@null@*/ char *
81 maxcp (/*@null@*/ /*@returned@*/ char *a, /*@null@*/ /*@returned@*/ char *b)
90 fprintf (stderr, " *** Please report bug to %s ***\n",
93 /* don't exit (EXIT_FAILURE); */
96 static bool s_needsPrepare = TRUE;
98 void prepareMessage (void)
100 DPRINTF (("Prepare message: %s", bool_unparse (context_loadingLibrary ())));
103 if ((context_isPreprocessing () || context_loadingLibrary ())
105 && context_getDebug (FLG_SHOWSCAN))
108 fprintf (stderr, " >\n");
109 s_needsPrepare = FALSE;
115 void closeMessage (void)
117 if (context_isPreprocessing ()
118 && context_getDebug (FLG_SHOWSCAN))
121 fprintf (stderr, "< more preprocessing .");
123 llassertprotect (!s_needsPrepare);
124 s_needsPrepare = TRUE;
133 llmsg (/*@only@*/ cstring s)
135 context_setNeednl ();
137 printMessage (g_msgstream, s);
142 lldiagmsg (/*@only@*/ cstring s)
144 static bool inmsg = FALSE;
148 fprintf (stderr, "Recursive message call detected: %s\n", cstring_toCharsSafe (s));
154 context_setNeednl ();
156 printMessage (stderr, s);
163 llmsgplain (/*@only@*/ cstring s)
165 context_setNeednl ();
167 printMessage (g_msgstream, s);
171 void llerror_flagWarning (cstring s)
173 if (context_getFlag (FLG_WARNFLAGS))
177 if (fileloc_isBuiltin (g_currentloc))
179 llmsg (message ("Warning: %q", s));
183 llgenmsg (message ("Warning: %q", s), g_currentloc);
193 llgenhint (/*@only@*/ cstring s) /*@modifies g_msgstream@*/
195 int indent = context_getIndentSpaces () - 1;
197 if (indent < 0) indent = 0;
199 context_setNeednl ();
200 printIndentMessage (g_msgstream, s, indent);
206 if (context_getFlag (FLG_HINTS) &&
207 !(context_inSuppressRegion () || context_inSuppressZone (g_currentloc)))
218 llshowhint (flagcode f)
220 if (context_getFlag (FLG_HINTS))
222 if ((flagcode_numReported (f) == 0) || context_getFlag (FLG_FORCEHINTS))
224 cstring desc = flagcodeHint (f);
226 if (cstring_isDefined (desc))
228 llgenhint (cstring_copy (desc));
235 llsuppresshint2 (char c, flagcode f1, flagcode f2)
238 if (context_getFlag (FLG_HINTS))
240 if ((flagcode_numReported (f1) == 0
241 || flagcode_numReported (f2) == 0)
242 || context_getFlag (FLG_FORCEHINTS))
244 cstring desc = flagcodeHint (f1);
245 context_setNeednl ();
248 if (cstring_isUndefined (desc))
250 desc = flagcodeHint (f2);
253 if (flagcode_isNamePrefixFlag (f1))
258 if (flagcode_isNamePrefixFlag (f2))
265 if (cstring_isDefined (desc))
267 llgenhint (message ("%s (Use %h%s to inhibit warning)", desc,
269 flagcode_unparse (f1)));
273 llgenhint (message ("(Use %h%s to inhibit warning)",
274 c, flagcode_unparse (f1)));
279 if (cstring_isDefined (desc))
281 llgenhint (message ("%s (Use either %h%s or %h%s to inhibit warning)", desc,
283 flagcode_unparse (f1),
285 flagcode_unparse (f2)));
289 llgenhint (message ("(Use either %h%s or %h%s to inhibit warning)", c,
290 flagcode_unparse (f1),
291 c, flagcode_unparse (f2)));
299 llsuppresshint (char c, flagcode f)
301 if (context_getFlag (FLG_HINTS))
303 if ((flagcode_numReported (f) == 0) || context_getFlag (FLG_FORCEHINTS))
305 cstring desc = flagcodeHint (f);
306 context_setNeednl ();
309 if (flagcode_isNamePrefixFlag (f))
314 if (cstring_isDefined (desc))
316 llgenhint (message ("%s (Use %h%s to inhibit warning)", desc, c,
317 flagcode_unparse (f)));
321 llgenhint (message ("(Use %h%s to inhibit warning)", c,
322 flagcode_unparse (f)));
329 llnosuppresshint (flagcode f)
331 if (context_getFlag (FLG_FORCEHINTS))
333 cstring desc = flagcodeHint (f);
334 context_setNeednl ();
337 if (cstring_isDefined (desc))
339 printError (g_msgstream, message (" %s", desc));
344 /*@constant int MAXSEARCH; @*/
345 # define MAXSEARCH 20
347 /*@constant int MINLINE; @*/
350 typedef /*@null@*/ /*@dependent@*/ char *nd_charp;
353 mstring_split (/*@returned@*/ char **sp,
354 /*@out@*/ nd_charp *tp,
355 int maxline, /*@in@*/ int *indentchars)
364 DPRINTF (("Split: %s / %d", *sp, maxline));
366 if (maxline < MINLINELEN)
368 maxline = MINLINELEN;
371 if (*indentchars > 0)
373 s = *sp = mstring_concatFree1 (mstring_spaces (*indentchars), s);
377 nl = strchr (s, '\n');
382 ** if there is a newline in first maxline characters, split there
383 ** if line len is <= maxline, return no split
384 ** if there is a ':' or ';' followed by ' ' in first maxline characters,
385 ** split there unless the ' ' is followed by a '}', then
387 ** of the ';' is inside quotation marks
388 ** if there is a space or tab in last maxsearch characters, split there
389 ** else, split at maxline
391 ** special code: slash [1-9] after a newline means indent the rest <n> chars
395 if ((nl != NULL) && ((nl - s) < maxline))
402 llassertprotect (*tp == NULL || (*tp > osp));
406 if (*t >= '\1' && *t <= '\7')
408 *indentchars += (int) (*t - '\1') + 1;
415 else if (size_toInt (strlen (s)) < maxline)
417 llassertprotect (*tp == NULL || (*tp > osp));
424 char *lcolon, *lsemi, *splitat;
432 lcolon = strrchr (s, ':');
433 lsemi = strrchr (s, ';');
436 splitat = maxcp (lcolon, lsemi);
438 if (splitat != NULL && ((int)(splitat - s) > MINLINE)
439 && *(splitat) != '\0'
440 && *(splitat + 1) == ' '
441 && (*(splitat + 2) != '}' && (*(splitat + 2) != '\0')))
443 *(splitat + 1) = '\0';
446 llassertprotect (*tp == NULL || (*tp > osp));
450 while (*t != ' ' && *t != '\t' && i < MAXSEARCH)
456 if (*t != ' ' && *t != '\t')
458 llassertprotect (maxline > 0);
459 t = mstring_copy (s + maxline);
460 *(s + maxline) = '\0';
465 llassertprotect (*tp == NULL || (*tp > osp));
469 mstring_markFree (t);
471 /* Won't be true since t is a copy: llassertprotect (*tp == NULL || (*tp > osp)); */
480 if (*t == '\0') return;
483 ** returns unqualified as only
489 /* Hack to prevent error case for wierd strings. */
495 llassertprotect (*tp == NULL || (*tp > osp));
506 void limitmessage (/*@only@*/ cstring s, fileloc loc)
508 if (mcount > context_getLimit () + 1)
514 cstring flstring = fileloc_unparse (loc);
516 lastfileloclen = cstring_length (flstring);
517 cstring_free (saveOneMessage);
518 saveOneMessage = message ("%q: %q", flstring, s);
522 static int parseerrorcount = 0;
524 void cleanupMessages ()
528 if (context_unlimitedMessages ())
534 int unprinted = mcount - context_getLimit ();
538 if (unprinted == 1 && cstring_isDefined (saveOneMessage))
541 printError (g_msgstream, saveOneMessage);
543 saveOneMessage = cstring_undefined;
547 if (cstring_isDefined (saveOneMessage))
549 /* cstring_free (saveOneMessage); */
550 saveOneMessage = cstring_undefined;
553 fprintf (g_msgstream, "%s: (%d more similar errors unprinted)\n",
554 cstring_toCharsSafe (fileloc_filename (g_currentloc)),
555 mcount - context_getLimit ());
564 llgenmsg (/*@only@*/ cstring s, fileloc fl)
566 cstring flstring = fileloc_unparse (fl);
567 lastfileloclen = cstring_length (flstring);
570 (void) printError (g_msgstream, message ("%q: %q", flstring, s));
575 llgenindentmsg (/*@only@*/ cstring s, fileloc fl)
577 cstring flstring = fileloc_unparse (fl);
580 (void) printIndentMessage (g_msgstream, message ("%q: %q", flstring, s), context_getIndentSpaces ());
585 llgenindentmsgnoloc (/*@only@*/ cstring s)
588 (void) printIndentMessage (g_msgstream, s, context_getIndentSpaces ());
593 llgentypeerroraux (char *srcFile, int srcLine,
594 flagcode ocode, ctype t1, exprNode e1, ctype t2, exprNode e2,
595 /*@only@*/ cstring s, fileloc fl)
597 cstring hint = cstring_undefined;
598 flagcode code = ocode;
599 flagcode hcode = INVALID_FLAG;
603 DPRINTF (("Type error [%s]: %s / %s : %s / %s",
604 flagcode_unparse (ocode),
605 exprNode_unparse (e1), exprNode_unparse (e2),
606 ctype_unparse (t1), ctype_unparse (t2)));
608 DPRINTF (("Bool: %s / %s",
609 bool_unparse (ctype_isBool (t1)),
610 bool_unparse (ctype_isBool (t2))));
613 ** Set the flag using the underlying types that didn't match.
616 while (ctype_isPointer (ut1) && ctype_isPointer (ut2)) {
617 ut1 = ctype_baseArrayPtr (ut1);
618 ut2 = ctype_baseArrayPtr (ut2);
621 if ((ctype_isFloat (ut1) && ctype_isDouble (ut2))
622 || (ctype_isFloat (ut1) && ctype_isDouble (ut2)))
624 hcode = FLG_FLOATDOUBLE;
626 else if ((exprNode_isCharLit (e1) && ctype_isInt (ut2))
627 || (exprNode_isCharLit (e2) && ctype_isInt (ut1)))
629 hcode = FLG_CHARINTLITERAL;
631 else if ((exprNode_isNumLit (e1) && ctype_isReal (ut2))
632 || (exprNode_isNumLit (e2) && ctype_isReal (ut1)))
634 hcode = FLG_NUMLITERAL;
636 else if ((ctype_isManifestBool (ut1) && ctype_isInt (ut2))
637 || (ctype_isInt (ut1) && ctype_isManifestBool (ut2)))
638 /* evs 2000-07-24: was ctype_isDirectBool */
642 else if (((ctype_isChar (ut1) && !ctype_isInt (ut1)) && ctype_isInt (ut2))
643 || ((ctype_isInt (ut1) && (ctype_isChar (ut2) && !ctype_isInt (ut2)))))
647 else if ((ctype_isInt (ut1) && ctype_isInt (ut2))
648 || (ctype_isChar (ut1) && ctype_isChar (ut2))
649 || (ctype_isDouble (ut1) && ctype_isDouble (ut2)))
651 if (!bool_equal (ctype_isSigned (ut1), ctype_isSigned (ut2)))
653 hcode = FLG_IGNORESIGNS;
657 hcode = FLG_IGNOREQUALS;
660 else if (ctype_isArbitraryIntegral (ctype_realType (ut1)))
662 if (ctype_isArbitraryIntegral (ctype_realType (ut2)))
664 hcode = FLG_MATCHANYINTEGRAL;
666 else if (ctype_match (ut2, ctype_ulint))
668 hcode = FLG_LONGUNSIGNEDINTEGRAL;
670 else if (ctype_match (ut2, ctype_lint))
672 hcode = FLG_LONGINTEGRAL;
674 else if (ctype_isInt (ut2))
676 hcode = FLG_MATCHANYINTEGRAL;
683 else if (ctype_isArbitraryIntegral (ctype_realType (ut2)))
685 ctype tr = ctype_realType (ut1);
687 if (ctype_isArbitraryIntegral (tr))
689 hcode = FLG_MATCHANYINTEGRAL;
691 else if (ctype_match (ut1, ctype_ulint))
693 if (ctype_isUnsignedIntegral (tr))
695 hcode = FLG_LONGUNSIGNEDUNSIGNEDINTEGRAL;
697 else if (ctype_isSignedIntegral (tr))
703 hcode = FLG_LONGUNSIGNEDINTEGRAL;
706 else if (ctype_match (ut1, ctype_lint))
708 if (ctype_isSignedIntegral (tr))
710 hcode = FLG_LONGSIGNEDINTEGRAL;
712 else if (ctype_isSignedIntegral (tr))
718 hcode = FLG_LONGINTEGRAL;
721 else if (ctype_isInt (ut1))
723 hcode = FLG_MATCHANYINTEGRAL;
735 if (hcode == INVALID_FLAG)
737 DPRINTF (("[%s] %s - %s / %s",
739 bool_unparse (ctype_isEnum (ut1)),
740 bool_unparse (ctype_isEnum (ctype_realType (ut1))),
741 bool_unparse (ctype_isInt (ut2))));
743 if (ctype_isAbstract (ut1) && !ctype_isAbstract (ut2))
745 uentry ue1 = usymtab_getTypeEntry (ctype_typeId (ut1));
746 ctype ct = uentry_getType (ue1);
748 if (ctype_match (ct, ut2))
751 hint = message ("Underlying types match, but %s is an "
752 "abstract type that is not accessible here.",
756 else if (ctype_isAbstract (ut2) && !ctype_isAbstract (ut1))
758 uentry ue = usymtab_getTypeEntry (ctype_typeId (ut2));
759 ctype ct = uentry_getType (ue);
761 if (ctype_match (ct, ut1))
764 hint = message ("Underlying types match, but %s is an "
765 "abstract type that is not accessible here.",
771 ; /* Not an abstract mismatch. */
775 if (hcode == INVALID_FLAG)
777 if ((ctype_isEnum (ut1) && ctype_isInt (ut2))
778 || (ctype_isEnum (ut2) && ctype_isInt (ut1)))
782 else if ((ctype_isEnum (ut1) && ctype_isInt (ut2))
783 || (ctype_isEnum (ut2) && ctype_isInt (ut1)))
787 else if ((ctype_isSignedChar (ut1) && ctype_isUnsignedChar (ut2))
788 || (ctype_isUnsignedChar (ut1) && ctype_isSignedChar (ut2)))
790 hcode = FLG_CHARUNSIGNEDCHAR;
792 else if (ctype_isNumeric (ut1) && ctype_isNumeric (ut2))
794 hcode = FLG_RELAXTYPES;
795 DPRINTF (("Setting relax types!"));
799 DPRINTF (("No special type rule: %s / %s", ctype_unparse (ut1),
800 ctype_unparse (ut2)));
805 if (cstring_isDefined (hint))
807 if (!context_suppressFlagMsg (ocode, fl))
809 return llgenhinterror (code, s, hint, fl);
820 if (llgenerroraux (srcFile, srcLine, s, fl, TRUE, FALSE))
822 if (hcode != INVALID_FLAG && hcode != ocode)
830 llsuppresshint ('-', code);
833 flagcode_recordError (code);
842 xllgentypeerror (char *srcFile, int srcLine,
843 ctype t1, exprNode e1, ctype t2, exprNode e2,
844 /*@only@*/ cstring s, fileloc fl)
846 return llgentypeerroraux (srcFile, srcLine, FLG_TYPE, t1, e1, t2, e2, s, fl);
850 xllgenformattypeerror (char *srcFile, int srcLine,
851 ctype t1, exprNode e1, ctype t2, exprNode e2,
852 /*@only@*/ cstring s, fileloc fl)
854 if (!context_suppressFlagMsg (FLG_FORMATTYPE, fl))
856 return llgentypeerroraux (srcFile, srcLine, FLG_FORMATTYPE, t1, e1, t2, e2, s, fl);
866 xllgenerror (char *srcFile, int srcLine, flagcode o, /*@only@*/ cstring s, fileloc fl)
868 if (llgenerroraux (srcFile, srcLine, s, fl, TRUE, FALSE))
870 llnosuppresshint (o);
871 flagcode_recordError (o);
877 flagcode_recordSuppressed (o);
883 xllgenhinterror (char *srcFile, int srcLine,
884 flagcode o, /*@only@*/ cstring s, /*@only@*/ cstring hint,
887 if (!context_suppressFlagMsg (o, fl))
889 if (llgenerroraux (srcFile, srcLine, s, fl, TRUE, FALSE))
891 flagcode_recordError (o);
893 if (context_getFlag (FLG_HINTS))
914 flagcode_recordSuppressed (o);
919 llrealerror (char *srcFile, int srcLine, /*@only@*/ cstring s, fileloc fl)
921 return (llgenerrorreal (srcFile, srcLine, s, fl, TRUE, FALSE));
925 llgenerroraux (char *srcFile, int srcLine,
926 /*@only@*/ cstring s, fileloc fl, bool iserror, bool indent)
928 if (context_inSuppressZone (fl))
934 if (llgenerrorreal (srcFile, srcLine, s, fl, iserror, indent)) {
942 xllforceerror (char *srcFile, int srcLine,
943 flagcode code, /*@only@*/ cstring s, fileloc fl)
945 flagcode_recordError (code);
947 if (llgenerrorreal (srcFile, srcLine, s, fl, TRUE, FALSE)) {
956 llgenerrorreal (char *srcFile, int srcLine,
957 /*@only@*/ cstring s, fileloc fl, bool iserror, bool indent)
961 /* duplicate message (rescanning a header file */
963 if (!messageLog_add (context_messageLog (), fl, s))
965 DPRINTF (("Duplicate message suppressed! %s / %s",
966 fileloc_unparse (fl), s));
972 ** If herald has not been displayed, display it before the first message.
977 if (iserror) context_hasError ();
979 if (context_unlimitedMessages ())
986 ** suppress excessive messages:
991 char *sc = cstring_toCharsSafe (s);
992 char *tmpmsg = strchr (sc, ':');
1000 char *savechar = tmpmsg;
1006 if (cstring_equal (lastmsg, cstring_fromChars (tmpmsg)))
1009 if (mcount == (context_getLimit () + 1))
1011 limitmessage (s, fl);
1015 if (mcount > (context_getLimit ()))
1025 cstring_free (lastmsg);
1026 lastmsg = cstring_fromCharsNew (tmpmsg);
1030 DPRINTF (("Here..."));
1032 if (context_hasAliasAnnote ())
1034 char *sc = cstring_toCharsSafe (s);
1035 char *fcolon = strchr (sc, ':');
1036 cstring a = context_getAliasAnnote ();
1041 s = message ("%q (%q)", s, a);
1048 afterColon = cstring_fromCharsNew (fcolon + 1);
1050 s = message ("%q (%q):%q", s, a, afterColon);
1054 if (context_hasMessageAnnote ())
1056 char *fcolon = strchr (cstring_toCharsSafe (s), ':');
1061 /*@-dependenttrans@*/ /* s becomes dependent for fcolon */
1062 s = message ("%q (%q)", s, context_getMessageAnnote ());
1063 /*@=dependenttrans@*/
1070 afterColon = cstring_fromCharsNew (fcolon + 1);
1072 /*@-dependenttrans@*/ /* s becomes dependent for fcolon */
1073 s = message ("%q (%q):%q", s,
1074 context_getMessageAnnote (), afterColon);
1075 /*@=dependenttrans@*/
1079 context_setNeednl ();
1082 if (context_showFunction ())
1084 cstring fname = fileloc_unparseFilename (g_currentloc);
1086 if (context_inIterDef ())
1088 fprintf (g_msgstream, "%s: (in iter %s)\n",
1089 cstring_toCharsSafe (fname),
1090 cstring_toCharsSafe (context_inFunctionName ()));
1092 else if (context_inIterEnd ())
1094 fprintf (g_msgstream, "%s: (in iter finalizer %s)\n",
1095 cstring_toCharsSafe (fname),
1096 cstring_toCharsSafe (context_inFunctionName ()));
1098 else if (context_inMacro ())
1100 fprintf (g_msgstream, "%s: (in macro %s)\n", cstring_toCharsSafe (fname),
1101 cstring_toCharsSafe (context_inFunctionName ()));
1105 fprintf (g_msgstream, "%s: (in function %s)\n",
1106 cstring_toCharsSafe (fname),
1107 cstring_toCharsSafe (context_inFunctionName ()));
1110 cstring_free (fname);
1111 context_setShownFunction ();
1114 flstring = fileloc_unparse (fl);
1115 lastfileloclen = cstring_length (flstring);
1119 printError (g_msgstream, message (" %q: %q", flstring, s));
1123 printError (g_msgstream, message ("%q: %q", flstring, s));
1126 showSourceLoc (srcFile, srcLine);
1133 ** message contains no '\n'
1134 ** message fits in one line: print it
1135 ** message fits in two lines with 3-space indent after fileloc: print it
1136 ** split line with 5-space indent from left margin: print it
1141 void printMessage (FILE *stream, /*@only@*/ cstring s)
1143 printIndentMessage (stream, s, 0);
1147 void printIndentMessage (FILE *stream, /*@only@*/ cstring sc, int indent)
1149 static bool inbody = FALSE;
1150 int maxlen = context_getLineLen ();
1151 char *s = cstring_toCharsSafe (sc);
1154 llassertprotect (!inbody);
1162 llassertprotect (st != olds);
1164 mstring_split (&st, &t, maxlen, &indent);
1165 fprintf (stream, "%s\n", st);
1166 llassertprotect (t != s);
1168 } while (s != NULL) ;
1175 void printError (FILE *stream, /*@only@*/ cstring sc)
1177 int maxlen = context_getLineLen ();
1178 int nspaces = lastfileloclen + 5;
1179 int nextlen = maxlen - nspaces;
1180 int len = cstring_length (sc);
1182 char *s = cstring_toCharsSafe (sc);
1186 DPRINTF (("Print error: [%s]", sc));
1188 if (len < (maxlen + nextlen) && (strchr (s, '\n') == NULL))
1190 mstring_split (&s, &t, maxlen, &indent);
1192 fprintf (stream, "%s\n", s);
1196 len = mstring_length (t);
1198 if (len < (maxlen - 3) && (strchr (t, '\n') == NULL)
1199 && len > (nextlen - 1))
1201 fprintf (stream, " %s\n", t);
1205 char *spaces = (char *) dmalloc ((nspaces + 1) * sizeof (*spaces));
1208 for (i = 0; i < nspaces; i++)
1213 spaces[nspaces] = '\0';
1218 mstring_split (&st, &t, nextlen, &indent);
1219 fprintf (stream, "%s%s\n", spaces, st);
1228 DPRINTF (("Here 1: [%s]", sc));
1230 if (len < (maxlen + maxlen - 1) && (strchr (s, '\n') != NULL))
1232 nspaces = ((maxlen + maxlen - 1) - len) / 2;
1234 if (nspaces < 1) nspaces = 1;
1236 nextlen = maxlen - nspaces;
1238 mstring_split (&s, &t, maxlen, &indent);
1240 fprintf (stream, "%s\n", s);
1244 char *spaces = (char *) dmalloc ((nspaces + 1) * sizeof (*spaces));
1247 for (i = 0; i < nspaces; i++)
1252 spaces[nspaces] = '\0';
1258 mstring_split (&st, &t, nextlen, &indent);
1259 fprintf (stream, "%s%s\n", spaces, st);
1268 nextlen = maxlen - nspaces;
1270 DPRINTF (("Here 2: [%s]", s));
1271 mstring_split (&s, &t, maxlen, &indent);
1272 DPRINTF (("Here 3: [%s] [%s]", s, t));
1274 fprintf (stream, "%s\n", s);
1278 char *spaces = (char *) dmalloc ((nspaces + 1) * sizeof (*spaces));
1281 for (i = 0; i < nspaces; i++)
1286 spaces[nspaces] = '\0';
1291 DPRINTF (("Loop: [%s]", t));
1292 mstring_split (&st, &t, nextlen, &indent);
1293 DPRINTF (("Split: [%s] [%s]", st, t));
1294 fprintf (stream, "%s%s\n", spaces, st);
1295 DPRINTF (("Next..."));
1308 xllfatalbug (char *srcFile, int srcLine, /*@only@*/ cstring s)
1311 printError (stderr, message ("%q: *** Fatal bug: %q",
1312 fileloc_unparse (g_currentloc), s));
1313 showSourceLoc (srcFile, srcLine);
1321 lclfatalbug (char *msg)
1325 message ("*** Fatal Bug: %s", cstring_fromChars (msg)));
1333 checkParseError (void)
1335 if (fileloc_withinLines (lastparseerror, g_currentloc, 10))
1337 llfatalerror (message ("%q: Cannot recover from parse error.",
1338 fileloc_unparse (g_currentloc)));
1342 void llbugaux (cstring file, int line, /*@only@*/ cstring s)
1345 static int numbugs = 0;
1346 static bool inbug = FALSE;
1350 cstring temps = fileloc_unparseRaw (file, line);
1352 fprintf (stderr, "%s: Recursive bug detected: %s\n",
1353 cstring_toCharsSafe (temps),
1354 cstring_toCharsSafe (s));
1355 cstring_free (temps);
1366 if (fileloc_isRealLib (g_currentloc))
1368 DPRINTF (("Here we are!"));
1369 llfatalerror (message ("%q: Library file appears to be corrupted. Error: %q: %s",
1370 fileloc_unparse (g_currentloc),
1371 fileloc_unparseRaw (file, line),
1376 if (fileloc_withinLines (lastparseerror, g_currentloc, 7))
1378 llfatalerror (message ("%q: Cannot recover from parse error.",
1379 fileloc_unparse (g_currentloc)));
1382 (void) fflush (g_msgstream);
1384 printError (stderr, message ("%q: *** Internal Bug at %q: %q [errno: %d]",
1385 fileloc_unparse (g_currentloc),
1386 fileloc_unparseRaw (file, line),
1390 (void) fflush (stderr);
1393 perror ("Possible system error diagnostic: ");
1395 (void) fflush (stderr);
1401 if (numbugs > context_getBugsLimit () && fileloc_withinLines (lastbug, g_currentloc, 2))
1403 llfatalerror (message ("%q: Cannot recover from last bug. (If you really want Splint to try to continue, use -bugslimit <n>.)",
1404 fileloc_unparse (g_currentloc)));
1407 fprintf (stderr, " (attempting to continue, results may be incorrect)\n");
1408 fileloc_free (lastbug);
1409 lastbug = fileloc_copy (g_currentloc);
1412 (void) fflush (stderr);
1418 lclbug (/*@only@*/ cstring s)
1421 printError (stderr, message ("*** Internal Bug: %q", s));
1424 fprintf (stderr, " (attempting to continue, results may be incorrect)\n");
1430 llfatalerror (cstring s)
1433 printError (stderr, s);
1434 printError (stderr, cstring_makeLiteral ("*** Cannot continue."));
1439 llfatalerrorLoc (/*@only@*/ cstring s)
1442 (void) fflush (g_msgstream);
1443 printError (stderr, message ("%q: %q", fileloc_unparse (g_currentloc), s));
1444 printError (stderr, cstring_makeLiteral ("*** Cannot continue."));
1445 (void) fflush (g_msgstream);
1453 return (lclerrors > 0);
1457 lclHadNewError (void)
1459 static int lastcall = 0;
1461 if (lclerrors > lastcall)
1463 lastcall = lclerrors;
1473 lclNumberErrors (void)
1479 xlclerror (char *srcFile, int srcLine, ltoken t, /*@only@*/ cstring msg)
1483 if (ltoken_getCode (t) != NOTTOKEN)
1485 cstring loc = ltoken_unparseLoc (t);
1487 lastfileloclen = cstring_length (loc);
1489 printError (g_msgstream, message ("%q: %q", loc, msg));
1490 showSourceLoc (srcFile, srcLine);
1494 printError (g_msgstream, msg);
1495 showSourceLoc (srcFile, srcLine);
1500 lclplainerror (/*@only@*/ cstring msg)
1504 printError (g_msgstream, msg);
1508 lclfatalerror (ltoken t, /*@only@*/ cstring msg)
1511 (void) fflush (g_msgstream);
1512 printError (stderr, cstring_makeLiteral ("*** Cannot continue"));
1517 lclplainfatalerror (/*@only@*/ cstring msg)
1519 (void) fflush (g_msgstream);
1520 printError (stderr, message ("*** Cannot continue: %q", msg));
1525 lclRedeclarationError (ltoken id)
1527 cstring s = ltoken_getRawString (id);
1530 if (usymtab_existsEither (s))
1532 uentry le = usymtab_lookupEither (s);
1534 lclerror (id, message ("Respecification of %s", s));
1535 llgenindentmsg (message ("Previous specification of %q",
1536 uentry_getName (le)),
1537 uentry_whereSpecified (le));
1541 lclerror (id, message ("Identifier redeclared: %s", s));
1546 void genppllerror (flagcode code, /*@only@*/ cstring s)
1548 if (context_inSuppressZone (g_currentloc))
1554 if (context_getFlag (code))
1556 if (context_getFlag (FLG_SHOWSCAN) && !context_isInCommandLine ())
1558 fprintf (g_msgstream, " >\n");
1563 if (code != FLG_PREPROC)
1565 llsuppresshint ('-', code);
1568 if (context_getFlag (FLG_SHOWSCAN) && !context_isInCommandLine ())
1570 fprintf (stderr, "< more preprocessing .");
1580 void genppllerrorhint (flagcode code, /*@only@*/ cstring s,
1581 /*@only@*/ cstring hint)
1583 if (context_inSuppressZone (g_currentloc))
1586 cstring_free (hint);
1590 if (context_getFlag (code))
1593 context_clearPreprocessing ();
1596 context_setPreprocessing ();
1602 cstring_free (hint);
1607 void ppllerror (/*@only@*/ cstring s)
1609 genppllerror (FLG_PREPROC, s);
1612 void pplldiagmsg (cstring s)
1614 if (context_getDebug (FLG_SHOWSCAN) && !context_isInCommandLine ())
1616 fprintf (stderr, " >\n");
1618 fprintf (stderr, "< more preprocessing .");
1626 void loadllmsg (cstring s)
1628 if (context_getDebug (FLG_SHOWSCAN))
1630 fprintf (stderr, " >\n");
1632 fprintf (stderr, "< .");
1640 static void llreportparseerror (/*@only@*/ cstring s)
1642 if (fileloc_withinLines (lastparseerror, g_currentloc, 5))
1648 llerror (FLG_SYNTAX, s);
1650 fileloc_free (lastparseerror);
1651 lastparseerror = fileloc_copy (g_currentloc);
1655 bool xcppoptgenerror (char *srcFile, int srcLine,
1657 /*@only@*/ cstring s,
1661 fileloc loc = cppReader_getLoc (pfile);
1663 if (context_flagOn (o, loc))
1665 if (xlloptgenerror (srcFile, srcLine, o, s, loc))
1667 cppReader_printContainingFiles (pfile);
1681 bool xlloptgenerror (char *srcFile, int srcLine,
1682 flagcode o, /*@only@*/ cstring s, fileloc loc)
1684 DPRINTF (("xllopt: %s", s));
1686 if (llrealerror (srcFile, srcLine, s, loc))
1688 DPRINTF (("Here we are!"));
1689 llsuppresshint ('-', o);
1691 flagcode_recordError (o);
1696 DPRINTF (("Suppressed!"));
1697 flagcode_recordSuppressed (o);
1702 bool xoptgenerror2 (char *srcFile, int srcLine,
1703 flagcode f1, flagcode f2, /*@only@*/ cstring s, fileloc loc)
1705 if (context_suppressFlagMsg (f1, loc))
1707 flagcode_recordSuppressed (f1);
1712 if (context_suppressFlagMsg (f2, loc))
1714 flagcode_recordSuppressed (f2);
1719 if (llrealerror (srcFile, srcLine, s, loc))
1721 llsuppresshint2 ('-', f1, f2);
1722 flagcode_recordError (f2);
1728 flagcode_recordSuppressed (f2);
1736 bool xoptgenerror2n (char *srcFile, int srcLine,
1737 flagcode f1, flagcode f2, /*@only@*/ cstring s, fileloc loc)
1740 if (context_suppressFlagMsg (f1, loc))
1742 flagcode_recordSuppressed (f1);
1747 if (context_suppressNotFlagMsg (f2, loc))
1749 flagcode_recordSuppressed (f2);
1754 if (llrealerror (srcFile, srcLine, s, loc))
1756 llsuppresshint ('+', f2);
1757 flagcode_recordError (f2);
1762 flagcode_recordSuppressed (f2);
1768 bool xllnoptgenerror (char *srcFile, int srcLine,
1769 flagcode o, /*@only@*/ cstring s, fileloc loc)
1771 if (llrealerror (srcFile, srcLine, s, loc))
1773 llsuppresshint ('+', o);
1774 flagcode_recordError (o);
1779 flagcode_recordSuppressed (o);
1783 void llparseerror (cstring s)
1785 if (context_getFlag (FLG_TRYTORECOVER))
1789 if (parseerrorcount > GIVEUPPARSE)
1791 if (cstring_isDefined (s))
1793 llfatalerror (message ("%q: Parse Error: %q. "
1794 "Too many errors, giving up.",
1795 fileloc_unparse (g_currentloc), s));
1799 llfatalerror (message ("%q: Parse Error. Too many errors, giving up.",
1800 fileloc_unparse (g_currentloc)));
1805 if (cstring_isDefined (s))
1807 llreportparseerror (message ("Parse Error: %q. Attempting to continue.",
1812 llreportparseerror (message ("Parse Error. Attempting to continue."));
1820 if (cstring_isDefined (s))
1822 msg = message ("Parse Error: %q.", s);
1826 msg = message ("Parse Error.");
1830 (message ("%q: %s (For help on parse errors, "
1831 "see splint -help parseerrors.)",
1832 fileloc_unparse (g_currentloc), msg));
1836 bool xfsgenerror (char *srcFile, int srcLine,
1837 flagSpec fs, /*@only@*/ cstring s, fileloc fl)
1839 if (flagSpec_isOn (fs, fl))
1841 if (llgenerroraux (srcFile, srcLine, s, fl, TRUE, FALSE))
1843 llsuppresshint ('-', flagSpec_getFirstOn (fs, fl));
1844 flagcode_recordError (flagSpec_getFirstOn (fs, fl));
1849 flagcode_recordSuppressed (flagSpec_getFirstOn (fs, fl));
1855 flagcode_recordSuppressed (flagSpec_getDominant (fs));
1861 bool doCheck (bool x, cstring pred, cstring file, int line)
1864 llbug (message ("%q: Check Failed: %s",
1865 fileloc_unparseRaw (file, line),
1872 /*@observer@*/ cstring lldecodeerror (/*@unused@*/ int errnum)
1877 #ifndef HAVE_STRERROR
1880 result = strerror (errnum);
1883 /* VAXCRTL's strerror() takes an optional second argument, which only
1884 matters when the first argument is EVMSERR. However, it's simplest
1885 just to pass it unconditionally. `vaxc$errno' is declared in
1886 <errno.h>, and maintained by the library in parallel with `errno'.
1887 We assume that caller's `errnum' either matches the last setting of
1888 `errno' by the library or else does not have the value `EVMSERR'. */
1890 result = strerror (errnum, vaxc$errno);
1895 result = cstring_toCharsSafe (message ("undocumented I/O error: %d", errnum));
1898 return cstring_fromChars (result);
1901 void llquietbugaux (cstring s, /*@unused@*/ cstring file, /*@unused@*/ int line)
1906 printError (stderr, message ("%q: *** Internal Bug at %q: %q [errno: %d]",
1907 fileloc_unparse (g_currentloc),
1908 fileloc_unparseRaw (file, line),
1920 (void) fflush (g_msgstream);
1921 (void) fflush (stderr);