c401cc
From 3872db0a227069d906614e5449833ca1d13e16c4 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <3872db0a227069d906614e5449833ca1d13e16c4@dist-git>
c401cc
From: Eric Blake <eblake@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:54:33 +0100
c401cc
Subject: [PATCH] storage: use simpler 'char *'
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
'unsigned char *' makes sense if you are doing math on bytes and
c401cc
don't want to worry about wraparound from a signed 'char'; but
c401cc
since all we are doing is memcmp() or virReadBufInt*[LB]E(), which
c401cc
are both safe on either type of char, and since read() prefers to
c401cc
operate on 'char *', it's simpler to avoid casts by just typing
c401cc
things as 'char *' from the get-go.  [Technically, read can
c401cc
operate on an 'unsigned char *' thanks to the C rule that any
c401cc
pointer can be implicitly converted to 'char *' for legacy K&R
c401cc
compatibility; but where this patch saves us is if we try to use
c401cc
virfile.h functions that take 'char **' in order to allocate the
c401cc
buffer, where the compiler would barf on type mismatch.]
c401cc
c401cc
* src/util/virstoragefile.c (FileTypeInfo): Avoid unsigned char.
c401cc
(cowGetBackingStore, qcow2GetBackingStoreFormat)
c401cc
(qcowXGetBackingStore, qcow1GetBackingStore)
c401cc
(qcow2GetBackingStore, vmdk4GetBackingStore, qedGetBackingStore)
c401cc
(virStorageFileMatchesMagic, virStorageFileMatchesVersion)
c401cc
(virStorageFileProbeFormatFromBuf, qcow2GetFeatures)
c401cc
(virStorageFileGetMetadataInternal)
c401cc
(virStorageFileProbeFormatFromFD): Simplify clients.
c401cc
c401cc
Signed-off-by: Eric Blake <eblake@redhat.com>
c401cc
(cherry picked from commit 5717ee6ab871253c3e512ece7d59b754624e99c0)
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/util/virstoragefile.c | 42 +++++++++++++++++++++---------------------
c401cc
 1 file changed, 21 insertions(+), 21 deletions(-)
c401cc
c401cc
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
c401cc
index fc8aa90..bb27461 100644
c401cc
--- a/src/util/virstoragefile.c
c401cc
+++ b/src/util/virstoragefile.c
c401cc
@@ -102,23 +102,23 @@ struct FileTypeInfo {
c401cc
                            * where to find encryption mode,
c401cc
                            * -1 if encryption is not used */
c401cc
     int (*getBackingStore)(char **res, int *format,
c401cc
-                           const unsigned char *buf, size_t buf_size);
c401cc
+                           const char *buf, size_t buf_size);
c401cc
     int (*getFeatures)(virBitmapPtr *features, int format,
c401cc
-                       unsigned char *buf, ssize_t len);
c401cc
+                       char *buf, ssize_t len);
c401cc
 };
c401cc
 
c401cc
 static int cowGetBackingStore(char **, int *,
c401cc
-                              const unsigned char *, size_t);
c401cc
+                              const char *, size_t);
c401cc
 static int qcow1GetBackingStore(char **, int *,
c401cc
-                                const unsigned char *, size_t);
c401cc
+                                const char *, size_t);
c401cc
 static int qcow2GetBackingStore(char **, int *,
c401cc
-                                const unsigned char *, size_t);
c401cc
+                                const char *, size_t);
c401cc
 static int qcow2GetFeatures(virBitmapPtr *features, int format,
c401cc
-                            unsigned char *buf, ssize_t len);
c401cc
+                            char *buf, ssize_t len);
c401cc
 static int vmdk4GetBackingStore(char **, int *,
c401cc
-                                const unsigned char *, size_t);
c401cc
+                                const char *, size_t);
c401cc
 static int
c401cc
-qedGetBackingStore(char **, int *, const unsigned char *, size_t);
c401cc
+qedGetBackingStore(char **, int *, const char *, size_t);
c401cc
 
c401cc
 #define QCOWX_HDR_VERSION (4)
c401cc
 #define QCOWX_HDR_BACKING_FILE_OFFSET (QCOWX_HDR_VERSION+4)
