aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-09-18 19:24:17 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-09-18 19:40:29 +0200
commit2b915a42f6665b4110338cfde30eedc55abe7f3c (patch)
treedbac58734abd79891e54a0903021a9e606ef012e
parent3be3213d2f76e2968d4854cfb11cecd0b5360129 (diff)
downloadcforum-2b915a42f6665b4110338cfde30eedc55abe7f3c.tar.gz
mktpl: Limit string literals to 509 characters (C89)
-rw-r--r--mktpl/mktpl.lex12
1 files changed, 10 insertions, 2 deletions
diff --git a/mktpl/mktpl.lex b/mktpl/mktpl.lex
index f0674b7..e184c0e 100644
--- a/mktpl/mktpl.lex
+++ b/mktpl/mktpl.lex
@@ -65,12 +65,20 @@ eval()
void
text()
{
- int i;
+ int i, ofs;
if(!len) return;
printf("printf(\"");
- for(i = 0; i < len; i++){
+ for(i = ofs = 0; i < len; i++){
+ /*
+ * C89 compilers need only support 509-length
+ * string literals.
+ */
+ if(i-ofs >= 509){
+ printf("\");\nprintf(\"");
+ ofs = i;
+ }
if(buf[i] == '\\') printf("\\\\");
else if(buf[i] == '"') printf("\\\"");
else if(buf[i] == '\n') printf("\\n");