OLD | NEW |
1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 *limit_ = '\0'; | 47 *limit_ = '\0'; |
48 } | 48 } |
49 | 49 |
50 void RawPrinter::Printf(const char* format, ...) { | 50 void RawPrinter::Printf(const char* format, ...) { |
51 if (limit_ > ptr_) { | 51 if (limit_ > ptr_) { |
52 va_list ap; | 52 va_list ap; |
53 va_start(ap, format); | 53 va_start(ap, format); |
54 int avail = limit_ - ptr_; | 54 int avail = limit_ - ptr_; |
55 // We pass avail+1 to vsnprintf() since that routine needs room | 55 // We pass avail+1 to vsnprintf() since that routine needs room |
56 // to store the trailing \0. | 56 // to store the trailing \0. |
57 const int r = vsnprintf(ptr_, avail+1, format, ap); | 57 const int r = perftools_vsnprintf(ptr_, avail+1, format, ap); |
58 va_end(ap); | 58 va_end(ap); |
59 if (r < 0) { | 59 if (r < 0) { |
60 // Perhaps an old glibc that returns -1 on truncation? | 60 // Perhaps an old glibc that returns -1 on truncation? |
61 ptr_ = limit_; | 61 ptr_ = limit_; |
62 } else if (r > avail) { | 62 } else if (r > avail) { |
63 // Truncation | 63 // Truncation |
64 ptr_ = limit_; | 64 ptr_ = limit_; |
65 } else { | 65 } else { |
66 ptr_ += r; | 66 ptr_ += r; |
67 } | 67 } |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 } | 71 } |
OLD | NEW |