c401cc
@@ -252,7 +252,7 @@ verify(ARRAY_CARDINALITY(qcow2CompatibleFeatureArray) ==
c401cc
 static int
c401cc
 cowGetBackingStore(char **res,
c401cc
                    int *format,
c401cc
-                   const unsigned char *buf,
c401cc
+                   const char *buf,
c401cc
                    size_t buf_size)
c401cc
 {
c401cc
 #define COW_FILENAME_MAXLEN 1024
c401cc
@@ -274,7 +274,7 @@ cowGetBackingStore(char **res,
c401cc
 
c401cc
 static int
c401cc
 qcow2GetBackingStoreFormat(int *format,
c401cc
-                           const unsigned char *buf,
c401cc
+                           const char *buf,
c401cc
                            size_t buf_size,
c401cc
                            size_t extension_start,
c401cc
                            size_t extension_end)
c401cc
@@ -329,7 +329,7 @@ done:
c401cc
 static int
c401cc
 qcowXGetBackingStore(char **res,
c401cc
                      int *format,
c401cc
-                     const unsigned char *buf,
c401cc
+                     const char *buf,
c401cc
                      size_t buf_size,
c401cc
                      bool isQCow2)
c401cc
 {
c401cc
@@ -407,7 +407,7 @@ qcowXGetBackingStore(char **res,
c401cc
 static int
c401cc
 qcow1GetBackingStore(char **res,
c401cc
                      int *format,
c401cc
-                     const unsigned char *buf,
c401cc
+                     const char *buf,
c401cc
                      size_t buf_size)
c401cc
 {
c401cc
     int ret;
c401cc
@@ -424,7 +424,7 @@ qcow1GetBackingStore(char **res,
c401cc
 static int
c401cc
 qcow2GetBackingStore(char **res,
c401cc
                      int *format,
c401cc
-                     const unsigned char *buf,
c401cc
+                     const char *buf,
c401cc
                      size_t buf_size)
c401cc
 {
c401cc
     return qcowXGetBackingStore(res, format, buf, buf_size, true);
c401cc
@@ -434,7 +434,7 @@ qcow2GetBackingStore(char **res,
c401cc
 static int
c401cc
 vmdk4GetBackingStore(char **res,
c401cc
                      int *format,
c401cc
-                     const unsigned char *buf,
c401cc
+                     const char *buf,
c401cc
                      size_t buf_size)
c401cc
 {
c401cc
     static const char prefix[] = "parentFileNameHint=\"";
c401cc
@@ -495,7 +495,7 @@ cleanup:
c401cc
 static int
c401cc
 qedGetBackingStore(char **res,
c401cc
                    int *format,
c401cc
-                   const unsigned char *buf,
c401cc
+                   const char *buf,
c401cc
                    size_t buf_size)
c401cc
 {
c401cc
     unsigned long long flags;
c401cc
@@ -596,7 +596,7 @@ cleanup:
c401cc
 
c401cc
 static bool
c401cc
 virStorageFileMatchesMagic(int format,
c401cc
-                           unsigned char *buf,
c401cc
+                           char *buf,
c401cc
                            size_t buflen)
c401cc
 {
c401cc
     int mlen;
c401cc
@@ -634,7 +634,7 @@ virStorageFileMatchesExtension(int format,
c401cc
 
c401cc
 static bool
c401cc
 virStorageFileMatchesVersion(int format,
c401cc
-                             unsigned char *buf,
c401cc
+                             char *buf,
c401cc
                              size_t buflen)
c401cc
 {
c401cc
     int version;
c401cc
@@ -679,7 +679,7 @@ virBackingStoreIsFile(const char *backing)
c401cc
 
c401cc
 static int
c401cc
 virStorageFileProbeFormatFromBuf(const char *path,
c401cc
-                                 unsigned char *buf,
c401cc
+                                 char *buf,
c401cc
                                  size_t buflen)
c401cc
 {
c401cc
     int format = VIR_STORAGE_FILE_RAW;
c401cc
@@ -721,7 +721,7 @@ cleanup:
c401cc
 static int
c401cc
 qcow2GetFeatures(virBitmapPtr *features,
c401cc
                  int format,
c401cc
-                 unsigned char *buf,
c401cc
+                 char *buf,
c401cc
                  ssize_t len)
c401cc
 {
c401cc
     int version = -1;
c401cc
@@ -762,7 +762,7 @@ virStorageFileGetMetadataInternal(const char *path,
c401cc
                                   int format)
c401cc
 {
c401cc
     virStorageFileMetadata *meta = NULL;
c401cc
-    unsigned char *buf = NULL;
c401cc
+    char *buf = NULL;
c401cc
     ssize_t len = STORAGE_MAX_HEAD;
c401cc
     virStorageFileMetadata *ret = NULL;
c401cc
     struct stat sb;
c401cc
@@ -914,7 +914,7 @@ cleanup:
c401cc
 int
c401cc
 virStorageFileProbeFormatFromFD(const char *path, int fd)
c401cc
 {
c401cc
-    unsigned char *head;
c401cc
+    char *head = NULL;
c401cc
     ssize_t len = STORAGE_MAX_HEAD;
c401cc
     int ret = -1;
c401cc
     struct stat sb;
c401cc
-- 
c401cc
1.9.0
c401cc