[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libvir] [PATCH] Readd buffer errors & some cleanups



This readds some error checking of the returns from virBuffer* functions, removes need for is_blank (a _GNU_SOURCE extension), and a couple of other very minor cleanups.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
Index: src/conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/conf.c,v
retrieving revision 1.10
diff -u -p -r1.10 conf.c
--- src/conf.c	26 Jun 2007 22:33:22 -0000	1.10
+++ src/conf.c	3 Jul 2007 10:40:17 -0000
@@ -883,8 +883,10 @@ __virConfWriteFile(const char *filename,
         return(-1);
 
     buf = virBufferNew(500);
-    if (buf == NULL)
+    if (buf == NULL) {
+        virConfError(NULL, VIR_ERR_NO_MEMORY, _("failed to allocate buffer"), 0);
         return(-1);
+    }
 
     cur = conf->entries;
     while (cur != NULL) {
@@ -935,8 +937,10 @@ __virConfWriteMem(char *memory, int *len
         return(-1);
 
     buf = virBufferNew(500);
-    if (buf == NULL)
+    if (buf == NULL) {
+        virConfError(NULL, VIR_ERR_NO_MEMORY, _("failed to allocate buffer"), 0);
         return(-1);
+    }
 
     cur = conf->entries;
     while (cur != NULL) {
Index: src/sexpr.c
===================================================================
RCS file: /data/cvs/libvirt/src/sexpr.c,v
retrieving revision 1.6
diff -u -p -r1.6 sexpr.c
--- src/sexpr.c	14 Feb 2007 15:40:54 -0000	1.6
+++ src/sexpr.c	3 Jul 2007 10:40:17 -0000
@@ -10,7 +10,7 @@
  *  archive for more details.
  */
 
-#define _GNU_SOURCE
+#define _GNU_SOURCE /* for strndup */
 
 #include "sexpr.h"
 #include "internal.h"
Index: src/test.c
===================================================================
RCS file: /data/cvs/libvirt/src/test.c,v
retrieving revision 1.38
diff -u -p -r1.38 test.c
--- src/test.c	26 Jun 2007 22:57:41 -0000	1.38
+++ src/test.c	3 Jul 2007 10:40:18 -0000
@@ -1389,6 +1389,7 @@ char * testDomainDumpXML(virDomainPtr do
     con = &node->connections[priv->handle];
 
     if (!(buf = virBufferNew(4000))) {
+        testError(domain->conn, domain, VIR_ERR_NO_MEMORY, __FUNCTION__);
         return (NULL);
     }
 
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.90
diff -u -p -r1.90 virsh.c
--- src/virsh.c	29 Jun 2007 13:45:50 -0000	1.90
+++ src/virsh.c	3 Jul 2007 10:40:21 -0000
@@ -13,8 +13,6 @@
  * $Id: virsh.c,v 1.90 2007/06/29 13:45:50 veillard Exp $
  */
 
-#define _GNU_SOURCE             /* isblank() */
-
 #include "libvirt/libvirt.h"
 #include "libvirt/virterror.h"
 #include <stdio.h>
@@ -3806,7 +3804,7 @@ vshCommandGetToken(vshControl * ctl, cha
 
     *end = NULL;
 
-    while (p && *p && isblank((unsigned char) *p))
+    while (p && *p && (*p == ' ' || *p == '\t'))
         p++;
 
     if (p == NULL || *p == '\0')
@@ -3817,7 +3815,7 @@ vshCommandGetToken(vshControl * ctl, cha
     }
     while (*p) {
         /* end of token is blank space or ';' */
-        if ((quote == FALSE && isblank((unsigned char) *p)) || *p == ';')
+        if ((quote == FALSE && (*p == ' ' || *p == '\t')) || *p == ';')
             break;
 
         /* end of option name could be '=' */
Index: src/xen_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_internal.c,v
retrieving revision 1.82
diff -u -p -r1.82 xen_internal.c
--- src/xen_internal.c	26 Jun 2007 22:33:22 -0000	1.82
+++ src/xen_internal.c	3 Jul 2007 10:40:22 -0000
@@ -2138,7 +2138,10 @@ xenHypervisorMakeCapabilitiesXML(virConn
 
     /* Construct the final XML. */
     xml = virBufferNew (1024);
-    if (!xml) return NULL;
+    if (!xml) {
+        virXenError(VIR_ERR_NO_MEMORY, __FUNCTION__, 0);
+        return NULL;
+    }
     r = virBufferVSprintf (xml,
                            "\
 <capabilities>\n\
@@ -2225,15 +2228,13 @@ xenHypervisorMakeCapabilitiesXML(virConn
 </capabilities>\n", -1);
     if (r == -1) goto vir_buffer_failed;
     xml_str = strdup (xml->content);
-    if (!xml_str) {
-        virXenError(VIR_ERR_NO_MEMORY, "strdup", 0);
-        goto vir_buffer_failed;
-    }
+    if (!xml_str) goto vir_buffer_failed;
     virBufferFree (xml);
 
     return xml_str;
 
  vir_buffer_failed:
+    virXenError(VIR_ERR_NO_MEMORY, __FUNCTION__, 0);
     virBufferFree (xml);
     return NULL;
 }
Index: src/xml.c
===================================================================
RCS file: /data/cvs/libvirt/src/xml.c,v
retrieving revision 1.79
diff -u -p -r1.79 xml.c
--- src/xml.c	26 Jun 2007 23:48:47 -0000	1.79
+++ src/xml.c	3 Jul 2007 10:40:27 -0000
@@ -267,10 +267,7 @@ virXPathNodeSet(const char *xpath, xmlXP
     xmlXPathFreeObject(obj);
     return(ret);
 }
-#endif /* !PROXY */
-
 
-#ifndef PROXY
 /**
  * virtDomainParseXMLGraphicsDescImage:
  * @conn: pointer to the hypervisor connection
Index: tests/Makefile.am
===================================================================
RCS file: /data/cvs/libvirt/tests/Makefile.am,v
retrieving revision 1.19
diff -u -p -r1.19 Makefile.am
--- tests/Makefile.am	29 May 2007 14:44:15 -0000	1.19
+++ tests/Makefile.am	3 Jul 2007 10:40:28 -0000
@@ -46,8 +46,8 @@ valgrind:
 xmlrpctest_SOURCES = \
 	xmlrpctest.c \
 	testutils.c testutils.h \
-	$(top_builddir)/src/xmlrpc.c \
-	$(top_builddir)/src/xmlrpc.h
+	@top_srcdir@/src/xmlrpc.c \
+	@top_srcdir@/src/xmlrpc.h
 
 xmlrpctest_LDFLAGS =
 xmlrpctest_LDADD = $(LDADDS)

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]