Allow CFLGAS="-std=c99 -D_POSIX_C_SOURCE=2"

Use glib function:
strcasecmp -> g_ascii_strcasecmp
bzero -> memset
strdup -> g_strdump

Don't use arithmetic void*+int
This commit is contained in:
Nirgal Vourgère
2014-12-28 12:36:55 +01:00
parent 4b52d6bfd9
commit 2a70e16a8b
14 changed files with 59 additions and 57 deletions

View File

@@ -792,7 +792,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
fputs("TRUE", outfile);
else if (!strcmp(defval, "No"))
fputs("FALSE", outfile);
else if (!strcasecmp(defval, "date()")) {
else if (!g_ascii_strcasecmp(defval, "date()")) {
if (!strcmp(mdb_col_get_prop(col, "Format"), "Short Date"))
fputs(mdb->default_backend->short_now, outfile);
else

View File

@@ -147,7 +147,7 @@ mdb_get_catalogentry_by_name(MdbHandle *mdb, const gchar* name)
for (i=0; i<mdb->num_catalog; i++) {
entry = g_ptr_array_index(mdb->catalog, i);
if (!strcasecmp(entry->object_name, name))
if (!g_ascii_strcasecmp(entry->object_name, name))
return entry;
}
return NULL;

View File

@@ -67,7 +67,7 @@ mdb_bind_column_by_name(MdbTableDef *table, gchar *col_name, void *bind_ptr, int
for (i=0;i<table->num_cols;i++) {
col=g_ptr_array_index(table->columns,i);
if (!strcasecmp(col->name,col_name)) {
if (!g_ascii_strcasecmp(col->name,col_name)) {
col_num = i + 1;
if (bind_ptr)
col->bind_ptr = bind_ptr;
@@ -497,7 +497,7 @@ mdb_ole_read_next(MdbHandle *mdb, MdbColumn *col, void *ole_ptr)
mdb_debug(MDB_DEBUG_OLE,"start %d len %d", row_start, len);
if (col->bind_ptr)
memcpy(col->bind_ptr, buf + row_start + 4, len - 4);
memcpy(col->bind_ptr, (char*)buf + row_start + 4, len - 4);
col->cur_blob_pg_row = mdb_get_int32(buf, row_start);
return len - 4;
@@ -542,7 +542,7 @@ mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size)
mdb_debug(MDB_DEBUG_OLE,"start %d len %d", row_start, len);
if (col->bind_ptr) {
memcpy(col->bind_ptr, buf + row_start, len);
memcpy(col->bind_ptr, (char*)buf + row_start, len);
if (mdb_get_option(MDB_DEBUG_OLE))
mdb_buffer_dump(col->bind_ptr, 0, 16);
}
@@ -560,7 +560,7 @@ mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size)
mdb_debug(MDB_DEBUG_OLE,"start %d len %d", row_start, len);
if (col->bind_ptr)
memcpy(col->bind_ptr, buf + row_start + 4, len - 4);
memcpy(col->bind_ptr, (char*)buf + row_start + 4, len - 4);
col->cur_blob_pg_row = mdb_get_int32(buf, row_start);
mdb_debug(MDB_DEBUG_OLE, "next pg_row %d", col->cur_blob_pg_row);
@@ -692,7 +692,7 @@ static char *mdb_memo_to_string(MdbHandle *mdb, int start, int size)
if (memo_len & 0x80000000) {
/* inline memo field */
mdb_unicode2ascii(mdb, pg_buf + start + MDB_MEMO_OVERHEAD,
mdb_unicode2ascii(mdb, (char*)pg_buf + start + MDB_MEMO_OVERHEAD,
size - MDB_MEMO_OVERHEAD, text, MDB_BIND_SIZE);
return text;
} else if (memo_len & 0x40000000) {
@@ -710,7 +710,7 @@ static char *mdb_memo_to_string(MdbHandle *mdb, int start, int size)
pg_row & 0xff, row_start, len);
mdb_buffer_dump(buf, row_start, len);
#endif
mdb_unicode2ascii(mdb, buf + row_start, len, text, MDB_BIND_SIZE);
mdb_unicode2ascii(mdb, (char*)buf + row_start, len, text, MDB_BIND_SIZE);
return text;
} else if ((memo_len & 0xff000000) == 0) { // assume all flags in MSB
/* multi-page memo field */
@@ -739,7 +739,7 @@ static char *mdb_memo_to_string(MdbHandle *mdb, int start, int size)
if (!len)
break;
memcpy(tmp + tmpoff, buf + row_start + 4, len - 4);
memcpy(tmp + tmpoff, (char*)buf + row_start + 4, len - 4);
tmpoff += len - 4;
} while (( pg_row = mdb_get_int32(buf, row_start) ));
if (tmpoff < memo_len) {
@@ -940,7 +940,7 @@ char *mdb_col_to_string(MdbHandle *mdb, void *buf, int start, int datatype, int
text = g_strdup("");
} else {
text = (char *) g_malloc(MDB_BIND_SIZE);
mdb_unicode2ascii(mdb, buf + start,
mdb_unicode2ascii(mdb, (char*)buf + start,
size, text, MDB_BIND_SIZE);
}
break;

View File

@@ -423,7 +423,7 @@ unsigned char mdb_pg_get_byte(MdbHandle *mdb, int offset)
int mdb_get_int16(void *buf, int offset)
{
guint16 l;
memcpy(&l, buf + offset, 2);
memcpy(&l, (char*)buf + offset, 2);
return (int)GUINT16_FROM_LE(l);
}
int mdb_pg_get_int16(MdbHandle *mdb, int offset)
@@ -436,13 +436,13 @@ int mdb_pg_get_int16(MdbHandle *mdb, int offset)
long mdb_get_int32_msb(void *buf, int offset)
{
gint32 l;
memcpy(&l, buf + offset, 4);
memcpy(&l, (char*)buf + offset, 4);
return (long)GINT32_FROM_BE(l);
}
long mdb_get_int32(void *buf, int offset)
{
gint32 l;
memcpy(&l, buf + offset, 4);
memcpy(&l, (char*)buf + offset, 4);
return (long)GINT32_FROM_LE(l);
}
long mdb_pg_get_int32(MdbHandle *mdb, int offset)
@@ -455,7 +455,7 @@ long mdb_pg_get_int32(MdbHandle *mdb, int offset)
float mdb_get_single(void *buf, int offset)
{
union {guint32 g; float f;} f;
memcpy(&f, buf + offset, 4);
memcpy(&f, (char*)buf + offset, 4);
f.g = GUINT32_FROM_LE(f.g);
return f.f;
}
@@ -469,7 +469,7 @@ float mdb_pg_get_single(MdbHandle *mdb, int offset)
double mdb_get_double(void *buf, int offset)
{
union {guint64 g; double d;} d;
memcpy(&d, buf + offset, 8);
memcpy(&d, (char*)buf + offset, 8);
d.g = GUINT64_FROM_LE(d.g);
return d.d;
}

View File

@@ -192,7 +192,7 @@ mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
switch (record_type) {
case 0x80:
if (names) free_names(names);
names = mdb_read_props_list(mdb, buffer+pos+6, record_len - 6);
names = mdb_read_props_list(mdb, (char*)buffer+pos+6, record_len - 6);
break;
case 0x00:
case 0x01:
@@ -200,7 +200,7 @@ mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
fprintf(stderr,"sequence error!\n");
break;
}
props = mdb_read_props(mdb, names, buffer+pos+6, record_len - 6);
props = mdb_read_props(mdb, names, (char*)buffer+pos+6, record_len - 6);
g_array_append_val(result, props);
//mdb_dump_props(props, stderr, 1);
break;

View File

@@ -302,7 +302,7 @@ int mdb_add_sarg_by_name(MdbTableDef *table, char *colname, MdbSarg *in_sarg)
for (i=0;i<table->num_cols;i++) {
col = g_ptr_array_index (table->columns, i);
if (!strcasecmp(col->name,colname)) {
if (!g_ascii_strcasecmp(col->name,colname)) {
return mdb_add_sarg(col, in_sarg);
}
}

View File

@@ -95,7 +95,7 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry)
/* grab a copy of the usage map */
pg_row = mdb_get_int32(pg_buf, fmt->tab_usage_map_offset);
mdb_find_pg_row(mdb, pg_row, &buf, &row_start, &(table->map_sz));
table->usage_map = g_memdup(buf + row_start, table->map_sz);
table->usage_map = g_memdup((char*)buf + row_start, table->map_sz);
if (mdb_get_option(MDB_DEBUG_USAGE))
mdb_buffer_dump(buf, row_start, table->map_sz);
mdb_debug(MDB_DEBUG_USAGE,"usage map found on page %ld row %d start %d len %d",
@@ -104,7 +104,7 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry)
/* grab a copy of the free space page map */
pg_row = mdb_get_int32(pg_buf, fmt->tab_free_map_offset);
mdb_find_pg_row(mdb, pg_row, &buf, &row_start, &(table->freemap_sz));
table->free_usage_map = g_memdup(buf + row_start, table->freemap_sz);
table->free_usage_map = g_memdup((char*)buf + row_start, table->freemap_sz);
mdb_debug(MDB_DEBUG_USAGE,"free map found on page %ld row %d start %d len %d\n",
pg_row >> 8, pg_row & 0xff, row_start, table->freemap_sz);
@@ -128,7 +128,7 @@ MdbTableDef *mdb_read_table_by_name(MdbHandle *mdb, gchar *table_name, int obj_t
for (i=0; i<mdb->num_catalog; i++) {
entry = g_ptr_array_index(mdb->catalog, i);
if (!strcasecmp(entry->object_name, table_name))
if (!g_ascii_strcasecmp(entry->object_name, table_name))
return mdb_read_table(entry);
}
@@ -168,6 +168,8 @@ read_pg_if_8(MdbHandle *mdb, int *cur_pos)
void *
read_pg_if_n(MdbHandle *mdb, void *buf, int *cur_pos, size_t len)
{
char* _buf = buf;
/* Advance to page which contains the first byte */
while (*cur_pos >= mdb->fmt->pg_size) {
mdb_read_pg(mdb, mdb_get_int32(mdb->pg_buf,4));
@@ -176,20 +178,20 @@ read_pg_if_n(MdbHandle *mdb, void *buf, int *cur_pos, size_t len)
/* Copy pages into buffer */
while (*cur_pos + len >= mdb->fmt->pg_size) {
int piece_len = mdb->fmt->pg_size - *cur_pos;
if (buf) {
memcpy(buf, mdb->pg_buf + *cur_pos, piece_len);
buf += piece_len;
if (_buf) {
memcpy(_buf, mdb->pg_buf + *cur_pos, piece_len);
_buf += piece_len;
}
len -= piece_len;
mdb_read_pg(mdb, mdb_get_int32(mdb->pg_buf,4));
*cur_pos = 8;
}
/* Copy into buffer from final page */
if (len && buf) {
memcpy(buf, mdb->pg_buf + *cur_pos, len);
if (len && _buf) {
memcpy(_buf, mdb->pg_buf + *cur_pos, len);
}
*cur_pos += len;
return buf;
return _buf;
}

View File

@@ -33,7 +33,7 @@ void
mdb_put_int16(void *buf, guint32 offset, guint32 value)
{
value = GINT32_TO_LE(value);
memcpy(buf + offset, &value, 2);
memcpy((char*)buf + offset, &value, 2);
}
void
_mdb_put_int16(void *buf, guint32 offset, guint32 value)
@@ -47,7 +47,7 @@ void
mdb_put_int32(void *buf, guint32 offset, guint32 value)
{
value = GINT32_TO_LE(value);
memcpy(buf + offset, &value, 4);
memcpy((char*)buf + offset, &value, 4);
}
void
_mdb_put_int32(void *buf, guint32 offset, guint32 value)
@@ -61,7 +61,7 @@ void
mdb_put_int32_msb(void *buf, guint32 offset, guint32 value)
{
value = GINT32_TO_BE(value);
memcpy(buf + offset, &value, 4);
memcpy((char*)buf + offset, &value, 4);
}
void
_mdb_put_int32_mdb(void *buf, guint32 offset, guint32 value)
@@ -194,7 +194,7 @@ mdb_crack_row(MdbTableDef *table, int row_start, int row_end, MdbField *fields)
}
bitmask_sz = (row_cols + 7) / 8;
nullmask = pg_buf + row_end - bitmask_sz + 1;
nullmask = (unsigned char*)pg_buf + row_end - bitmask_sz + 1;
/* read table of variable column locations */
if (table->num_var_cols > 0) {
@@ -235,7 +235,7 @@ mdb_crack_row(MdbTableDef *table, int row_start, int row_end, MdbField *fields)
&& (fixed_cols_found < row_fixed_cols)) {
col_start = col->fixed_offset + col_count_size;
fields[i].start = row_start + col_start;
fields[i].value = pg_buf + row_start + col_start;
fields[i].value = (char*)pg_buf + row_start + col_start;
fields[i].siz = col->col_size;
fixed_cols_found++;
/* Use col->var_col_num because a deleted column is still
@@ -244,7 +244,7 @@ mdb_crack_row(MdbTableDef *table, int row_start, int row_end, MdbField *fields)
&& (col->var_col_num < row_var_cols)) {
col_start = var_col_offsets[col->var_col_num];
fields[i].start = row_start + col_start;
fields[i].value = pg_buf + row_start + col_start;
fields[i].value = (char*)pg_buf + row_start + col_start;
fields[i].siz = var_col_offsets[(col->var_col_num)+1] -
col_start;
} else {
@@ -627,14 +627,14 @@ mdb_add_row_to_pg(MdbTableDef *table, unsigned char *row_buffer, int new_row_siz
for (i=0;i<num_rows;i++) {
mdb_find_row(mdb, i, &row_start, &row_size);
pos -= row_size;
memcpy(new_pg + pos, mdb->pg_buf + row_start, row_size);
memcpy((char*)new_pg + pos, mdb->pg_buf + row_start, row_size);
mdb_put_int16(new_pg, (fmt->row_count_offset + 2) + (i*2), pos);
}
}
/* add our new row */
pos -= new_row_size;
memcpy(new_pg + pos, row_buffer, new_row_size);
memcpy((char*)new_pg + pos, row_buffer, new_row_size);
/* add row to the row offset table */
mdb_put_int16(new_pg, (fmt->row_count_offset + 2) + (num_rows*2), pos);
@@ -747,20 +747,20 @@ int i, pos;
for (i=0;i<row;i++) {
mdb_find_row(mdb, i, &row_start, &row_size);
pos -= row_size;
memcpy(new_pg + pos, mdb->pg_buf + row_start, row_size);
memcpy((char*)new_pg + pos, mdb->pg_buf + row_start, row_size);
mdb_put_int16(new_pg, rco + 2 + i*2, pos);
}
/* our row */
pos -= new_row_size;
memcpy(new_pg + pos, new_row, new_row_size);
memcpy((char*)new_pg + pos, new_row, new_row_size);
mdb_put_int16(new_pg, rco + 2 + row*2, pos);
/* rows after */
for (i=row+1;i<num_rows;i++) {
mdb_find_row(mdb, i, &row_start, &row_size);
pos -= row_size;
memcpy(new_pg + pos, mdb->pg_buf + row_start, row_size);
memcpy((char*)new_pg + pos, mdb->pg_buf + row_start, row_size);
mdb_put_int16(new_pg, rco + 2 + i*2, pos);
}
@@ -838,7 +838,7 @@ mdb_copy_index_pg(MdbTableDef *table, MdbIndex *idx, MdbIndexPage *ipg)
mdb_buffer_dump(key_hash, 0, col->col_size);
}
memcpy(new_pg + ipg->offset, mdb->pg_buf + ipg->offset, ipg->len);
memcpy((char*)new_pg + ipg->offset, mdb->pg_buf + ipg->offset, ipg->len);
ipg->offset += ipg->len;
ipg->len = 0;
@@ -863,7 +863,7 @@ mdb_copy_index_pg(MdbTableDef *table, MdbIndex *idx, MdbIndexPage *ipg)
printf("--------\n");
}
((char *)new_pg)[ipg->offset] = 0x7f;
memcpy(new_pg + ipg->offset + 1, key_hash, col->col_size);
memcpy((char*)new_pg + ipg->offset + 1, key_hash, col->col_size);
pg_row = (pgnum << 8) | ((rownum-1) & 0xff);
mdb_put_int32_msb(new_pg, ipg->offset + 5, pg_row);
ipg->idx_starts[row++] = ipg->offset + ipg->len;