[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bison message counters silently wrap around; return from 'main'
From: |
Paul Eggert |
Subject: |
Bison message counters silently wrap around; return from 'main' |
Date: |
Mon, 21 Oct 2002 21:58:37 -0700 (PDT) |
Bison returns nonzero from "main", but this doesn't work on some older
hosts. I also noticed that the Bison error message counters silently
wrap around when overflowing, but they are only used as booleans so
they might as well be bool. I installed this patch.
2002-10-21 Paul Eggert <address@hidden>
* src/complain.c (warning_issued): Renamed from warn_message_count,
so that we needn't worry about integer overflow (!).
Now of type bool. All uses changed.
(complaint_issued): Renamed from complain_message_count; likewise.
* src/main.c (main): Use exit to exit with failure.
Index: src/complain.c
===================================================================
RCS file: /cvsroot/bison/bison/src/complain.c,v
retrieving revision 1.14
diff -p -u -r1.14 complain.c
--- src/complain.c 21 Oct 2002 05:28:16 -0000 1.14
+++ src/complain.c 22 Oct 2002 04:31:39 -0000
@@ -83,11 +83,11 @@ private_strerror (int errnum)
# endif /* HAVE_STRERROR */
#endif /* not _LIBC */
-/* This variable is incremented each time `warn' is called. */
-unsigned int warn_message_count;
+/* This variable is set each time `warn' is called. */
+bool warning_issued;
-/* This variable is incremented each time `complain' is called. */
-unsigned int complain_message_count;
+/* This variable is set each time `complain' is called. */
+bool complaint_issued;
/*--------------------------------.
@@ -108,7 +108,7 @@ warn_at (location_t location, const char
vfprintf (stderr, message, args);
va_end (args);
- ++warn_message_count;
+ warning_issued = true;
putc ('\n', stderr);
fflush (stderr);
}
@@ -125,7 +125,7 @@ warn (const char *message, ...)
vfprintf (stderr, message, args);
va_end (args);
- ++warn_message_count;
+ warning_issued = true;
putc ('\n', stderr);
fflush (stderr);
}
@@ -147,7 +147,7 @@ complain_at (location_t location, const
vfprintf (stderr, message, args);
va_end (args);
- ++complain_message_count;
+ complaint_issued = true;
putc ('\n', stderr);
fflush (stderr);
}
@@ -164,7 +164,7 @@ complain (const char *message, ...)
vfprintf (stderr, message, args);
va_end (args);
- ++complain_message_count;
+ complaint_issued = true;
putc ('\n', stderr);
fflush (stderr);
}
Index: src/complain.h
===================================================================
RCS file: /cvsroot/bison/bison/src/complain.h,v
retrieving revision 1.10
diff -p -u -r1.10 complain.h
--- src/complain.h 21 Oct 2002 05:28:34 -0000 1.10
+++ src/complain.h 22 Oct 2002 04:31:40 -0000
@@ -44,19 +44,19 @@ void complain_at (location_t location, c
/* Something bad happen and we die now. */
void fatal (const char *format, ...)
__attribute__ ((__format__ (__printf__, 1, 2)));
void fatal_at (location_t location, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
/* Position in the current input file. */
extern char *infile;
-/* This variable is incremented each time `warn' is called. */
-extern unsigned int warn_message_count;
+/* This variable is set each time `warn' is called. */
+extern bool warning_issued;
-/* This variable is incremented each time `complain' is called. */
-extern unsigned int complain_message_count;
+/* This variable is set each time `complain' is called. */
+extern bool complaint_issued;
# ifdef __cplusplus
}
Index: src/main.c
===================================================================
RCS file: /cvsroot/bison/bison/src/main.c,v
retrieving revision 1.70
diff -p -u -r1.70 main.c
--- src/main.c 12 Aug 2002 14:41:48 -0000 1.70
+++ src/main.c 22 Oct 2002 04:31:40 -0000
@@ -73,8 +73,8 @@ main (int argc, char *argv[])
reader ();
timevar_pop (TV_READER);
- if (complain_message_count)
+ if (complaint_issued)
exit (1);
/* Find useless nonterminals and productions and reduce the grammar. */
timevar_push (TV_REDUCE);
@@ -137,8 +137,8 @@ main (int argc, char *argv[])
/* Stop if there were errors, to avoid trashing previous output
files. */
- if (complain_message_count)
+ if (complaint_issued)
exit (1);
/* Lookaheads are no longer needed. */
timevar_push (TV_FREE);
@@ -177,5 +177,10 @@ main (int argc, char *argv[])
timevar_stop (TV_TOTAL);
timevar_print (stderr);
- return complain_message_count ? EXIT_FAILURE : EXIT_SUCCESS;
+ /* Some ancient SunOS versions exit (0) if main returns, so use
+ `exit' to exit with nonzero status. */
+ if (complaint_issued)
+ exit (EXIT_FAILURE);
+
+ return EXIT_SUCCESS;
}
Index: src/reader.c
===================================================================
RCS file: /cvsroot/bison/bison/src/reader.c,v
retrieving revision 1.212
diff -p -u -r1.212 reader.c
--- src/reader.c 17 Oct 2002 17:47:33 -0000 1.212
+++ src/reader.c 22 Oct 2002 04:31:41 -0000
@@ -507,8 +507,8 @@ reader (void)
/* If something went wrong during the parsing, don't try to
continue. */
- if (complain_message_count)
+ if (complaint_issued)
exit (1);
/* Grammar has been read. Do some checking */
if (nrules == 0)
- Bison message counters silently wrap around; return from 'main',
Paul Eggert <=