Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mono] Fix C4018 round I #70417

Merged
merged 12 commits into from
Jun 15, 2022
2 changes: 1 addition & 1 deletion src/mono/mono/component/debugger-state-machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ mono_debugger_state (JsonWriter *writer)
mono_json_writer_object_key(writer, "breakpoints");
mono_json_writer_array_begin (writer);

for (int i=0; i < breakpoint_copy->len; i++) {
for (guint i=0; i < breakpoint_copy->len; i++) {
MonoBreakpoint *bp = (MonoBreakpoint *) g_ptr_array_index (breakpoint_copy, i);

mono_json_writer_indent (writer);
Expand Down
8 changes: 4 additions & 4 deletions src/mono/mono/component/hot_reload-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void
hot_reload_stub_cleanup_on_close (MonoImage *image);

static void
hot_reload_stub_effective_table_slow (const MonoTableInfo **t, int idx);
hot_reload_stub_effective_table_slow (const MonoTableInfo **t, uint32_t idx);

static void
hot_reload_stub_close_except_pools_all (MonoImage *base_image);
Expand All @@ -62,7 +62,7 @@ hot_reload_stub_get_updated_method_ppdb (MonoImage *base_image, uint32_t idx);
static gboolean
hot_reload_stub_has_modified_rows (const MonoTableInfo *table);

static int
static guint32
hot_reload_stub_table_num_rows_slow (MonoImage *image, int table_index);

static uint32_t
Expand Down Expand Up @@ -183,7 +183,7 @@ hot_reload_stub_cleanup_on_close (MonoImage *image)
}

void
hot_reload_stub_effective_table_slow (const MonoTableInfo **t, int idx)
hot_reload_stub_effective_table_slow (const MonoTableInfo **t, uint32_t idx)
{
g_assert_not_reached ();
}
Expand Down Expand Up @@ -234,7 +234,7 @@ hot_reload_stub_has_modified_rows (const MonoTableInfo *table)
return FALSE;
}

