Pārlūkot izejas kodu

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

master
kevin 11 gadus atpakaļ
vecāks
revīzija
bfcbe9f1fd
1 mainītis faili ar 26 papildinājumiem un 6 dzēšanām
  1. 26
    6
      cmRpt.c

+ 26
- 6
cmRpt.c Parādīt failu

@@ -1,6 +1,10 @@
1 1
 #include "cmPrefix.h"
2 2
 #include "cmGlobal.h"
3 3
 #include "cmRpt.h"
4
+#include "cmErr.h"
5
+#include "cmCtx.h"
6
+#include "cmMem.h"
7
+#include "cmMallocDebug.h"
4 8
 
5 9
 cmRpt_t cmRptNull = { NULL, NULL, NULL };
6 10
 
@@ -26,15 +30,31 @@ void _cmOut( cmRptPrintFunc_t printFunc, void* userData, const cmChar_t* text )
26 30
 
27 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 50
   if( fmt != NULL )
34
-    if( vsnprintf(buf,bufN,fmt,vl) > bufN )
51
+    if( vsnprintf(b,bn,fmt,vl) > bn )
35 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 60
 void cmRptSetup( cmRpt_t* rpt, cmRptPrintFunc_t printFunc, cmRptPrintFunc_t errorFunc, void* userPtr )

Notiek ielāde…
Atcelt
Saglabāt