aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2020-03-22 13:12:35 -0700
committerMichael Forney <mforney@mforney.org>2020-03-22 13:21:21 -0700
commitcaa4368d89116077fe94191e6e3ee67b6a8b092b (patch)
tree7e5af80ed6d83f6be1fac08f372c0ac43dce4466
parented8f52d4a65d8a06aa01a247eab39e65ec5334e1 (diff)
pp: Don't add leading space for first stringized token
-rw-r--r--pp.c2
-rw-r--r--test/preprocess-macro-stringize-2.c1
-rw-r--r--test/preprocess-macro-stringize-2.pp1
3 files changed, 3 insertions, 1 deletions
diff --git a/pp.c b/pp.c
index 7f6b737..5b9258b 100644
--- a/pp.c
+++ b/pp.c
@@ -403,7 +403,7 @@ stringize(struct array *buf, struct token *t)
{
const char *lit;
- if ((t->space || t->kind == TNEWLINE) && ((char *)buf->val)[buf->len - 1] != ' ')
+ if ((t->space || t->kind == TNEWLINE) && buf->len > 1 && ((char *)buf->val)[buf->len - 1] != ' ')
arrayaddbuf(buf, " ", 1);
lit = t->lit ? t->lit : tokstr[t->kind];
if (t->kind == TSTRINGLIT || t->kind == TCHARCONST) {
diff --git a/test/preprocess-macro-stringize-2.c b/test/preprocess-macro-stringize-2.c
index 81862b6..5631883 100644
--- a/test/preprocess-macro-stringize-2.c
+++ b/test/preprocess-macro-stringize-2.c
@@ -3,3 +3,4 @@ str(@)
str(12 x- 3
abc)
str('"' "\\")
+str( abc)
diff --git a/test/preprocess-macro-stringize-2.pp b/test/preprocess-macro-stringize-2.pp
index 1dad46c..975126d 100644
--- a/test/preprocess-macro-stringize-2.pp
+++ b/test/preprocess-macro-stringize-2.pp
@@ -1,3 +1,4 @@
"@"
"12 x- 3 abc"
"'\"' \"\\\\\""
+"abc"