]> granicus.if.org Git - libevent/commitdiff
Do a memberwise comparison of threading function tables
authorNate R <nate_r@example.com>
Tue, 24 Jan 2012 22:15:50 +0000 (17:15 -0500)
committerNick Mathewson <nickm@torproject.org>
Tue, 24 Jan 2012 22:15:50 +0000 (17:15 -0500)
Doing a memcmp risks comparing uninitialized padding bytes at the
end of the structure.

evthread.c

index 734b77c53b7d2052f512abfc0711cdd97de59082..765d73466f0da637c274626a6cabcdd24d30475e 100644 (file)
@@ -84,7 +84,12 @@ evthread_set_lock_callbacks(const struct evthread_lock_callbacks *cbs)
        }
        if (target->alloc) {
                /* Uh oh; we already had locking callbacks set up.*/
-               if (!memcmp(target, cbs, sizeof(_evthread_lock_fns))) {
+               if (target->lock_api_version == cbs->lock_api_version &&
+                       target->supported_locktypes == cbs->supported_locktypes &&
+                       target->alloc == cbs->alloc &&
+                       target->free == cbs->free &&
+                       target->lock == cbs->lock &&
+                       target->unlock == cbs->unlock) {
                        /* no change -- allow this. */
                        return 0;
                }
@@ -117,7 +122,11 @@ evthread_set_condition_callbacks(const struct evthread_condition_callbacks *cbs)
        }
        if (target->alloc_condition) {
                /* Uh oh; we already had condition callbacks set up.*/
-               if (!memcmp(target, cbs, sizeof(_evthread_cond_fns))) {
+               if (target->condition_api_version == cbs->condition_api_version &&
+                       target->alloc_condition == cbs->alloc_condition &&
+                       target->free_condition == cbs->free_condition &&
+                       target->signal_condition == cbs->signal_condition &&
+                       target->wait_condition == cbs->wait_condition) {
                        /* no change -- allow this. */
                        return 0;
                }