static int
static guint32
hot_reload_stub_table_num_rows_slow (MonoImage *image, int table_index)
{
g_assert_not_reached (); /* should always take the fast path */
Expand Down
8 changes: 4 additions & 4 deletions src/mono/mono/component/hot_reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void
hot_reload_cleanup_on_close (MonoImage *image);

static void
hot_reload_effective_table_slow (const MonoTableInfo **t, int idx);
hot_reload_effective_table_slow (const MonoTableInfo **t, uint32_t idx);

static void
hot_reload_apply_changes (int origin, MonoImage *base_image, gconstpointer dmeta, uint32_t dmeta_len, gconstpointer dil, uint32_t dil_len, gconstpointer dpdb_bytes_orig, uint32_t dpdb_length, MonoError *error);
Expand Down Expand Up @@ -92,7 +92,7 @@ hot_reload_get_updated_method_ppdb (MonoImage *base_image, uint32_t idx);
static gboolean
hot_reload_has_modified_rows (const MonoTableInfo *table);

static int
static guint32
hot_reload_table_num_rows_slow (MonoImage *image, int table_index);

static GSList*
Expand Down Expand Up @@ -1041,7 +1041,7 @@ effective_table_mutant (MonoImage *base, BaselineInfo *info, int tbl_index, cons
}

void
hot_reload_effective_table_slow (const MonoTableInfo **t, int idx)
hot_reload_effective_table_slow (const MonoTableInfo **t, uint32_t idx G_GNUC_UNUSED)
{
/* FIXME: don't let any thread other than the updater thread see values from a delta image
* with a generation past update_published
Expand Down Expand Up @@ -2678,7 +2678,7 @@ hot_reload_has_modified_rows (const MonoTableInfo *table)
return info->any_modified_rows[tbl_index];
}

static int
static guint32
hot_reload_table_num_rows_slow (MonoImage *base, int table_index)
{
BaselineInfo *base_info = baseline_info_lookup (base);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/component/hot_reload.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef struct _MonoComponentHotReload {
uint32_t (*thread_expose_published) (void);
uint32_t (*get_thread_generation) (void);
void (*cleanup_on_close) (MonoImage *image);
void (*effective_table_slow) (const MonoTableInfo **t, int idx);
void (*effective_table_slow) (const MonoTableInfo **t, uint32_t idx);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
void (*apply_changes) (int origin, MonoImage *base_image, gconstpointer dmeta, uint32_t dmeta_len, gconstpointer dil, uint32_t dil_len, gconstpointer dpdb_bytes_orig, uint32_t dpdb_length, MonoError *error);
void (*image_close_except_pools_all) (MonoImage *base_image);
void (*image_close_all) (MonoImage *base_image);
Expand All @@ -32,7 +32,7 @@ typedef struct _MonoComponentHotReload {
gboolean (*delta_heap_lookup) (MonoImage *base_image, MetadataHeapGetterFunc get_heap, uint32_t orig_index, MonoImage **image_out, uint32_t *index_out);
gpointer (*get_updated_method_ppdb) (MonoImage *base_image, uint32_t idx);
gboolean (*has_modified_rows) (const MonoTableInfo *table);
gboolean (*table_num_rows_slow) (MonoImage *base_image, int table_index);
uint32_t (*table_num_rows_slow) (MonoImage *base_image, int table_index);
uint32_t (*method_parent) (MonoImage *base_image, uint32_t method_index);
void* (*metadata_linear_search) (MonoImage *base_image, MonoTableInfo *base_table, const void *key, BinarySearchComparer comparer);
uint32_t (*field_parent) (MonoImage *base_image, uint32_t method_index);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eglib/garray.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ g_array_set_size (GArray *array, gint length)
if (length == priv->capacity)
return; // nothing to be done

if (length > priv->capacity) {
if (GINT_TO_UINT(length) > priv->capacity) {
// grow the array
ensure_capacity (priv, length);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eglib/gfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ g_file_set_contents (const gchar *filename, const gchar *contents, gssize length
if (length < 0)
length = strlen (contents);

if (fwrite (contents, 1, length, fp) < length) {
if (fwrite (contents, 1, length, fp) < GSSIZE_TO_SIZE(length)) {
g_set_error (err, G_FILE_ERROR, g_file_error_from_errno (ferror (fp)), "%s", g_strerror (ferror (fp)));
g_unlink (path);
g_free (path);
Expand Down
8 changes: 8 additions & 0 deletions src/mono/mono/eglib/glib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,9 @@ __CAST_STYPE_TO_UTYPE(gssize, guint32, UINT32_MAX)
__CAST_STYPE_TO_STYPE(gssize, gint, INT_MIN, INT_MAX)
__CAST_STYPE_TO_UTYPE(gssize, guint, UINT_MAX)

__CAST_STYPE_TO_UTYPE(gssize, gsize, SIZE_MAX)
__CAST_UTYPE_TO_STYPE(gsize, gssize, PTRDIFF_MIN, PTRDIFF_MAX)

__CAST_STYPE_TO_STYPE(gdouble, gint64, INT64_MIN, INT64_MAX)
__CAST_STYPE_TO_UTYPE(gdouble, guint64, UINT64_MAX)
__CAST_STYPE_TO_STYPE(gdouble, gint32, INT32_MIN, INT32_MAX)
Expand Down Expand Up @@ -1487,6 +1490,7 @@ __CAST_STYPE_TO_UTYPE(gint32, guint8, UINT8_MAX)

__CAST_STYPE_TO_UTYPE(gint32, guint, UINT_MAX)

__CAST_UTYPE_TO_UTYPE(guint32, guint, UINT_MAX)
__CAST_UTYPE_TO_STYPE(guint32, gint32, INT32_MIN, INT32_MAX)
__CAST_UTYPE_TO_STYPE(guint32, gint16, INT16_MIN, INT16_MAX)
__CAST_UTYPE_TO_UTYPE(guint32, guint16, UINT16_MAX)
Expand Down Expand Up @@ -1617,6 +1621,9 @@ __CAST_UTYPE_TO_STYPE(gunichar, gchar, CHAR_MIN, CHAR_MAX)
#define GSSIZE_TO_INT(v) G_CAST_TYPE_TO_TYPE(gssize, gint, v)
#define GSSIZE_TO_UINT(v) G_CAST_TYPE_TO_TYPE(gssize, guint, v)

#define GSSIZE_TO_SIZE(v) G_CAST_TYPE_TO_TYPE(gssize, gsize, v)
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
#define GSIZE_TO_SSIZE(v) G_CAST_TYPE_TO_TYPE(gsize, gssize, v)

#define GDOUBLE_TO_INT64(v) G_CAST_TYPE_TO_TYPE(gdouble, gint64, v)
#define GDOUBLE_TO_UINT64(v) G_CAST_TYPE_TO_TYPE(gdouble, guint64, v)
#define GDOUBLE_TO_INT32(v) G_CAST_TYPE_TO_TYPE(gdouble, gint32, v)
Expand Down Expand Up @@ -1670,6 +1677,7 @@ __CAST_UTYPE_TO_STYPE(gunichar, gchar, CHAR_MIN, CHAR_MAX)

#define GINT32_TO_UINT(v) G_CAST_TYPE_TO_TYPE(gint32, guint, v)

#define GUINT32_TO_UINT(v) G_CAST_TYPE_TO_TYPE(guint32, guint, v)
#define GUINT32_TO_INT32(v) G_CAST_TYPE_TO_TYPE(guint32, gint32, v)
#define GUINT32_TO_INT16(v) G_CAST_TYPE_TO_TYPE(guint32, gint16, v)
#define GUINT32_TO_UINT16(v) G_CAST_TYPE_TO_TYPE(guint32, guint16, v)
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eglib/gptrarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ gboolean
g_ptr_array_find (GPtrArray *array, gconstpointer needle, guint *index)
{
g_assert (array);
for (int i = 0; i < array->len; i++) {
for (guint i = 0; i < array->len; i++) {
if (array->pdata [i] == needle) {
if (index)
*index = i;
Expand Down
10 changes: 5 additions & 5 deletions src/mono/mono/eventpipe/ep-rt-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ eventpipe_fire_method_events (
il_offsets = (uint32_t*)events_data->buffer;
native_offsets = il_offsets + offset_entries;

for (int32_t offset_count = 0; offset_count < offset_entries; ++offset_count) {
for (uint32_t offset_count = 0; offset_count < offset_entries; ++offset_count) {
il_offsets [offset_count] = debug_info->line_numbers [offset_count].il_offset;
native_offsets [offset_count] = debug_info->line_numbers [offset_count].native_offset;
}
Expand Down Expand Up @@ -3106,7 +3106,7 @@ ep_rt_mono_fire_bulk_type_event (BulkTypeEventLogger *type_logger)

char *ptr = (char *)type_logger->bulk_type_event_buffer;

for (int type_value_index = 0; type_value_index < type_logger->bulk_type_value_count; type_value_index++) {
for (uint32_t type_value_index = 0; type_value_index < type_logger->bulk_type_value_count; type_value_index++) {
BulkTypeValue *target = &type_logger->bulk_type_values [type_value_index];

values_element_size += write_event_buffer_int64 (target->fixed_sized_data.type_id, ptr, &ptr);
Expand All @@ -3120,7 +3120,7 @@ ep_rt_mono_fire_bulk_type_event (BulkTypeEventLogger *type_logger)

values_element_size += write_event_buffer_int32 (target->type_parameters_count, ptr, &ptr);

for (int i = 0; i < target->type_parameters_count; i++) {
for (uint32_t i = 0; i < target->type_parameters_count; i++) {
uint64_t type_parameter = get_typeid_for_type (target->mono_type_parameters [i]);
values_element_size += write_event_buffer_int64 ((int64_t)type_parameter, ptr, &ptr);
}
Expand Down Expand Up @@ -3413,7 +3413,7 @@ ep_rt_mono_send_method_details_event (MonoMethod *method)
method_inst_parameter_types_count = method_inst->type_argc;

uint64_t *method_inst_parameters_type_ids = mono_mempool_alloc0 (type_logger->mem_pool, method_inst_parameter_types_count * sizeof (uint64_t));
for (int i = 0; i < method_inst_parameter_types_count; i++) {
for (uint32_t i = 0; i < method_inst_parameter_types_count; i++) {
method_inst_parameters_type_ids [i] = get_typeid_for_type (method_inst->type_argv [i]);

ep_rt_mono_log_type_and_parameters_if_necessary (type_logger, method_inst->type_argv [i]);
Expand Down Expand Up @@ -3524,7 +3524,7 @@ ep_rt_mono_write_event_method_il_to_native_map (
}
if (il_offsets) {
native_offsets = il_offsets + offset_entries;
for (int32_t offset_count = 0; offset_count < offset_entries; ++offset_count) {
for (uint32_t offset_count = 0; offset_count < offset_entries; ++offset_count) {
il_offsets [offset_count] = debug_info->line_numbers [offset_count].il_offset;
native_offsets [offset_count] = debug_info->line_numbers [offset_count].native_offset;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eventpipe/ep-rt-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ ep_rt_temp_path_get (

const ep_char8_t *path = g_get_tmp_dir ();
int32_t result = snprintf (buffer, buffer_len, "%s", path);
if (result <= 0 || result > buffer_len)
if (result <= 0 || GINT32_TO_UINT32(result) > buffer_len)
ep_raise_error ();

if (buffer [result - 1] != G_DIR_SEPARATOR) {
Expand Down
36 changes: 18 additions & 18 deletions src/mono/mono/metadata/class-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token, MonoError
MonoClass *klass, *parent = NULL;
guint32 cols [MONO_TYPEDEF_SIZE];
guint32 cols_next [MONO_TYPEDEF_SIZE];
guint tidx = mono_metadata_token_index (type_token);
guint32 tidx = mono_metadata_token_index (type_token);
MonoGenericContext *context = NULL;
const char *name, *nspace;
guint icount = 0;
Expand Down Expand Up @@ -2020,7 +2020,8 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_
int i;
const int top = mono_class_get_field_count (klass);
guint32 layout = mono_class_get_flags (klass) & TYPE_ATTRIBUTE_LAYOUT_MASK;
guint32 pass, passes, real_size;
guint32 pass, passes;
gint32 real_size;
gboolean gc_aware_layout = FALSE;
gboolean has_static_fields = FALSE;
gboolean has_references = FALSE;
Expand Down Expand Up @@ -2270,8 +2271,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_
case TYPE_ATTRIBUTE_EXPLICIT_LAYOUT: {
real_size = 0;
for (i = 0; i < top; i++) {
gint32 align;
guint32 size;
gint32 align, size;
MonoType *ftype;

field = &klass->fields [i];
Expand Down Expand Up @@ -2815,7 +2815,7 @@ mono_get_unique_iid (MonoClass *klass)

iid = mono_bitset_find_first_unset (global_interface_bitset, -1);
if (iid < 0) {
int old_size = mono_bitset_size (global_interface_bitset);
guint32 old_size = mono_bitset_size (global_interface_bitset);
MonoBitSet *new_set = mono_bitset_clone (global_interface_bitset, old_size * 2);
mono_bitset_free (global_interface_bitset);
global_interface_bitset = new_set;
Expand All @@ -2825,7 +2825,7 @@ mono_get_unique_iid (MonoClass *klass)
/* set the bit also in the per-image set */
if (!mono_class_is_ginst (klass)) {
if (klass->image->interface_bitset) {
if (iid >= mono_bitset_size (klass->image->interface_bitset)) {
if (GINT_TO_UINT32(iid) >= mono_bitset_size (klass->image->interface_bitset)) {
MonoBitSet *new_set = mono_bitset_clone (klass->image->interface_bitset, iid + 1);
mono_bitset_free (klass->image->interface_bitset);
klass->image->interface_bitset = new_set;
Expand Down Expand Up @@ -3567,12 +3567,11 @@ mono_class_setup_methods (MonoClass *klass)
void
mono_class_setup_properties (MonoClass *klass)
{
guint startm, endm, i, j;
guint startm, endm;
guint32 cols [MONO_PROPERTY_SIZE];
MonoTableInfo *msemt = &klass->image->tables [MONO_TABLE_METHODSEMANTICS];
MonoProperty *properties;
guint32 last;
int first, count;
guint32 first, last, count;
MonoClassPropertyInfo *info;

info = mono_class_get_property_info (klass);
Expand All @@ -3590,7 +3589,7 @@ mono_class_setup_properties (MonoClass *klass)
MonoClassPropertyInfo *ginfo = mono_class_get_property_info (gklass);
properties = mono_class_new0 (klass, MonoProperty, ginfo->count + 1);

for (i = 0; i < ginfo->count; i++) {
for (guint32 i = 0; i < ginfo->count; i++) {
ERROR_DECL (error);
MonoProperty *prop = &properties [i];

Expand All @@ -3611,6 +3610,7 @@ mono_class_setup_properties (MonoClass *klass)
count = ginfo->count;
} else {
first = mono_metadata_properties_from_typedef (klass->image, mono_metadata_token_index (klass->type_token) - 1, &last);
g_assert ((last - first) >= 0);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
count = last - first;

if (count) {
Expand All @@ -3620,15 +3620,15 @@ mono_class_setup_properties (MonoClass *klass)
}

properties = (MonoProperty *)mono_class_alloc0 (klass, sizeof (MonoProperty) * count);
for (i = first; i < last; ++i) {
for (guint32 i = first; i < last; ++i) {
mono_metadata_decode_table_row (klass->image, MONO_TABLE_PROPERTY, i, cols, MONO_PROPERTY_SIZE);
properties [i - first].parent = klass;
properties [i - first].attrs = cols [MONO_PROPERTY_FLAGS];
properties [i - first].name = mono_metadata_string_heap (klass->image, cols [MONO_PROPERTY_NAME]);

startm = mono_metadata_methods_from_property (klass->image, i, &endm);
int first_idx = mono_class_get_first_method_idx (klass);
for (j = startm; j < endm; ++j) {
for (guint j = startm; j < endm; ++j) {
MonoMethod *method;

mono_metadata_decode_row (msemt, j, cols, MONO_METHOD_SEMA_SIZE);
Expand Down Expand Up @@ -3690,11 +3690,10 @@ inflate_method_listz (MonoMethod **methods, MonoClass *klass, MonoGenericContext
void
mono_class_setup_events (MonoClass *klass)
{
int first, count;
guint startm, endm, i, j;
guint32 first, last, count;
guint startm, endm;
guint32 cols [MONO_EVENT_SIZE];
MonoTableInfo *msemt = &klass->image->tables [MONO_TABLE_METHODSEMANTICS];
guint32 last;
MonoEvent *events;

MonoClassEventInfo *info = mono_class_get_event_info (klass);
Expand All @@ -3718,7 +3717,7 @@ mono_class_setup_events (MonoClass *klass)
if (count)
context = mono_class_get_context (klass);

for (i = 0; i < count; i++) {
for (guint32 i = 0; i < count; i++) {
ERROR_DECL (error);
MonoEvent *event = &events [i];
MonoEvent *gevent = &ginfo->events [i];
Expand All @@ -3739,6 +3738,7 @@ mono_class_setup_events (MonoClass *klass)
}
} else {
first = mono_metadata_events_from_typedef (klass->image, mono_metadata_token_index (klass->type_token) - 1, &last);
g_assert ((last - first) >= 0);
count = last - first;

if (count) {
Expand All @@ -3749,7 +3749,7 @@ mono_class_setup_events (MonoClass *klass)
}

events = (MonoEvent *)mono_class_alloc0 (klass, sizeof (MonoEvent) * count);
for (i = first; i < last; ++i) {
for (guint32 i = first; i < last; ++i) {
MonoEvent *event = &events [i - first];

mono_metadata_decode_table_row (klass->image, MONO_TABLE_EVENT, i, cols, MONO_EVENT_SIZE);
Expand All @@ -3759,7 +3759,7 @@ mono_class_setup_events (MonoClass *klass)

startm = mono_metadata_methods_from_event (klass->image, i, &endm);
int first_idx = mono_class_get_first_method_idx (klass);
for (j = startm; j < endm; ++j) {
for (guint j = startm; j < endm; ++j) {
MonoMethod *method;

mono_metadata_decode_row (msemt, j, cols, MONO_METHOD_SEMA_SIZE);
Expand Down
Loading