This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] class method vector
- From: Nathan Sidwell <nathan at acm dot org>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 16 Jun 2017 10:52:01 -0400
- Subject: [C++ PATCH] class method vector
- Authentication-results: sourceware.org; auth=none
The class method vector needs resorting on PCH readin, and module
readback. It suffered an unfortunate signed/unsigned comparison
collision, that I hit. Reworked to be made safer.
Of course this thing should really be a hash table + vector of type
conversions, but that's another story.
applied to trunk.
nathan
--
Nathan Sidwell
2017-06-16 Nathan Sidwell <nathan@acm.org>
* class.c (resort_type_method_vec): Avoid potential unsigned
overflow.
Index: class.c
===================================================================
--- class.c (revision 249264)
+++ class.c (working copy)
@@ -2328,25 +2328,25 @@ resort_type_method_vec (void* obj,
gt_pointer_operator new_value,
void* cookie)
{
- vec<tree, va_gc> *method_vec = (vec<tree, va_gc> *) obj;
- int len = vec_safe_length (method_vec);
- size_t slot;
- tree fn;
+ if (vec<tree, va_gc> *method_vec = (vec<tree, va_gc> *) obj)
+ {
+ int len = method_vec->length ();
+ int slot;
- /* The type conversion ops have to live at the front of the vec, so we
- can't sort them. */
- for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
- vec_safe_iterate (method_vec, slot, &fn);
- ++slot)
- if (!DECL_CONV_FN_P (OVL_FIRST (fn)))
- break;
+ /* The type conversion ops have to live at the front of the vec, so we
+ can't sort them. */
+ for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
+ slot < len; slot++)
+ if (!DECL_CONV_FN_P (OVL_FIRST ((*method_vec)[slot])))
+ break;
- if (len - slot > 1)
- {
- resort_data.new_value = new_value;
- resort_data.cookie = cookie;
- qsort (method_vec->address () + slot, len - slot, sizeof (tree),
- resort_method_name_cmp);
+ if (len > slot + 1)
+ {
+ resort_data.new_value = new_value;
+ resort_data.cookie = cookie;
+ qsort (method_vec->address () + slot, len - slot, sizeof (tree),
+ resort_method_name_cmp);
+ }
}
}