Blob Blame History Raw
From 3872db0a227069d906614e5449833ca1d13e16c4 Mon Sep 17 00:00:00 2001
Message-Id: <3872db0a227069d906614e5449833ca1d13e16c4@dist-git>
From: Eric Blake <eblake@redhat.com>
Date: Wed, 26 Feb 2014 14:54:33 +0100
Subject: [PATCH] storage: use simpler 'char *'

https://bugzilla.redhat.com/show_bug.cgi?id=1032370

'unsigned char *' makes sense if you are doing math on bytes and
don't want to worry about wraparound from a signed 'char'; but
since all we are doing is memcmp() or virReadBufInt*[LB]E(), which
are both safe on either type of char, and since read() prefers to
operate on 'char *', it's simpler to avoid casts by just typing
things as 'char *' from the get-go.  [Technically, read can
operate on an 'unsigned char *' thanks to the C rule that any
pointer can be implicitly converted to 'char *' for legacy K&R
compatibility; but where this patch saves us is if we try to use
virfile.h functions that take 'char **' in order to allocate the
buffer, where the compiler would barf on type mismatch.]

* src/util/virstoragefile.c (FileTypeInfo): Avoid unsigned char.
(cowGetBackingStore, qcow2GetBackingStoreFormat)
(qcowXGetBackingStore, qcow1GetBackingStore)
(qcow2GetBackingStore, vmdk4GetBackingStore, qedGetBackingStore)
(virStorageFileMatchesMagic, virStorageFileMatchesVersion)
(virStorageFileProbeFormatFromBuf, qcow2GetFeatures)
(virStorageFileGetMetadataInternal)
(virStorageFileProbeFormatFromFD): Simplify clients.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 5717ee6ab871253c3e512ece7d59b754624e99c0)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/util/virstoragefile.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index fc8aa90..bb27461 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -102,23 +102,23 @@ struct FileTypeInfo {
                            * where to find encryption mode,
                            * -1 if encryption is not used */
     int (*getBackingStore)(char **res, int *format,
-                           const unsigned char *buf, size_t buf_size);
+                           const char *buf, size_t buf_size);
     int (*getFeatures)(virBitmapPtr *features, int format,
-                       unsigned char *buf, ssize_t len);
+                       char *buf, ssize_t len);
 };
 
 static int cowGetBackingStore(char **, int *,
-                              const unsigned char *, size_t);
+                              const char *, size_t);
 static int qcow1GetBackingStore(char **, int *,
-                                const unsigned char *, size_t);
+                                const char *, size_t);
 static int qcow2GetBackingStore(char **, int *,
-                                const unsigned char *, size_t);
+                                const char *, size_t);
 static int qcow2GetFeatures(virBitmapPtr *features, int format,
-                            unsigned char *buf, ssize_t len);
+                            char *buf, ssize_t len);
 static int vmdk4GetBackingStore(char **, int *,
-                                const unsigned char *, size_t);
+                                const char *, size_t);
 static int
-qedGetBackingStore(char **, int *, const unsigned char *, size_t);
+qedGetBackingStore(char **, int *, const char *, size_t);
 
 #define QCOWX_HDR_VERSION (4)
 #define QCOWX_HDR_BACKING_FILE_OFFSET (QCOWX_HDR_VERSION+4)
@@ -252,7 +252,7 @@ verify(ARRAY_CARDINALITY(qcow2CompatibleFeatureArray) ==
 static int
 cowGetBackingStore(char **res,
                    int *format,
-                   const unsigned char *buf,
+                   const char *buf,
                    size_t buf_size)
 {
 #define COW_FILENAME_MAXLEN 1024
@@ -274,7 +274,7 @@ cowGetBackingStore(char **res,
 
 static int
 qcow2GetBackingStoreFormat(int *format,
-                           const unsigned char *buf,
+                           const char *buf,
                            size_t buf_size,
                            size_t extension_start,
                            size_t extension_end)
@@ -329,7 +329,7 @@ done:
 static int
 qcowXGetBackingStore(char **res,
                      int *format,
-                     const unsigned char *buf,
+                     const char *buf,
                      size_t buf_size,
                      bool isQCow2)
 {
@@ -407,7 +407,7 @@ qcowXGetBackingStore(char **res,
 static int
 qcow1GetBackingStore(char **res,
                      int *format,
-                     const unsigned char *buf,
+                     const char *buf,
                      size_t buf_size)
 {
     int ret;
@@ -424,7 +424,7 @@ qcow1GetBackingStore(char **res,
 static int
 qcow2GetBackingStore(char **res,
                      int *format,
-                     const unsigned char *buf,
+                     const char *buf,
                      size_t buf_size)
 {
     return qcowXGetBackingStore(res, format, buf, buf_size, true);
@@ -434,7 +434,7 @@ qcow2GetBackingStore(char **res,
 static int
 vmdk4GetBackingStore(char **res,
                      int *format,
-                     const unsigned char *buf,
+                     const char *buf,
                      size_t buf_size)
 {
     static const char prefix[] = "parentFileNameHint=\"";
@@ -495,7 +495,7 @@ cleanup:
 static int
 qedGetBackingStore(char **res,
                    int *format,
-                   const unsigned char *buf,
+                   const char *buf,
                    size_t buf_size)
 {
     unsigned long long flags;
@@ -596,7 +596,7 @@ cleanup:
 
 static bool
 virStorageFileMatchesMagic(int format,
-                           unsigned char *buf,
+                           char *buf,
                            size_t buflen)
 {
     int mlen;
@@ -634,7 +634,7 @@ virStorageFileMatchesExtension(int format,
 
 static bool
 virStorageFileMatchesVersion(int format,
-                             unsigned char *buf,
+                             char *buf,
                              size_t buflen)
 {
     int version;
@@ -679,7 +679,7 @@ virBackingStoreIsFile(const char *backing)
 
 static int
 virStorageFileProbeFormatFromBuf(const char *path,
-                                 unsigned char *buf,
+                                 char *buf,
                                  size_t buflen)
 {
     int format = VIR_STORAGE_FILE_RAW;
@@ -721,7 +721,7 @@ cleanup:
 static int
 qcow2GetFeatures(virBitmapPtr *features,
                  int format,
-                 unsigned char *buf,
+                 char *buf,
                  ssize_t len)
 {
     int version = -1;
@@ -762,7 +762,7 @@ virStorageFileGetMetadataInternal(const char *path,
                                   int format)
 {
     virStorageFileMetadata *meta = NULL;
-    unsigned char *buf = NULL;
+    char *buf = NULL;
     ssize_t len = STORAGE_MAX_HEAD;
     virStorageFileMetadata *ret = NULL;
     struct stat sb;
@@ -914,7 +914,7 @@ cleanup:
 int
 virStorageFileProbeFormatFromFD(const char *path, int fd)
 {
-    unsigned char *head;
+    char *head = NULL;
     ssize_t len = STORAGE_MAX_HEAD;
     int ret = -1;
     struct stat sb;
-- 
1.9.0