* [C++ PATCH] class method vector
@ 2017-06-16 14:52 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2017-06-16 14:52 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 339 bytes --]
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
[-- Attachment #2: mvec.diff --]
[-- Type: text/x-patch, Size: 1586 bytes --]
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);
+ }
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-06-16 14:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-16 14:52 [C++ PATCH] class method vector Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).