summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac1
-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
-rw-r--r--tools/msibuild.c1
-rw-r--r--tools/msiinfo.c79
-rw-r--r--tools/sqldelim.c8
14 files changed, 102 insertions, 153 deletions
diff --git a/configure.ac b/configure.ac
index 69a4897..9bf54f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,7 +44,6 @@ AM_GNU_GETTEXT_VERSION([0.18])
AM_GLIB_GNU_GETTEXT
gl_MANYWARN_ALL_GCC([warnings])
-
nw=
nw="$nw -Wsystem-headers" # Don't let system headers trigger warnings
nw="$nw -Wundef" # All compiler preprocessors support #if UNDEF
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);
diff --git a/tools/msibuild.c b/tools/msibuild.c
index 5f638c5..0e96e81 100644
--- a/tools/msibuild.c
+++ b/tools/msibuild.c
@@ -128,7 +128,6 @@ static LibmsiDatabase *db;
static gboolean import_table(char *table, GError **error)
{
gboolean success = TRUE;
- char dir[PATH_MAX];
if (!libmsi_database_import(db, table, error))
{
diff --git a/tools/msiinfo.c b/tools/msiinfo.c
index 36dd0cd..ac299fd 100644
--- a/tools/msiinfo.c
+++ b/tools/msiinfo.c
@@ -34,8 +34,6 @@
#include <fcntl.h>
#include <limits.h>
-static const char *program_name;
-
struct Command {
const char *cmd;
const char *desc;
@@ -47,27 +45,11 @@ struct Command {
static struct Command cmds[];
-static char *get_basename(char *path)
-{
- char *p;
- if (!path || !*path) {
- return ".";
- }
- p = path + strlen(path);
- while (p > path && *p != '/' && *p != '\\') {
- p--;
- }
- if (p > path) {
- p++;
- }
- return p;
-}
-
static void usage(FILE *out)
{
int i;
- fprintf(out, "Usage: %s SUBCOMMAND COMMAND-OPTIONS...\n\n", program_name);
+ fprintf(out, "Usage: %s SUBCOMMAND COMMAND-OPTIONS...\n\n", g_get_prgname ());
fprintf(out, "Options:\n");
fprintf(out, " -h, --help Show program usage\n");
fprintf(out, " -v, --version Display program version\n\n");
@@ -82,7 +64,7 @@ static void usage(FILE *out)
static void cmd_usage(FILE *out, struct Command *cmd)
{
- fprintf(out, "%s %s %s\n\n%s.\n", program_name, cmd->cmd, cmd->opts,
+ fprintf(out, "%s %s %s\n\n%s.\n", g_get_prgname (), cmd->cmd, cmd->opts,
cmd->desc);
if (cmd->help) {
@@ -98,54 +80,56 @@ static void print_libmsi_error(LibmsiResultError r)
case LIBMSI_RESULT_SUCCESS:
abort();
case LIBMSI_RESULT_CONTINUE:
- fprintf(stderr, "%s: internal error (continue)\n", program_name);
+ fprintf(stderr, "%s: internal error (continue)\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_MORE_DATA:
- fprintf(stderr, "%s: internal error (more data)\n", program_name);
+ fprintf(stderr, "%s: internal error (more data)\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_INVALID_HANDLE:
- fprintf(stderr, "%s: internal error (invalid handle)\n", program_name);
+ fprintf(stderr, "%s: internal error (invalid handle)\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_NOT_ENOUGH_MEMORY:
case LIBMSI_RESULT_OUTOFMEMORY:
- fprintf(stderr, "%s: out of memory\n", program_name);
+ fprintf(stderr, "%s: out of memory\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_INVALID_DATA:
- fprintf(stderr, "%s: invalid data\n", program_name);
+ fprintf(stderr, "%s: invalid data\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_INVALID_PARAMETER:
- fprintf(stderr, "%s: invalid parameter\n", program_name);
+ fprintf(stderr, "%s: invalid parameter\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_OPEN_FAILED:
- fprintf(stderr, "%s: open failed\n", program_name);
+ fprintf(stderr, "%s: open failed\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_CALL_NOT_IMPLEMENTED:
- fprintf(stderr, "%s: not implemented\n", program_name);
+ fprintf(stderr, "%s: not implemented\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_NOT_FOUND:
- fprintf(stderr, "%s: not found\n", program_name);
+ fprintf(stderr, "%s: not found\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_UNKNOWN_PROPERTY:
- fprintf(stderr, "%s: unknown property\n", program_name);
+ fprintf(stderr, "%s: unknown property\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_BAD_QUERY_SYNTAX:
- fprintf(stderr, "%s: bad query syntax\n", program_name);
+ fprintf(stderr, "%s: bad query syntax\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_INVALID_FIELD:
- fprintf(stderr, "%s: invalid field\n", program_name);
+ fprintf(stderr, "%s: invalid field\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_FUNCTION_FAILED:
- fprintf(stderr, "%s: internal error (function failed)\n", program_name);
+ fprintf(stderr, "%s: internal error (function failed)\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_INVALID_TABLE:
- fprintf(stderr, "%s: invalid table\n", program_name);
+ fprintf(stderr, "%s: invalid table\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_DATATYPE_MISMATCH:
- fprintf(stderr, "%s: datatype mismatch\n", program_name);
+ fprintf(stderr, "%s: datatype mismatch\n", g_get_prgname ());
exit(1);
case LIBMSI_RESULT_INVALID_DATATYPE:
- fprintf(stderr, "%s: invalid datatype\n", program_name);
+ fprintf(stderr, "%s: invalid datatype\n", g_get_prgname ());
exit(1);
+ default:
+ g_warn_if_reached ();
}
}
@@ -159,7 +143,7 @@ static struct Command *find_cmd(const char *s)
}
}
- fprintf(stderr, "%s: Unrecognized command '%s'\n", program_name, s);
+ fprintf(stderr, "%s: Unrecognized command '%s'\n", g_get_prgname (), s);
return NULL;
}
@@ -263,11 +247,8 @@ static void print_suminfo(LibmsiSummaryInfo *si, int prop, const char *name)
const gchar* str;
int val;
uint64_t valtime;
- unsigned sz;
- unsigned r;
time_t t;
- sz = 0;
type = libmsi_summary_info_get_property_type(si, prop, &error);
if (error)
goto end;
@@ -375,7 +356,7 @@ static int cmd_extract(struct Command *cmd, int argc, char **argv, GError **erro
GInputStream *in = NULL;
int r = 1;
char buffer[4096];
- size_t n_read, n_written;
+ size_t n_read;
if (argc != 3) {
cmd_usage(stderr, cmd);
@@ -441,7 +422,6 @@ static gboolean export_create_table(const char *table,
guint i, len;
char size[20], extra[30];
gchar *name, *type;
- unsigned sz;
if (!strcmp(table, "_Tables") ||
!strcmp(table, "_Columns") ||
@@ -464,7 +444,7 @@ static gboolean export_create_table(const char *table,
}
extra[0] = '\0';
- if (islower(type[0])) {
+ if (g_ascii_islower(type[0])) {
strcat(extra, " NOT NULL");
}
@@ -533,7 +513,6 @@ static gboolean export_insert(const char *table,
guint num_columns = libmsi_record_get_field_count(names);
gchar *name, *type;
guint i;
- unsigned sz;
char *s;
printf("INSERT INTO `%s` (", table);
@@ -543,7 +522,6 @@ static gboolean export_insert(const char *table,
continue;
}
- sz = sizeof(name);
name = libmsi_record_get_string(names, i);
g_return_val_if_fail(name != NULL, FALSE);
@@ -565,7 +543,6 @@ static gboolean export_insert(const char *table,
printf(", ");
}
- sz = sizeof(type);
type = libmsi_record_get_string(types, i);
g_return_val_if_fail(type != NULL, FALSE);
@@ -582,7 +559,7 @@ static gboolean export_insert(const char *table,
printf("%d", libmsi_record_get_int(vals, i));
break;
case 'v': case 'V':
- printf("''", s);
+ printf("''");
break;
default:
abort();
@@ -634,7 +611,6 @@ static gboolean export_sql( LibmsiDatabase *db, const char *table, GError **erro
/* write out row 4 onwards, the data */
while ((rec = libmsi_query_fetch(query, &err))) {
- unsigned size = PATH_MAX;
success = export_insert(table, name, type, rec);
g_object_unref(rec);
if (!success) {
@@ -696,7 +672,7 @@ end:
static int cmd_version(struct Command *cmd, int argc, char **argv, GError **error)
{
- printf("%s (%s) version %s\n", program_name, PACKAGE, VERSION);
+ printf("%s (%s) version %s\n", g_get_prgname (), PACKAGE, VERSION);
return 0;
}
@@ -779,8 +755,7 @@ int main(int argc, char **argv)
#if !GLIB_CHECK_VERSION(2,35,1)
g_type_init ();
#endif
-
- program_name = get_basename(argv[0]);
+ g_set_prgname ("msiinfo");
if (argc == 1) {
usage(stderr);
@@ -788,7 +763,7 @@ int main(int argc, char **argv)
cmd = find_cmd(argv[1]);
if (!cmd) {
- fprintf(stderr, "%s: Unrecognized command\n", program_name);
+ fprintf(stderr, "%s: Unrecognized command\n", g_get_prgname ());
usage(stderr);
}
diff --git a/tools/sqldelim.c b/tools/sqldelim.c
index 1eebf09..645c783 100644
--- a/tools/sqldelim.c
+++ b/tools/sqldelim.c
@@ -26,13 +26,15 @@
#include <string.h>
#include <glib.h>
+#include "sqldelim.h"
+
/*
** All the keywords of the SQL language are stored as in a hash
** table composed of instances of the following structure.
*/
typedef struct Keyword Keyword;
struct Keyword {
- const uint8_t *zName; /* The keyword name */
+ const char *zName; /* The keyword name */
};
#define MAX_TOKEN_LEN 11
@@ -59,7 +61,7 @@ static const Keyword aKeywordTable[] = {
static int sql_compare_keyword(const void *m1, const void *m2){
const uint8_t *p = m1;
const Keyword *k = m2;
- const uint8_t *q = k->zName;
+ const char *q = k->zName;
for (; *p; p++, q++) {
uint8_t c;
@@ -179,7 +181,7 @@ static int sql_skip_token(const char **p, bool *cont)
return true;
}
while (isIdChar[z[i]]) i++;
- if (get_keyword && sqlite_find_keyword(z, i)) {
+ if (get_keyword && sqlite_find_keyword(*p, i)) {
return true;
} else {
/* Do not recognize a keyword at the beginning of the next chunk. */