Merge lp:~vkolesnikov/pbxt/pbxt-vasprintf into lp:pbxt

Proposed by Vladimir Kolesnikov
Status: Merged
Merged at revision: 850
Proposed branch: lp:~vkolesnikov/pbxt/pbxt-vasprintf
Merge into: lp:pbxt
Diff against target: 29 lines (+8/-3)
1 file modified
src/thread_xt.cc (+8/-3)
To merge this branch: bzr merge lp:~vkolesnikov/pbxt/pbxt-vasprintf
Reviewer Review Type Date Requested Status
PBXT Core Pending
Review via email: mp+34423@code.launchpad.net

Description of the change

merged into the latest lp:pbxt

To post a comment you must log in.
Revision history for this message
Paul McCullagh (paul-mccullagh) wrote :

Hi Vlad,

I am not so sure about this now. The code no longer uses ap2. But, I think it may be required, as was done previously. I think the first call to vsnprintf() clobbers ap.

It would be good to run this code once to check that it works.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/thread_xt.cc'
2--- src/thread_xt.cc 2010-05-06 12:37:19 +0000
3+++ src/thread_xt.cc 2010-09-02 14:26:09 +0000
4@@ -203,7 +203,8 @@
5 {
6 char buffer[DEFAULT_LOG_BUFFER_SIZE];
7 char *log_string = NULL;
8-
9+ int bufsize;
10+
11 if (level > log_level)
12 return;
13
14@@ -226,9 +227,13 @@
15 va_list ap2;
16
17 va_copy(ap2, ap);
18- if (vsnprintf(buffer, DEFAULT_LOG_BUFFER_SIZE, fmt, ap) >= DEFAULT_LOG_BUFFER_SIZE) {
19- if (vasprintf(&log_string, fmt, ap2) == -1)
20+ bufsize = vsnprintf(buffer, DEFAULT_LOG_BUFFER_SIZE, fmt, ap);
21+ if (bufsize >= DEFAULT_LOG_BUFFER_SIZE) {
22+ log_string = (char *)malloc(bufsize + 1);
23+ if (vsnprintf(log_string, bufsize + 1, fmt, ap) > bufsize) {
24+ free(log_string);
25 log_string = NULL;
26+ }
27 }
28 else
29 log_string = buffer;

Subscribers

People subscribed via source and target branches