Просмотр исходного кода

cmRpt.c: _cmVOut() now uses a dynamically allocated buffer on long messages.

master
kevin 11 лет назад
Родитель
Сommit
bfcbe9f1fd
1 измененных файлов: 26 добавлений и 6 удалений
  1. 26
    6
      cmRpt.c

+ 26
- 6
cmRpt.c Просмотреть файл

1
 #include "cmPrefix.h"
1
 #include "cmPrefix.h"
2
 #include "cmGlobal.h"
2
 #include "cmGlobal.h"
3
 #include "cmRpt.h"
3
 #include "cmRpt.h"
4
+#include "cmErr.h"
5
+#include "cmCtx.h"
6
+#include "cmMem.h"
7
+#include "cmMallocDebug.h"
4
 
8
 
5
 cmRpt_t cmRptNull = { NULL, NULL, NULL };
9
 cmRpt_t cmRptNull = { NULL, NULL, NULL };
6
 
10
 
26
 
30
 
27
 void _cmVOut( cmRptPrintFunc_t printFunc, void* userData, const cmChar_t* fmt, va_list vl )
31
 void _cmVOut( cmRptPrintFunc_t printFunc, void* userData, const cmChar_t* fmt, va_list vl )
28
 {
32
 {
29
-  unsigned bufN = 511;
30
- 
31
-  cmChar_t buf[bufN+1];
32
-  buf[0]=0;
33
+  va_list vl1;
34
+  va_copy(vl1,vl);
35
+  unsigned  n    = vsnprintf(NULL,0,fmt,vl1);
36
+  va_end(vl1);
37
+
38
+  unsigned  bufN = 511;
39
+  cmChar_t  buf[bufN+1];
40
+  cmChar_t* b    = buf;
41
+  unsigned  bn   = bufN;
42
+
43
+  if( n > bufN )
44
+  {
45
+    b  = cmMemAllocZ(cmChar_t,n+1); 
46
+    bn = n;
47
+  }
48
+
49
+  b[0]=0;
33
   if( fmt != NULL )
50
   if( fmt != NULL )
34
-    if( vsnprintf(buf,bufN,fmt,vl) > bufN )
51
+    if( vsnprintf(b,bn,fmt,vl) > bn )
35
     _cmOut(printFunc,userData,"The following error message was truncated because the character buffer in cmRpt::_cmVOut() was too small.");
52
     _cmOut(printFunc,userData,"The following error message was truncated because the character buffer in cmRpt::_cmVOut() was too small.");
36
 
53
 
37
-  _cmOut(printFunc,userData,buf);
54
+  _cmOut(printFunc,userData,b);
55
+
56
+  if( n > bufN )
57
+    cmMemFree(b);
38
 }
58
 }
39
 
59
 
40
 void cmRptSetup( cmRpt_t* rpt, cmRptPrintFunc_t printFunc, cmRptPrintFunc_t errorFunc, void* userPtr )
60
 void cmRptSetup( cmRpt_t* rpt, cmRptPrintFunc_t printFunc, cmRptPrintFunc_t errorFunc, void* userPtr )

Загрузка…
Отмена
Сохранить