diff options
author | Anas Nashif <anas.nashif@intel.com> | 2012-11-04 18:18:17 -0800 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2012-11-04 18:18:17 -0800 |
commit | 58a8c0edfa213572fd6ef7ba7705c4031d6f7928 (patch) | |
tree | 73012bd2124c90bd9db7dee490cb4e3e2f02e700 /buf.c | |
parent | 0960e23e38178233fc295c3d87760f6f8fac58bf (diff) | |
parent | b8577c30fcc6e962e341f5ab3402197cd9bb1124 (diff) | |
download | flex-58a8c0edfa213572fd6ef7ba7705c4031d6f7928.tar.gz flex-58a8c0edfa213572fd6ef7ba7705c4031d6f7928.tar.bz2 flex-58a8c0edfa213572fd6ef7ba7705c4031d6f7928.zip |
Merge commit 'upstream/2.5.37'
Diffstat (limited to 'buf.c')
-rw-r--r-- | buf.c | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -74,6 +74,8 @@ struct Buf *buf_prints (struct Buf *buf, const char *fmt, const char *s) size_t tsz; t = flex_alloc (tsz = strlen (fmt) + strlen (s) + 1); + if (!t) + flexfatal (_("Allocation of buffer to print string failed")); snprintf (t, tsz, fmt, s); buf = buf_strappend (buf, t); flex_free (t); @@ -88,11 +90,20 @@ struct Buf *buf_prints (struct Buf *buf, const char *fmt, const char *s) */ struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno) { - char *t, *fmt = "#line %d \"%s\"\n"; - size_t tsz; - - t = flex_alloc (tsz = strlen (fmt) + strlen (filename) + (int)(1 + log10(lineno>=0?lineno:-lineno)) + 1); - snprintf (t, tsz, fmt, lineno, filename); + char *dst, *src, *t; + + 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 (!t) + flexfatal (_("Allocation of buffer for line directive failed")); + for (dst = t + sprintf (t, "#line %d \"", lineno), src = filename; *src; *dst++ = *src++) + if (*src == '\\') /* escape backslashes */ + *dst++ = '\\'; + *dst++ = '"'; + *dst++ = '\n'; + *dst = '\0'; buf = buf_strappend (buf, t); flex_free (t); return buf; @@ -162,6 +173,8 @@ struct Buf *buf_m4_define (struct Buf *buf, const char* def, const char* val) val = val?val:""; str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + strlen(val) + 2); + if (!str) + flexfatal (_("Allocation of buffer for m4 def failed")); snprintf(str, strsz, fmt, def, val); buf_append(buf, &str, 1); @@ -180,6 +193,8 @@ struct Buf *buf_m4_undefine (struct Buf *buf, const char* def) size_t strsz; str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + 2); + if (!str) + flexfatal (_("Allocation of buffer for m4 undef failed")); snprintf(str, strsz, fmt, def); buf_append(buf, &str, 1); |