|
| 1 | +diff -wpruN --no-dereference '--exclude=*.orig' a~/template.c a/template.c |
| 2 | +--- a~/template.c 1970-01-01 00:00:00 |
| 3 | ++++ a/template.c 1970-01-01 00:00:00 |
| 4 | +@@ -192,7 +192,13 @@ tplToString(struct template *__restrict__ const pTpl, |
| 5 | + */ |
| 6 | + pTpe = pTpl->pEntryRoot; |
| 7 | + iBuf = 0; |
| 8 | +- const int extra_space = (pTpl->optFormatEscape == JSONF) ? 1 : 3; |
| 9 | ++ /* |
| 10 | ++ * We reserve one extra space for a trailing NUL. In the JSON case we |
| 11 | ++ * need to add space for an additional four characters, a potential |
| 12 | ++ * leading ", " if this is not the first value, and a trailing "}\n" if |
| 13 | ++ * it's the last. |
| 14 | ++ */ |
| 15 | ++ const int extra_space = (pTpl->optFormatEscape == JSONF) ? 1 : 5; |
| 16 | + if(pTpl->optFormatEscape == JSONF) { |
| 17 | + if(iparam->lenBuf < 2) /* we reserve one char for the final \0! */ |
| 18 | + CHKiRet(ExtendBuf(iparam, 2)); |
| 19 | +@@ -228,8 +234,8 @@ tplToString(struct template *__restrict__ const pTpl, |
| 20 | + /* got source, now copy over */ |
| 21 | + if(iLenVal > 0) { /* may be zero depending on property */ |
| 22 | + /* first, make sure buffer fits */ |
| 23 | +- if(iBuf + iLenVal + extra_space >= iparam->lenBuf) /* we reserve one char for the final \0! */ |
| 24 | +- CHKiRet(ExtendBuf(iparam, iBuf + iLenVal + 1)); |
| 25 | ++ if(iBuf + iLenVal + extra_space > iparam->lenBuf) |
| 26 | ++ CHKiRet(ExtendBuf(iparam, iBuf + iLenVal + extra_space)); |
| 27 | + |
| 28 | + if(need_comma) { |
| 29 | + memcpy(iparam->param + iBuf, ", ", 2); |
0 commit comments