>From 722cb0154a4b82c522bbd04ea4209adf23a5b16c Mon Sep 17 00:00:00 2001
From: Patrick Ohly <patrick.ohly@intel.com>
Date: Mon, 17 Jan 2011 11:11:09 +0100
Subject: [PATCH] SyncML TK: adjust size of DevInf buffer dynamically

The size of the buffer into which DevInf was encoded was limited to
~12KB, regardless of which message size was configured for the actual
message.

12KB is too small for larger numbers of databases, like 15, which
caused "SmlException: SyncML Toolkit error=0x2002, smlResultsCmd,
smlerr=8194".

This patch uses a DevInf buffer size which is as large as the
remaining buffer for the actual message, or the old size (just in
case, not expected to be used anymore).
---
 src/syncml_tk/src/sml/xlt/all/xltenc.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/syncml_tk/src/sml/xlt/all/xltenc.c b/src/syncml_tk/src/sml/xlt/all/xltenc.c
index 7cbcf3d..700874b 100755
--- a/src/syncml_tk/src/sml/xlt/all/xltenc.c
+++ b/src/syncml_tk/src/sml/xlt/all/xltenc.c
@@ -1457,9 +1457,17 @@ Ret_t subdtdEncWBXML(XltTagID_t tagId, XltRO_t reqOptFlag, const VoidPtr_t pCont
     /* Double the size of SubBufSize for the memory is small for some complex
      * content.
      */ 
-    Short_t           SubBufSize   = 12000 * 2; // for starters we use 12kB for each sub DTD to encode in WBXML
+    MemSize_t         SubBufSize   = 12000 * 2; // for starters we use 12kB for each sub DTD to encode in WBXML
     BufferMgmtPtr_t   pSubBufMgr   = NULL;
 
+    /* Even the doubled size was still too small. Instead of
+       hard-coding the size, make it as large as the buffer we are
+       copying into. The size of that one can be configured by the
+       user of the toolkit. -- Patrick Ohly */
+    MemSize_t VarSubBufSize = pBufMgr->smlXltBufferLen - pBufMgr->smlXltWrittenBytes;
+    if (VarSubBufSize > SubBufSize) {
+      SubBufSize = VarSubBufSize;
+    }
 
     // first create a sub buffer
     pSubBufMgr = (BufferMgmtPtr_t)smlLibMalloc(sizeof(BufferMgmt_t));
-- 
1.7.2.3

