summaryrefslogtreecommitdiff
path: root/src/buf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buf.c')
-rw-r--r--src/buf.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/buf.c b/src/buf.c
index 6f6bd9a..2a423ef 100644
--- a/src/buf.c
+++ b/src/buf.c
@@ -93,14 +93,16 @@ struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno)
{
char *dst, *t;
const char *src;
+ size_t tsz;
- t = malloc(strlen("#line \"\"\n") + /* constant parts */
- 2 * strlen (filename) + /* filename with possibly all backslashes escaped */
- (int) (1 + log10 (abs (lineno))) + /* line number */
- 1); /* NUL */
+ 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++)
+ for (dst = t + snprintf (t, tsz, "#line %d \"", lineno), src = filename; *src; *dst++ = *src++)
if (*src == '\\') /* escape backslashes */
*dst++ = '\\';
*dst++ = '"';