summaryrefslogtreecommitdiffstats
path: root/runtime/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/parser.c')
-rw-r--r--runtime/parser.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/runtime/parser.c b/runtime/parser.c
index b40edf4c..74b28f4c 100644
--- a/runtime/parser.c
+++ b/runtime/parser.c
@@ -362,11 +362,10 @@ SanitizeMsg(msg_t *pMsg)
*/
int bNeedSanitize = 0;
for(iSrc = 0 ; iSrc < lenMsg ; iSrc++) {
- if(iscntrl(pszMsg[iSrc])) {
+ if(pszMsg[iSrc] < 32) {
if(bSpaceLFOnRcv && pszMsg[iSrc] == '\n')
pszMsg[iSrc] = ' ';
- else
- if(pszMsg[iSrc] == '\0' || bEscapeCCOnRcv) {
+ else if(pszMsg[iSrc] == '\0' || bEscapeCCOnRcv) {
bNeedSanitize = 1;
if (!bSpaceLFOnRcv)
break;
@@ -383,7 +382,9 @@ SanitizeMsg(msg_t *pMsg)
FINALIZE;
}
- /* now copy over the message and sanitize it */
+ /* now copy over the message and sanitize it. Note that up to iSrc-1 there was
+ * obviously no need to sanitize, so we can go over that quickly...
+ */
iMaxLine = glbl.GetMaxLine();
maxDest = lenMsg * 4; /* message can grow at most four-fold */
if(maxDest > iMaxLine)
@@ -392,9 +393,13 @@ SanitizeMsg(msg_t *pMsg)
pDst = szSanBuf;
else
CHKmalloc(pDst = MALLOC(sizeof(uchar) * (iMaxLine + 1)));
- iSrc = iDst = 0;
+ if(iSrc > 0) {
+ iSrc--; /* go back to where everything is OK */
+ memcpy(pDst, pszMsg, iSrc); /* fast copy known good */
+ }
+ iDst = iSrc;
while(iSrc < lenMsg && iDst < maxDest - 3) { /* leave some space if last char must be escaped */
- if(iscntrl((int) pszMsg[iSrc]) && (pszMsg[iSrc] != '\t' || bEscapeTab)) {
+ if((pszMsg[iSrc] < 32) && (pszMsg[iSrc] != '\t' || bEscapeTab)) {
/* note: \0 must always be escaped, the rest of the code currently
* can not handle it! -- rgerhards, 2009-08-26
*/