]> xenbits.xensource.com Git - libvirt.git/commitdiff
logging: always NUL-terminate circular buffer
authorEric Blake <eblake@redhat.com>
Wed, 23 Mar 2011 19:23:59 +0000 (13:23 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 28 Mar 2011 16:14:06 +0000 (10:14 -0600)
* src/util/logging.c (virLogStartup, virLogSetBufferSize):
Over-allocate, so that a debugger can just print the circular
buffer.  Suggested by Daniel Veillard.

src/util/logging.c

index f4910ad945fbfe2216b45139b33cae2f7099f68b..48c0cfd4b4d010ea1cd669a3223ee64871b3434b 100644 (file)
@@ -197,14 +197,14 @@ int virLogStartup(void) {
 
     virLogInitialized = 1;
     virLogLock();
-    if (VIR_ALLOC_N(virLogBuffer, virLogSize) < 0) {
+    if (VIR_ALLOC_N(virLogBuffer, virLogSize + 1) < 0) {
         /*
          * The debug buffer is not a critical component, allow startup
          * even in case of failure to allocate it in case of a
          * configuration mistake.
          */
         virLogSize = 64 * 1024;
-        if (VIR_ALLOC_N(virLogBuffer, virLogSize) < 0) {
+        if (VIR_ALLOC_N(virLogBuffer, virLogSize + 1) < 0) {
             pbm = "Failed to allocate debug buffer: deactivating debug log\n";
             virLogSize = 0;
         } else {
@@ -249,14 +249,14 @@ virLogSetBufferSize(int size) {
     oldsize = virLogSize;
     oldLogBuffer = virLogBuffer;
 
-    if (INT_MAX / 1024 < size) {
+    if (INT_MAX / 1024 <= size) {
         pbm = "Requested log size of %d kB too large\n";
         ret = -1;
         goto error;
     }
 
     virLogSize = size * 1024;
-    if (VIR_ALLOC_N(virLogBuffer, virLogSize) < 0) {
+    if (VIR_ALLOC_N(virLogBuffer, virLogSize + 1) < 0) {
         pbm = "Failed to allocate debug buffer of %d kB\n";
         virLogBuffer = oldLogBuffer;
         virLogSize = oldsize;