summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoj Srivastava <srivasta@debian.org>2016-02-24 14:54:26 -0800
committerManoj Srivastava <srivasta@debian.org>2016-02-24 14:54:26 -0800
commit7b308a5f1652444a812ba39bce631cd895449c3a (patch)
tree33453eb329336bb57d0f826a0267874f3fc680f4
parent36e2e59881e6c5ac981242d2e28ee5ad43600a6a (diff)
parent58213fd78e208381815502c0574d8d0c1c467f85 (diff)
Merge branch 'fix-line-directives'
-rw-r--r--src/buf.c16
-rw-r--r--src/main.c3
2 files changed, 12 insertions, 7 deletions
diff --git a/src/buf.c b/src/buf.c
index fa713a6..907f4f1 100644
--- a/src/buf.c
+++ b/src/buf.c
@@ -36,13 +36,13 @@
/* Take note: The buffer object is sometimes used as a String buffer (one
* continuous string), and sometimes used as a list of strings, usually line by
* line.
- *
+ *
* The type is specified in buf_init by the elt_size. If the elt_size is
* sizeof(char), then the buffer should be treated as string buffer. If the
* elt_size is sizeof(char*), then the buffer should be treated as a list of
* strings.
*
- * Certain functions are only appropriate for one type or the other.
+ * Certain functions are only appropriate for one type or the other.
*/
/* global buffers. */
@@ -93,10 +93,14 @@ struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno)
char *dst, *t;
const char *src;
- t = flex_alloc (strlen ("#line \"\"\n") + /* constant parts */
- 2 * strlen (filename) + /* filename with possibly all backslashes escaped */
- (int) (1 + log10 (abs (lineno))) + /* line number */
- 1); /* NUL */
+ if (gen_line_dirs)
+ return buf;
+
+ tsz = strlen("#line \"\"\n") + /* constant parts */
+ 2 * strlen (filename) + /* filename with possibly all backslashes escaped */
+ (int) (1 + log10 (abs (lineno))) + /* line number */
+ 1; /* NUL */
+ t = malloc(tsz);
if (!t)
flexfatal (_("Allocation of buffer for line directive failed"));
for (dst = t + sprintf (t, "#line %d \"", lineno), src = filename; *src; *dst++ = *src++)
diff --git a/src/main.c b/src/main.c
index 8710702..336e25c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -474,7 +474,8 @@ void check_options ()
m4defs_buf.nelts = 0; /* memory leak here. */
/* Place a bogus line directive, it will be fixed in the filter. */
- outn("#line 0 \"M4_YY_OUTFILE_NAME\"\n");
+ if (gen_line_dirs)
+ outn("#line 0 \"M4_YY_OUTFILE_NAME\"\n");
/* Dump the user defined preproc directives. */
if (userdef_buf.elts)