summaryrefslogtreecommitdiffstats
path: root/libmsi
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@gmail.com>2013-02-08 01:59:12 +0100
committerMarc-André Lureau <marcandre.lureau@gmail.com>2013-02-08 01:59:12 +0100
commita2a6330372621a7adb1bab2ef13d67de523b3d01 (patch)
tree2cc7b493e646c5fee1a836f5d0341400bcbfcd19 /libmsi
parent6bde332f3a326d6b4836fca11b76d2099a2b8d66 (diff)
downloadmsitools-a2a6330372621a7adb1bab2ef13d67de523b3d01.tar.gz
msitools-a2a6330372621a7adb1bab2ef13d67de523b3d01.tar.xz
msitools-a2a6330372621a7adb1bab2ef13d67de523b3d01.zip
Clean-up all gcc warning
Diffstat (limited to 'libmsi')
-rw-r--r--libmsi/libmsi-database.c70
-rw-r--r--libmsi/libmsi-query.c45
-rw-r--r--libmsi/libmsi-record.c8
-rw-r--r--libmsi/libmsi-summary-info.c14
-rw-r--r--libmsi/msipriv.h8
-rw-r--r--libmsi/storages.c3
-rw-r--r--libmsi/streams.c3
-rw-r--r--libmsi/table.c9
-rw-r--r--libmsi/tokenize.c5
-rw-r--r--libmsi/where.c1
10 files changed, 70 insertions, 96 deletions
diff --git a/libmsi/libmsi-database.c b/libmsi/libmsi-database.c
index 6cfa082..350ae62 100644
--- a/libmsi/libmsi-database.c
+++ b/libmsi/libmsi-database.c
@@ -43,9 +43,9 @@ enum
G_DEFINE_TYPE (LibmsiDatabase, libmsi_database, G_TYPE_OBJECT);
-const char clsid_msi_transform[16] = { 0x82, 0x10, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46 };
-const char clsid_msi_database[16] = { 0x84, 0x10, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46 };
-const char clsid_msi_patch[16] = { 0x86, 0x10, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46 };
+const guint8 clsid_msi_transform[16] = { 0x82, 0x10, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46 };
+const guint8 clsid_msi_database[16] = { 0x84, 0x10, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46 };
+const guint8 clsid_msi_patch[16] = { 0x86, 0x10, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46 };
/*
* .MSI file format
@@ -356,7 +356,7 @@ unsigned write_raw_stream_data( LibmsiDatabase *db, const char *stname,
{
unsigned ret = LIBMSI_RESULT_FUNCTION_FAILED;
GsfInput *stm = NULL;
- char *mem;
+ guint8 *mem;
LibmsiStream *stream;
if (db->flags & LIBMSI_DB_FLAGS_READONLY)
@@ -466,6 +466,7 @@ unsigned msi_enum_db_storages(LibmsiDatabase *db,
return LIBMSI_RESULT_SUCCESS;
}
+static
unsigned clone_infile_stream( LibmsiDatabase *db, const char *name, GsfInput **stm )
{
GsfInput *stream;
@@ -1315,7 +1316,7 @@ static LibmsiResult msi_export_summaryinfo (LibmsiDatabase *db, int fd, GError *
gchar *val = summary_info_as_string (si, i);
if (!val)
goto end;
- gchar *str = g_strdup_printf ("%d\t%s\r\n", i, val);
+ str = g_strdup_printf ("%d\t%s\r\n", i, val);
sz = strlen (str);
if (write (fd, str, sz) != sz)
goto end;
@@ -1607,28 +1608,18 @@ static char *get_key_value(LibmsiQuery *view, const char *key, LibmsiRecord *rec
static char *create_diff_row_query(LibmsiDatabase *merge, LibmsiQuery *view,
char *table, LibmsiRecord *rec)
{
- char *query = NULL;
- char *clause = NULL;
+ GString *query;
char *val;
- const char *setptr;
const char *key;
- unsigned size, oldsize;
LibmsiRecord *keys;
unsigned r, i, count;
- static const char keyset[] = "`%s` = %s AND";
- static const char lastkeyset[] = "`%s` = %s ";
- static const char fmt[] = "SELECT * FROM %s WHERE %s";
-
r = _libmsi_database_get_primary_keys(merge, table, &keys);
if (r != LIBMSI_RESULT_SUCCESS)
return NULL;
- clause = msi_alloc_zero(sizeof(char));
- if (!clause)
- goto done;
-
- size = 1;
+ query = g_string_sized_new(256);
+ g_string_printf (query, "SELECT * FROM %s WHERE ", table);
count = libmsi_record_get_field_count(keys);
for (i = 1; i <= count; i++)
{
@@ -1636,34 +1627,13 @@ static char *create_diff_row_query(LibmsiDatabase *merge, LibmsiQuery *view,
val = get_key_value(view, key, rec);
if (i == count)
- setptr = lastkeyset;
+ g_string_append_printf (query, "`%s` = %s", key, val);
else
- setptr = keyset;
-
- oldsize = size;
- size += strlen(setptr) + strlen(key) + strlen(val) - 4;
- clause = msi_realloc(clause, size * sizeof (char));
- if (!clause)
- {
- msi_free(val);
- goto done;
- }
-
- sprintf(clause + oldsize - 1, setptr, key, val);
- msi_free(val);
+ g_string_append_printf (query, "`%s` = %s AND ", key, val);
}
- size = strlen(fmt) + strlen(table) + strlen(clause) + 1;
- query = msi_alloc(size * sizeof(char));
- if (!query)
- goto done;
-
- sprintf(query, fmt, table, clause);
-
-done:
- msi_free(clause);
g_object_unref(keys);
- return query;
+ return g_string_free (query, FALSE);
}
static unsigned merge_diff_row(LibmsiRecord *rec, void *param)
@@ -2068,7 +2038,7 @@ libmsi_database_merge (LibmsiDatabase *db,
bool conflicts;
unsigned r;
- TRACE("(%d, %d, %s)\n", db, merge,
+ TRACE("(%p, %p, %s)\n", db, merge,
debugstr_a(tablename));
g_return_val_if_fail (LIBMSI_IS_DATABASE (db), FALSE);
@@ -2104,7 +2074,7 @@ libmsi_database_merge (LibmsiDatabase *db,
LIST_FOR_EACH_SAFE(item, cursor, &tabledata)
{
- MERGETABLE *table = LIST_ENTRY(item, MERGETABLE, entry);
+ table = LIST_ENTRY(item, MERGETABLE, entry);
list_remove(&table->entry);
free_merge_table(table);
}
@@ -2149,14 +2119,15 @@ static void cache_infile_structure( LibmsiDatabase *db )
for (i = 0; i < n; i++)
{
GsfInput *in = gsf_infile_child_by_index(db->infile, i);
- const uint8_t *name = (const uint8_t *) gsf_input_name(in);
+ const char* name = gsf_input_name(in);
+ const uint8_t *name8 = (const uint8_t *)name;
/* table streams are not in the _Streams table */
if (!GSF_IS_INFILE(in) || gsf_infile_num_children(GSF_INFILE(in)) == -1) {
/* UTF-8 encoding of 0x4840. */
- if (name[0] == 0xe4 && name[1] == 0xa1 && name[2] == 0x80)
+ if (name8[0] == 0xe4 && name8[1] == 0xa1 && name8[2] == 0x80)
{
- decode_streamname( name + 3, decname );
+ decode_streamname(name + 3, decname);
if ( !strcmp( decname, szStringPool ) ||
!strcmp( decname, szStringData ) )
continue;
@@ -2541,7 +2512,7 @@ libmsi_database_get_primary_keys (LibmsiDatabase *db,
LibmsiRecord *rec;
unsigned r;
- TRACE("%d %s\n", db, debugstr_a(table));
+ TRACE("%p %s\n", db, debugstr_a(table));
g_return_val_if_fail (LIBMSI_IS_DATABASE (db), NULL);
g_return_val_if_fail (table != NULL, NULL);
@@ -2585,7 +2556,8 @@ libmsi_database_is_table_persistent (LibmsiDatabase *db, const char *table,
g_set_error (error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_INVALID_TABLE,
"The table is unknown");
else if (r == LIBMSI_CONDITION_ERROR)
- g_set_error (error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_FUNCTION_FAILED, "");
+ g_set_error (error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_FUNCTION_FAILED,
+ "Error");
return r == LIBMSI_CONDITION_TRUE;
}
diff --git a/libmsi/libmsi-query.c b/libmsi/libmsi-query.c
index aa3e2b1..6653bbc 100644
--- a/libmsi/libmsi-query.c
+++ b/libmsi/libmsi-query.c
@@ -190,28 +190,19 @@ unsigned _libmsi_query_open( LibmsiDatabase *db, LibmsiQuery **view, const char
{
GError *err = NULL;
unsigned r = LIBMSI_RESULT_SUCCESS;
- int size = 100, res;
char *query;
+ va_list va;
+
+ va_start(va, fmt);
+ query = g_strdup_vprintf(fmt, va);
+ va_end(va);
- /* construct the string */
- for (;;)
- {
- va_list va;
- query = msi_alloc( size*sizeof(char) );
- va_start(va, fmt);
- res = vsnprintf(query, size, fmt, va);
- va_end(va);
- if (res == -1) size *= 2;
- else if (res >= size) size = res + 1;
- else break;
- msi_free( query );
- }
- /* perform the query */
*view = libmsi_query_new (db, query, &err);
if (err)
r = err->code;
g_clear_error (&err);
- msi_free(query);
+
+ g_free(query);
return r;
}
@@ -263,29 +254,19 @@ LibmsiRecord *_libmsi_query_get_record( LibmsiDatabase *db, const char *fmt, ...
LibmsiRecord *rec = NULL;
LibmsiQuery *view = NULL;
unsigned r;
- int size = 100, res;
+ va_list va;
char *query;
GError *error = NULL; // FIXME: move error to caller
- /* construct the string */
- for (;;)
- {
- va_list va;
- query = msi_alloc( size*sizeof(char) );
- va_start(va, fmt);
- res = vsnprintf(query, size, fmt, va);
- va_end(va);
- if (res == -1) size *= 2;
- else if (res >= size) size = res + 1;
- else break;
- msi_free( query );
- }
- /* perform the query */
+ va_start(va, fmt);
+ query = g_strdup_vprintf(fmt, va);
+ va_end(va);
+
view = libmsi_query_new (db, query, &error);
if (error)
r = error->code;
g_clear_error (&error);
- msi_free(query);
+ g_free(query);
if( r == LIBMSI_RESULT_SUCCESS )
{
diff --git a/libmsi/libmsi-record.c b/libmsi/libmsi-record.c
index c05eb03..1b391dd 100644
--- a/libmsi/libmsi-record.c
+++ b/libmsi/libmsi-record.c
@@ -255,6 +255,8 @@ libmsi_record_get_int (const LibmsiRecord *rec, guint field)
if( expr_int_from_string( rec->fields[field].u.szVal, &ret ) )
return ret;
return LIBMSI_NULL_INT;
+ default:
+ g_warn_if_reached ();
}
return LIBMSI_NULL_INT;
@@ -364,6 +366,8 @@ libmsi_record_get_string (const LibmsiRecord *self, guint field)
return g_strdup (self->fields[field].u.szVal);
case LIBMSI_FIELD_TYPE_NULL:
return g_strdup ("");
+ default:
+ g_warn_if_reached ();
}
return NULL;
@@ -470,7 +474,7 @@ libmsi_record_set_string (LibmsiRecord *rec, unsigned field, const char *szValue
static unsigned _libmsi_addstream_from_file(const char *szFile, GsfInput **pstm)
{
GsfInput *stm;
- char *data;
+ guint8 *data;
off_t sz;
stm = gsf_input_stdio_new(szFile, NULL);
@@ -501,7 +505,7 @@ static unsigned _libmsi_addstream_from_file(const char *szFile, GsfInput **pstm)
g_object_unref(G_OBJECT(stm));
*pstm = gsf_input_memory_new(data, sz, true);
- TRACE("read %s, %d bytes into GsfInput %p\n", debugstr_a(szFile), sz, *pstm);
+ TRACE("read %s, %ld bytes into GsfInput %p\n", debugstr_a(szFile), sz, *pstm);
return LIBMSI_RESULT_SUCCESS;
}
diff --git a/libmsi/libmsi-summary-info.c b/libmsi/libmsi-summary-info.c
index 52dd815..a7a9571 100644
--- a/libmsi/libmsi-summary-info.c
+++ b/libmsi/libmsi-summary-info.c
@@ -181,6 +181,9 @@ static unsigned get_type( unsigned uiProperty )
case LIBMSI_PROPERTY_SECURITY:
case LIBMSI_PROPERTY_VERSION:
return OLEVT_I4;
+
+ default:
+ g_warn_if_reached ();
}
return OLEVT_EMPTY;
}
@@ -316,7 +319,7 @@ static void read_properties_from_data( LibmsiOLEVariant *prop, const uint8_t *da
for( i = 0; i < cProperties; i++ )
{
int propid = read_dword(data, &idofs);
- int dwOffset = read_dword(data, &idofs);
+ unsigned dwOffset = read_dword(data, &idofs);
int proptype;
if( propid >= MSI_MAX_PROPS )
@@ -374,6 +377,8 @@ static void read_properties_from_data( LibmsiOLEVariant *prop, const uint8_t *da
memcpy( str, &data[dwOffset], len-1 );
str[ len - 1 ] = 0;
break;
+ default:
+ g_warn_if_reached ();
}
/* check the type is the same as we expect */
@@ -516,6 +521,8 @@ static unsigned write_property_to_data( const LibmsiOLEVariant *prop, uint8_t *d
case OLEVT_LPSTR:
sz += write_string( data, sz, prop->strval );
break;
+ default:
+ g_warn_if_reached ();
}
return sz;
}
@@ -680,7 +687,8 @@ static void _summary_info_get_property (LibmsiSummaryInfo *si, unsigned uiProper
if (szValueBuf)
strcpyn (szValueBuf, prop->strval, *pcchValueBuf);
if (len >= *pcchValueBuf)
- g_set_error (error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_MORE_DATA, "");
+ g_set_error (error, LIBMSI_RESULT_ERROR, LIBMSI_RESULT_MORE_DATA,
+ "The given string is too small");
*pcchValueBuf = len;
}
break;
@@ -827,6 +835,8 @@ static LibmsiResult _libmsi_summary_info_set_property( LibmsiSummaryInfo *si, un
prop->strval = msi_alloc( len );
strcpy( prop->strval, szValue );
break;
+ default:
+ g_warn_if_reached ();
}
ret = LIBMSI_RESULT_SUCCESS;
diff --git a/libmsi/msipriv.h b/libmsi/msipriv.h
index 5241f9f..c94aa20 100644
--- a/libmsi/msipriv.h
+++ b/libmsi/msipriv.h
@@ -309,9 +309,9 @@ struct _LibmsiSummaryInfo
typedef struct _LibmsiIStream LibmsiIStream;
-extern const char clsid_msi_transform[16];
-extern const char clsid_msi_database[16];
-extern const char clsid_msi_patch[16];
+extern const guint8 clsid_msi_transform[16];
+extern const guint8 clsid_msi_database[16];
+extern const guint8 clsid_msi_patch[16];
/* handle unicode/ascii output in the Msi* API functions */
typedef struct {
@@ -464,7 +464,7 @@ static void *msi_realloc_zero( void *mem, size_t oldlen, size_t len ) G_GNUC_ALL
static inline void *msi_realloc_zero( void *mem, size_t oldlen, size_t len )
{
mem = realloc( mem, len );
- memset(mem + oldlen, 0, len - oldlen);
+ memset((char*)mem + oldlen, 0, len - oldlen);
return mem;
}
diff --git a/libmsi/storages.c b/libmsi/storages.c
index 5f8a989..3914305 100644
--- a/libmsi/storages.c
+++ b/libmsi/storages.c
@@ -244,6 +244,9 @@ static unsigned storages_view_get_column_info( LibmsiView *view, unsigned n, con
if (name) *name = szData;
if (type) *type = MSITYPE_STRING | MSITYPE_VALID | MSITYPE_NULLABLE;
break;
+
+ default:
+ g_warn_if_reached ();
}
if (table_name) *table_name = szStorages;
if (temporary) *temporary = false;
diff --git a/libmsi/streams.c b/libmsi/streams.c
index e34fffd..379dcee 100644
--- a/libmsi/streams.c
+++ b/libmsi/streams.c
@@ -278,6 +278,9 @@ static unsigned streams_view_get_column_info( LibmsiView *view, unsigned n, cons
if (name) *name = szData;
if (type) *type = MSITYPE_STRING | MSITYPE_VALID | MSITYPE_NULLABLE;
break;
+
+ default:
+ g_warn_if_reached ();
}
if (table_name) *table_name = szStreams;
if (temporary) *temporary = false;
diff --git a/libmsi/table.c b/libmsi/table.c
index 2044b4d..39d72af 100644
--- a/libmsi/table.c
+++ b/libmsi/table.c
@@ -563,10 +563,11 @@ unsigned _libmsi_open_table( LibmsiDatabase *db, const char *name, bool encoded
{
char decname[0x40];
LibmsiTable *table;
+ guint8 *name8 = (guint8*)name;
if (encoded)
{
- assert(name[0] == 0xe4 && name[1] == 0xa1 && name[2] == 0x80);
+ assert(name8[0] == 0xe4 && name8[1] == 0xa1 && name8[2] == 0x80);
decode_streamname( name + 1, decname );
name = decname;
}
@@ -2453,13 +2454,13 @@ static unsigned msi_table_load_transform( LibmsiDatabase *db, GsfInfile *stg,
if (rec)
{
char table[32];
- unsigned sz = 32;
unsigned number = LIBMSI_NULL_INT;
unsigned row = 0;
if (!strcmp( name, szColumns ))
{
- _libmsi_record_get_string( rec, 1, table, &sz );
+ unsigned tablesz = 32;
+ _libmsi_record_get_string( rec, 1, table, &tablesz );
number = libmsi_record_get_int( rec, 2 );
/*
@@ -2568,7 +2569,7 @@ unsigned msi_table_apply_transform( LibmsiDatabase *db, GsfInfile *stg )
if ( encname[0] != 0xe4 || encname[1] != 0xa1 || encname[2] != 0x80)
continue;
- decode_streamname( encname, name );
+ decode_streamname( (char*)encname, name );
if ( !strcmp( name+3, szStringPool ) ||
!strcmp( name+3, szStringData ) )
continue;
diff --git a/libmsi/tokenize.c b/libmsi/tokenize.c
index 3d95854..1320c4a 100644
--- a/libmsi/tokenize.c
+++ b/libmsi/tokenize.c
@@ -160,7 +160,8 @@ static const char isIdChar[] = {
** -1 if the token is (or might be) incomplete. Store the token
** type in *tokenType before returning.
*/
-int sql_get_token(const char *z, int *tokenType, int *skip){
+int sql_get_token(const char *zz, int *tokenType, int *skip){
+ guint8 *z = (guint8*)zz;
int i;
*skip = 0;
@@ -251,7 +252,7 @@ int sql_get_token(const char *z, int *tokenType, int *skip){
break;
}
for(i=1; isIdChar[z[i]]; i++){}
- *tokenType = sqlite_find_keyword(z, i);
+ *tokenType = sqlite_find_keyword(zz, i);
if( *tokenType == TK_ID && z[i] == '`' ) *skip = 1;
return i;
}
diff --git a/libmsi/where.c b/libmsi/where.c
index fde5684..5da396a 100644
--- a/libmsi/where.c
+++ b/libmsi/where.c
@@ -306,7 +306,6 @@ static unsigned where_view_set_row( LibmsiView *view, unsigned row, LibmsiRecord
do
{
const unsigned col_count = table->col_count;
- unsigned i;
LibmsiRecord *reduced;
unsigned reduced_mask = (mask >> offset) & ((1 << col_count) - 1);