]> xenbits.xensource.com Git - libvirt.git/commitdiff
(absolutePathFromBaseFile): fix up preceding commit
authorJim Meyering <meyering@redhat.com>
Fri, 5 Feb 2010 13:57:35 +0000 (14:57 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 5 Feb 2010 14:07:17 +0000 (15:07 +0100)
When configured with --enable-gcc-warnings, it didn't even compile.
* src/util/storage_file.c: Include <assert.h>.
(absolutePathFromBaseFile): Assert that converting size_t to int is valid.
Reverse length/string args to match "%.*s".
Explicitly ignore the return value of virAsprintf.

src/util/storage_file.c

index 2c79fa9e60b1399de700346d545f3580725a914a..135acece7ef2938ca606c2fd634092f69ea5e759 100644 (file)
@@ -26,7 +26,9 @@
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <assert.h>
 #include "dirname.h"
+#include "ignore-value.h"
 #include "memory.h"
 #include "virterror_internal.h"
 
@@ -255,7 +257,10 @@ absolutePathFromBaseFile(const char *base_file, const char *path)
     if (*path == '/' || d_len == 0)
         return strdup(path);
 
-    virAsprintf(&res, "%.*s/%s", base_file, d_len, path);
+    /* Ensure that the following cast-to-int is valid.  */
+    assert (d_len <= INT_MAX);
+
+    ignore_value(virAsprintf(&res, "%.*s/%s", (int) d_len, base_file, path));
     return res;
 }