diff --git a/contrib/flex/buf.c b/contrib/flex/buf.c index fa713a69da98..d6efdacee7bf 100644 --- a/contrib/flex/buf.c +++ b/contrib/flex/buf.c @@ -95,7 +95,7 @@ struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno) t = flex_alloc (strlen ("#line \"\"\n") + /* constant parts */ 2 * strlen (filename) + /* filename with possibly all backslashes escaped */ - (int) (1 + log10 (abs (lineno))) + /* line number */ + NUMCHARLINES + /* line number */ 1); /* NUL */ if (!t) flexfatal (_("Allocation of buffer for line directive failed")); diff --git a/contrib/flex/flexdef.h b/contrib/flex/flexdef.h index 1f03d5aca1ac..d37a50929aee 100644 --- a/contrib/flex/flexdef.h +++ b/contrib/flex/flexdef.h @@ -61,7 +61,6 @@ char *alloca (); #include #include #include -#include #endif #ifdef HAVE_ASSERT_H #include @@ -171,6 +170,9 @@ char *alloca (); */ #define NUMDATALINES 10 +/* Number of characters to print a line number, i.e., 1 + log10(INT_MAX) */ +#define NUMCHARLINES 10 + /* transition_struct_out() definitions. */ #define TRANS_STRUCT_PRINT_LENGTH 14 diff --git a/contrib/flex/main.c b/contrib/flex/main.c index 57b1f67ca23a..43960da5a4c6 100644 --- a/contrib/flex/main.c +++ b/contrib/flex/main.c @@ -451,7 +451,7 @@ void check_options () char *str, *fmt = "#define %s %d\n"; size_t strsz; - str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(scname[i]) + (int)(1 + log10(i)) + 2); + str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(scname[i]) + NUMCHARLINES + 2); if (!str) flexfatal(_("allocation of macro definition failed")); snprintf(str, strsz, fmt, scname[i], i - 1);