diff options
| author | Richard Hughes <richard@hughsie.com> | 2017-11-17 13:03:04 (GMT) |
|---|---|---|
| committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2017-11-20 10:56:13 (GMT) |
| commit | 0c9c7b478b5a9d0d8b5da5ef8cd964fa1b678448 (patch) | |
| tree | f140820510f5352673e95dfb8db584bf00534317 | |
| parent | 24ef000897f81a3b93c3116dc93a9be59b725f4b (diff) | |
| download | gcab-0c9c7b478b5a9d0d8b5da5ef8cd964fa1b678448.zip gcab-0c9c7b478b5a9d0d8b5da5ef8cd964fa1b678448.tar.xz | |
Replace all the custom typedefd unsigned types with working versions
On some architectures, sizeof(unsigned long int) is not 4 bytes, which makes
various assumptions in the code fail.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
| -rw-r--r-- | libgcab/cabinet.c | 36 | ||||
| -rw-r--r-- | libgcab/cabinet.h | 62 | ||||
| -rw-r--r-- | libgcab/decomp.h | 2 | ||||
| -rw-r--r-- | libgcab/gcab-file.c | 2 | ||||
| -rw-r--r-- | libgcab/gcab-folder.c | 8 | ||||
| -rw-r--r-- | libgcab/gcab-priv.h | 4 |
6 files changed, 54 insertions, 60 deletions
diff --git a/libgcab/cabinet.c b/libgcab/cabinet.c index 46e534e..caf695e 100644 --- a/libgcab/cabinet.c +++ b/libgcab/cabinet.c @@ -303,7 +303,7 @@ cfolder_write (cfolder_t *cf, GDataOutputStream *out, } G_GNUC_INTERNAL gboolean -cfolder_read (cfolder_t *cf, u1 res_size, GDataInputStream *in, +cfolder_read (cfolder_t *cf, guint8 res_size, GDataInputStream *in, GCancellable *cancellable, GError **error) { gboolean success = FALSE; @@ -377,34 +377,32 @@ end: return success; } -typedef guint32 CHECKSUM; - -static CHECKSUM -compute_checksum (guint8 *in, u2 ncbytes, CHECKSUM seed) +static guint32 +compute_checksum (guint8 *in, guint16 ncbytes, guint32 seed) { int no_ulongs; - CHECKSUM csum=0; - CHECKSUM temp; + guint32 csum=0; + guint32 temp; no_ulongs = ncbytes / 4; csum = seed; while (no_ulongs-- > 0) { - temp = ((CHECKSUM) (*in++)); - temp |= (((CHECKSUM) (*in++)) << 8); - temp |= (((CHECKSUM) (*in++)) << 16); - temp |= (((CHECKSUM) (*in++)) << 24); + temp = ((guint32) (*in++)); + temp |= (((guint32) (*in++)) << 8); + temp |= (((guint32) (*in++)) << 16); + temp |= (((guint32) (*in++)) << 24); csum ^= temp; } temp = 0; switch (ncbytes % 4) { - case 3: temp |= (((CHECKSUM) (*in++)) << 16); + case 3: temp |= (((guint32) (*in++)) << 16); /* fall-thru */ - case 2: temp |= (((CHECKSUM) (*in++)) << 8); + case 2: temp |= (((guint32) (*in++)) << 8); /* fall-thru */ - case 1: temp |= ((CHECKSUM) (*in++)); + case 1: temp |= ((guint32) (*in++)); /* fall-thru */ default: break; } @@ -422,8 +420,8 @@ cdata_write (cdata_t *cd, GDataOutputStream *out, int type, if (!cdata_set(cd, type, data, size)) return FALSE; - CHECKSUM datacsum = compute_checksum(cd->in, cd->ncbytes, 0); - CHECKSUM sizecsum = GUINT32_TO_LE(cd->ncbytes << 16 | cd->nubytes); + guint32 datacsum = compute_checksum(cd->in, cd->ncbytes, 0); + guint32 sizecsum = GUINT32_TO_LE(cd->ncbytes << 16 | cd->nubytes); cd->checksum = compute_checksum ((guint8*)&sizecsum, 4, datacsum); GOutputStream *stream = g_filter_output_stream_get_base_stream (G_FILTER_OUTPUT_STREAM (out)); @@ -458,7 +456,7 @@ cdata_finish (cdata_t *cd, GError **error) } G_GNUC_INTERNAL gboolean -cdata_read (cdata_t *cd, u1 res_data, gint comptype, +cdata_read (cdata_t *cd, guint8 res_data, gint comptype, GDataInputStream *in, GCancellable *cancellable, GError **error) { @@ -466,8 +464,8 @@ cdata_read (cdata_t *cd, u1 res_data, gint comptype, int ret, zret = Z_OK; gint compression = comptype & GCAB_COMPRESSION_MASK; guint8 *buf = compression == GCAB_COMPRESSION_NONE ? cd->out : cd->in; - CHECKSUM datacsum; - CHECKSUM sizecsum; + guint32 datacsum; + guint32 sizecsum; if (compression > GCAB_COMPRESSION_MSZIP && compression != GCAB_COMPRESSION_LZX) { diff --git a/libgcab/cabinet.h b/libgcab/cabinet.h index 299eb68..b50088b 100644 --- a/libgcab/cabinet.h +++ b/libgcab/cabinet.h @@ -20,10 +20,6 @@ /* based on the spec http://msdn.microsoft.com/en-us/library/bb417343.aspx */ -typedef unsigned char u1; -typedef unsigned short int u2; -typedef unsigned long int u4; - typedef struct cheader cheader_t; typedef struct cfolder cfolder_t; typedef struct cfile cfile_t; @@ -36,21 +32,21 @@ typedef struct cdata cdata_t; struct cheader { - u4 res1; - u4 size; - u4 res2; - u4 offsetfiles; - u4 res3; - u1 versionMIN; - u1 versionMAJ; - u2 nfolders; - u2 nfiles; - u2 flags; - u2 setID; - u2 cabID; - u2 res_header; - u1 res_folder; - u1 res_data; + guint32 res1; + guint32 size; + guint32 res2; + guint32 offsetfiles; + guint32 res3; + guint8 versionMIN; + guint8 versionMAJ; + guint16 nfolders; + guint16 nfiles; + guint16 flags; + guint16 setID; + guint16 cabID; + guint16 res_header; + guint8 res_folder; + guint8 res_data; guint8 *reserved; gchar *cab_prev; gchar *disk_prev; @@ -66,28 +62,28 @@ typedef enum { struct cfolder { - u4 offsetdata; - u2 ndatab; - u2 typecomp; + guint32 offsetdata; + guint16 ndatab; + guint16 typecomp; guint8 *reserved; }; struct cfile { - u4 usize; - u4 uoffset; - u2 index; - u2 date; - u2 time; - u2 fattr; + guint32 usize; + guint32 uoffset; + guint16 index; + guint16 date; + guint16 time; + guint16 fattr; gchar *name; }; struct cdata { - u4 checksum; - u2 ncbytes; - u2 nubytes; + guint32 checksum; + guint16 ncbytes; + guint16 nubytes; guint8 *reserved; guint8 in[CAB_INPUTMAX+2]; guint8 out[CAB_BLOCKMAX]; @@ -111,7 +107,7 @@ gboolean cfolder_write (cfolder_t *cf, GCancellable *cancellable, GError **error); gboolean cfolder_read (cfolder_t *cf, - u1 res_folder, + guint8 res_folder, GDataInputStream *in, GCancellable *cancellable, GError **error); @@ -132,7 +128,7 @@ gboolean cdata_write (cdata_t *cd, GCancellable *cancellable, GError **error); gboolean cdata_read (cdata_t *cd, - u1 res_data, + guint8 res_data, gint comptype, GDataInputStream *in, GCancellable *cancellable, diff --git a/libgcab/decomp.h b/libgcab/decomp.h index 14a9e8d..78b1b76 100644 --- a/libgcab/decomp.h +++ b/libgcab/decomp.h @@ -125,7 +125,7 @@ #define CAB_BLOCKMAX (32768) #define CAB_INPUTMAX (CAB_BLOCKMAX+6144) -typedef unsigned char cab_UBYTE; /* 8 bits */ +typedef guint8 cab_UBYTE; /* 8 bits */ typedef guint16 cab_UWORD; /* 16 bits */ typedef guint32 cab_ULONG; /* 32 bits */ typedef gint32 cab_LONG; /* 32 bits */ diff --git a/libgcab/gcab-file.c b/libgcab/gcab-file.c index fbc3504..f014fd6 100644 --- a/libgcab/gcab-file.c +++ b/libgcab/gcab-file.c @@ -151,7 +151,7 @@ gcab_file_update_info (GCabFile *self, GFileInfo *info) } G_GNUC_INTERNAL gboolean -gcab_file_set_uoffset (GCabFile *self, u4 uoffset) +gcab_file_set_uoffset (GCabFile *self, guint32 uoffset) { g_return_val_if_fail (GCAB_IS_FILE (self), FALSE); diff --git a/libgcab/gcab-folder.c b/libgcab/gcab-folder.c index 8c3c0be..2df51fd 100644 --- a/libgcab/gcab-folder.c +++ b/libgcab/gcab-folder.c @@ -332,7 +332,7 @@ sort_by_offset (GCabFile *a, GCabFile *b) G_GNUC_INTERNAL gboolean gcab_folder_extract (GCabFolder *self, GFile *path, - u1 res_data, + guint8 res_data, GCabFileCallback file_callback, GFileProgressCallback progress_callback, gpointer callback_data, @@ -345,7 +345,7 @@ gcab_folder_extract (GCabFolder *self, GFileOutputStream *out = NULL; GSList *f, *files = NULL; cdata_t cdata = { 0, }; - u4 nubytes = 0; + guint32 nubytes = 0; data = g_data_input_stream_new (self->stream); g_data_input_stream_set_byte_order (data, G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN); @@ -406,8 +406,8 @@ gcab_folder_extract (GCabFolder *self, if (!out) goto end; - u4 usize = file->cfile.usize; - u4 uoffset = file->cfile.uoffset; + guint32 usize = file->cfile.usize; + guint32 uoffset = file->cfile.uoffset; /* let's rewind if need be */ if (uoffset < nubytes) { diff --git a/libgcab/gcab-priv.h b/libgcab/gcab-priv.h index 1893cb7..4b8ad24 100644 --- a/libgcab/gcab-priv.h +++ b/libgcab/gcab-priv.h @@ -48,12 +48,12 @@ GCabFolder * gcab_folder_new_with_cfolder (const cfolder_t *folder, G GCabFile * gcab_file_new_with_cfile (const cfile_t *file); gboolean gcab_file_update_info (GCabFile *file, GFileInfo *info); -gboolean gcab_file_set_uoffset (GCabFile *file, u4 uoffset); +gboolean gcab_file_set_uoffset (GCabFile *file, guint32 uoffset); gsize gcab_folder_get_ndatablocks (GCabFolder *folder); gboolean gcab_folder_extract (GCabFolder *self, GFile *path, - u1 res_data, + guint8 res_data, GCabFileCallback file_callback, GFileProgressCallback progress_callback, gpointer callback_data, |