girepository: Use expected signed types for iterating

We are using various indexes types, but not always using the correct
sign or size, so let's adapt this to ensure we're consistent with the
values we're comparing with.
This commit is contained in:
Marco Trevisan (Treviño) 2024-01-16 01:57:09 +01:00
parent 91a3399027
commit 25ae968fc2
10 changed files with 35 additions and 37 deletions

View File

@ -51,14 +51,14 @@
GIFunctionInfo * GIFunctionInfo *
gi_base_info_find_method (GIBaseInfo *base, gi_base_info_find_method (GIBaseInfo *base,
uint32_t offset, uint32_t offset,
unsigned n_methods, uint16_t n_methods,
const char *name) const char *name)
{ {
/* FIXME hash */ /* FIXME hash */
GIRealInfo *rinfo = (GIRealInfo*)base; GIRealInfo *rinfo = (GIRealInfo*)base;
Header *header = (Header *)rinfo->typelib->data; Header *header = (Header *)rinfo->typelib->data;
for (unsigned i = 0; i < n_methods; i++) for (uint16_t i = 0; i < n_methods; i++)
{ {
FunctionBlob *fblob = (FunctionBlob *)&rinfo->typelib->data[offset]; FunctionBlob *fblob = (FunctionBlob *)&rinfo->typelib->data[offset];
const char *fname = (const char *)&rinfo->typelib->data[fblob->name]; const char *fname = (const char *)&rinfo->typelib->data[fblob->name];

View File

@ -323,10 +323,10 @@ GISignalInfo *
gi_interface_info_find_signal (GIInterfaceInfo *info, gi_interface_info_find_signal (GIInterfaceInfo *info,
const char *name) const char *name)
{ {
unsigned int n_signals; uint32_t n_signals;
n_signals = gi_interface_info_get_n_signals (info); n_signals = gi_interface_info_get_n_signals (info);
for (unsigned int i = 0; i < n_signals; i++) for (uint32_t i = 0; i < n_signals; i++)
{ {
GISignalInfo *siginfo = gi_interface_info_get_signal (info, i); GISignalInfo *siginfo = gi_interface_info_get_signal (info, i);

View File

@ -72,7 +72,7 @@ gi_object_info_get_field_offset (GIObjectInfo *info,
offset = rinfo->offset + header->object_blob_size offset = rinfo->offset + header->object_blob_size
+ (blob->n_interfaces + blob->n_interfaces % 2) * 2; + (blob->n_interfaces + blob->n_interfaces % 2) * 2;
for (unsigned int i = 0; i < n; i++) for (size_t i = 0; i < n; i++)
{ {
field_blob = (FieldBlob *)&rinfo->typelib->data[offset]; field_blob = (FieldBlob *)&rinfo->typelib->data[offset];
offset += header->field_blob_size; offset += header->field_blob_size;

View File

@ -233,10 +233,10 @@ void gi_type_info_init (GIBaseInfo *info,
GIFunctionInfo * gi_base_info_find_method (GIBaseInfo *base, GIFunctionInfo * gi_base_info_find_method (GIBaseInfo *base,
uint32_t offset, uint32_t offset,
unsigned n_methods, uint16_t n_methods,
const char *name); const char *name);
GIVFuncInfo * gi_base_info_find_vfunc (GIRealInfo *rinfo, GIVFuncInfo * gi_base_info_find_vfunc (GIRealInfo *rinfo,
uint32_t offset, uint32_t offset,
unsigned n_vfuncs, uint16_t n_vfuncs,
const char *name); const char *name);

View File

@ -531,7 +531,7 @@ get_typelib_dependencies_transitive (GIRepository *repository,
immediate_dependencies = get_typelib_dependencies (typelib); immediate_dependencies = get_typelib_dependencies (typelib);
for (unsigned int i = 0; immediate_dependencies != NULL && immediate_dependencies[i]; i++) for (size_t i = 0; immediate_dependencies != NULL && immediate_dependencies[i]; i++)
{ {
char *dependency; char *dependency;
const char *last_dash; const char *last_dash;
@ -1153,7 +1153,7 @@ gi_repository_get_loaded_namespaces (GIRepository *repository)
{ {
GList *l, *list = NULL; GList *l, *list = NULL;
char **names; char **names;
int i; size_t i;
repository = get_repository (repository); repository = get_repository (repository);

View File

@ -175,8 +175,7 @@ gi_callable_info_get_ffi_arg_types (GICallableInfo *callable_info,
{ {
ffi_type **arg_types; ffi_type **arg_types;
gboolean is_method, throws; gboolean is_method, throws;
size_t n_invoke_args; size_t n_args, n_invoke_args, i, offset;
unsigned int n_args, i, offset;
g_return_val_if_fail (callable_info != NULL, NULL); g_return_val_if_fail (callable_info != NULL, NULL);

View File

@ -1047,7 +1047,7 @@ find_entry_node (GIIrTypelibBuild *build,
{ {
GIIrModule *module = build->module; GIIrModule *module = build->module;
GList *l; GList *l;
unsigned int i; size_t i;
unsigned int n_names; unsigned int n_names;
char **names; char **names;
GIIrNode *result = NULL; GIIrNode *result = NULL;
@ -1220,7 +1220,7 @@ serialize_type (GIIrTypelibBuild *build,
GIIrNodeType *node, GIIrNodeType *node,
GString *str) GString *str)
{ {
int i; size_t i;
if (GI_TYPE_TAG_IS_BASIC (node->tag)) if (GI_TYPE_TAG_IS_BASIC (node->tag))
{ {

View File

@ -383,7 +383,9 @@ find_attribute (const char *name,
const char **attribute_names, const char **attribute_names,
const char **attribute_values) const char **attribute_values)
{ {
for (int i = 0; attribute_names[i] != NULL; i++) size_t i;
for (i = 0; attribute_names[i] != NULL; i++)
if (strcmp (attribute_names[i], name) == 0) if (strcmp (attribute_names[i], name) == 0)
return attribute_values[i]; return attribute_values[i];
@ -484,8 +486,8 @@ static BasicTypeInfo basic_types[] = {
static const BasicTypeInfo * static const BasicTypeInfo *
parse_basic (const char *str) parse_basic (const char *str)
{ {
unsigned int i; size_t i;
unsigned int n_basic = G_N_ELEMENTS (basic_types); size_t n_basic = G_N_ELEMENTS (basic_types);
for (i = 0; i < n_basic; i++) for (i = 0; i < n_basic; i++)
{ {

View File

@ -198,7 +198,7 @@ gi_typelib_get_dir_entry_by_name (GITypelib *typelib,
const char *name) const char *name)
{ {
Section *dirindex; Section *dirindex;
int i, n_entries; size_t i, n_entries;
const char *entry_name; const char *entry_name;
DirEntry *entry; DirEntry *entry;
@ -247,9 +247,8 @@ gi_typelib_get_dir_entry_by_gtype_name (GITypelib *typelib,
const char *gtype_name) const char *gtype_name)
{ {
Header *header = (Header *)typelib->data; Header *header = (Header *)typelib->data;
unsigned int i;
for (i = 1; i <= header->n_local_entries; i++) for (size_t i = 1; i <= header->n_local_entries; i++)
{ {
RegisteredTypeBlob *blob; RegisteredTypeBlob *blob;
const char *type; const char *type;
@ -400,11 +399,11 @@ gi_typelib_get_dir_entry_by_error_domain (GITypelib *typelib,
GQuark error_domain) GQuark error_domain)
{ {
Header *header = (Header *)typelib->data; Header *header = (Header *)typelib->data;
unsigned int n_entries = header->n_local_entries; size_t n_entries = header->n_local_entries;
const char *domain_string = g_quark_to_string (error_domain); const char *domain_string = g_quark_to_string (error_domain);
DirEntry *entry; DirEntry *entry;
for (unsigned int i = 1; i <= n_entries; i++) for (size_t i = 1; i <= n_entries; i++)
{ {
EnumBlob *blob; EnumBlob *blob;
const char *enum_domain_string; const char *enum_domain_string;
@ -743,11 +742,11 @@ validate_param_type_blob (GITypelib *typelib,
uint32_t offset, uint32_t offset,
uint32_t signature_offset, uint32_t signature_offset,
gboolean return_type, gboolean return_type,
int n_params, unsigned int n_params,
GError **error) GError **error)
{ {
ParamTypeBlob *blob; ParamTypeBlob *blob;
int i; unsigned int i;
blob = (ParamTypeBlob*)&typelib->data[offset]; blob = (ParamTypeBlob*)&typelib->data[offset];
@ -967,7 +966,7 @@ validate_signature_blob (GITypelib *typelib,
return FALSE; return FALSE;
} }
for (unsigned int i = 0; i < blob->n_arguments; i++) for (size_t i = 0; i < blob->n_arguments; i++)
{ {
if (!validate_arg_blob (typelib, if (!validate_arg_blob (typelib,
offset + sizeof (SignatureBlob) + offset + sizeof (SignatureBlob) +
@ -1336,7 +1335,7 @@ validate_signal_blob (GITypelib *typelib,
GError **error) GError **error)
{ {
SignalBlob *blob; SignalBlob *blob;
int n_signals; size_t n_signals;
if (typelib->len < offset + sizeof (SignalBlob)) if (typelib->len < offset + sizeof (SignalBlob))
{ {
@ -1405,7 +1404,7 @@ validate_vfunc_blob (GITypelib *typelib,
GError **error) GError **error)
{ {
VFuncBlob *blob; VFuncBlob *blob;
int n_vfuncs; size_t n_vfuncs;
if (typelib->len < offset + sizeof (VFuncBlob)) if (typelib->len < offset + sizeof (VFuncBlob))
{ {
@ -1464,7 +1463,7 @@ validate_struct_blob (ValidateContext *ctx,
{ {
GITypelib *typelib = ctx->typelib; GITypelib *typelib = ctx->typelib;
StructBlob *blob; StructBlob *blob;
int i; size_t i;
uint32_t field_offset; uint32_t field_offset;
if (typelib->len < offset + sizeof (StructBlob)) if (typelib->len < offset + sizeof (StructBlob))
@ -1561,7 +1560,6 @@ validate_enum_blob (ValidateContext *ctx,
{ {
GITypelib *typelib = ctx->typelib; GITypelib *typelib = ctx->typelib;
EnumBlob *blob; EnumBlob *blob;
int i;
uint32_t offset2; uint32_t offset2;
if (typelib->len < offset + sizeof (EnumBlob)) if (typelib->len < offset + sizeof (EnumBlob))
@ -1622,7 +1620,7 @@ validate_enum_blob (ValidateContext *ctx,
push_context (ctx, get_string_nofail (typelib, blob->name)); push_context (ctx, get_string_nofail (typelib, blob->name));
for (i = 0; i < blob->n_values; i++, offset2 += sizeof (ValueBlob)) for (size_t i = 0; i < blob->n_values; i++, offset2 += sizeof (ValueBlob))
{ {
if (!validate_value_blob (typelib, if (!validate_value_blob (typelib,
offset2, offset2,
@ -1650,7 +1648,7 @@ validate_enum_blob (ValidateContext *ctx,
#endif #endif
} }
for (i = 0; i < blob->n_methods; i++, offset2 += sizeof (FunctionBlob)) for (size_t i = 0; i < blob->n_methods; i++, offset2 += sizeof (FunctionBlob))
{ {
if (!validate_function_blob (ctx, offset2, BLOB_TYPE_ENUM, error)) if (!validate_function_blob (ctx, offset2, BLOB_TYPE_ENUM, error))
return FALSE; return FALSE;
@ -1669,7 +1667,7 @@ validate_object_blob (ValidateContext *ctx,
GITypelib *typelib = ctx->typelib; GITypelib *typelib = ctx->typelib;
Header *header; Header *header;
ObjectBlob *blob; ObjectBlob *blob;
int i; size_t i;
uint32_t offset2; uint32_t offset2;
uint16_t n_field_callbacks; uint16_t n_field_callbacks;
@ -1871,7 +1869,7 @@ validate_interface_blob (ValidateContext *ctx,
GITypelib *typelib = ctx->typelib; GITypelib *typelib = ctx->typelib;
Header *header; Header *header;
InterfaceBlob *blob; InterfaceBlob *blob;
int i; size_t i;
uint32_t offset2; uint32_t offset2;
header = (Header *)typelib->data; header = (Header *)typelib->data;
@ -2071,7 +2069,7 @@ validate_directory (ValidateContext *ctx,
GITypelib *typelib = ctx->typelib; GITypelib *typelib = ctx->typelib;
Header *header = (Header *)typelib->data; Header *header = (Header *)typelib->data;
DirEntry *entry; DirEntry *entry;
int i; size_t i;
if (typelib->len < header->directory + header->n_entries * sizeof (DirEntry)) if (typelib->len < header->directory + header->n_entries * sizeof (DirEntry))
{ {
@ -2341,7 +2339,6 @@ gi_typelib_do_dlopen (GITypelib *typelib)
if (shlib_str != NULL && shlib_str[0] != '\0') if (shlib_str != NULL && shlib_str[0] != '\0')
{ {
char **shlibs; char **shlibs;
int i;
/* shared-library is a comma-separated list of libraries */ /* shared-library is a comma-separated list of libraries */
shlibs = g_strsplit (shlib_str, ",", 0); shlibs = g_strsplit (shlib_str, ",", 0);
@ -2350,7 +2347,7 @@ gi_typelib_do_dlopen (GITypelib *typelib)
* again with g_module_open(), the same file handle will be returned. See bug: * again with g_module_open(), the same file handle will be returned. See bug:
* http://bugzilla.gnome.org/show_bug.cgi?id=555294 * http://bugzilla.gnome.org/show_bug.cgi?id=555294
*/ */
for (i = 0; shlibs[i]; i++) for (size_t i = 0; shlibs[i]; i++)
{ {
GModule *module; GModule *module;

View File

@ -48,13 +48,13 @@
GIVFuncInfo * GIVFuncInfo *
gi_base_info_find_vfunc (GIRealInfo *rinfo, gi_base_info_find_vfunc (GIRealInfo *rinfo,
uint32_t offset, uint32_t offset,
unsigned n_vfuncs, uint16_t n_vfuncs,
const char *name) const char *name)
{ {
/* FIXME hash */ /* FIXME hash */
Header *header = (Header *)rinfo->typelib->data; Header *header = (Header *)rinfo->typelib->data;
for (unsigned i = 0; i < n_vfuncs; i++) for (uint16_t i = 0; i < n_vfuncs; i++)
{ {
VFuncBlob *fblob = (VFuncBlob *)&rinfo->typelib->data[offset]; VFuncBlob *fblob = (VFuncBlob *)&rinfo->typelib->data[offset];
const char *fname = (const char *)&rinfo->typelib->data[fblob->name]; const char *fname = (const char *)&rinfo->typelib->data[fblob->name];