1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-12-04 14:46:31 -05:00

Fix: Corrected bugs related to incorrect check for transparent unions

This commit is contained in:
Philipp Schafft 2019-07-01 12:22:15 +00:00
parent 68332f291f
commit 4a9dd94b07
7 changed files with 18 additions and 13 deletions

View File

@ -97,8 +97,9 @@ int igloo_list_iterator_rewind(igloo_list_iterator_t *iterat
do { \
igloo_list_iterator_storage_t __igloo_list_iterator_storage; \
igloo_list_iterator_t *__igloo_list_iterator = igloo_list_iterator_start((list), &__igloo_list_iterator_storage, sizeof(__igloo_list_iterator_storage)); \
igloo_ro_t __igloo_ret; \
type * var; \
for (; !igloo_RO_IS_NULL((var) = igloo_RO_TO_TYPE(igloo_list_iterator_next(__igloo_list_iterator),type));) { \
for (; !igloo_RO_IS_NULL(__igloo_ret = igloo_list_iterator_next(__igloo_list_iterator)) && ((var) = igloo_RO_TO_TYPE(__igloo_ret,type));) { \
code; \
igloo_ro_unref((var)); \
} \

View File

@ -26,6 +26,7 @@ extern "C" {
#include <stdarg.h>
#include <igloo/config.h>
#include "types.h"
#include "thread.h"
@ -88,11 +89,11 @@ struct igloo_ro_base_tag {
int igloo_ro_new__return_zero(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap);
/* ---[ END PRIVATE ]--- */
#ifdef igloo_HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
#ifdef IGLOO_CTC_HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
#define igloo_RO__GETBASE(x) (((igloo_ro_t)(x)).subtype__igloo_ro_base_t)
#define igloo_RO_NULL ((igloo_ro_t)(igloo_ro_base_t*)NULL)
#define igloo_RO_IS_NULL(x) (igloo_RO__GETBASE((x)) == NULL)
#define igloo_RO_TO_TYPE(x,type) (igloo_RO_IS_VALID((x),type) ? NULL : ((igloo_ro_t)(x)).subtype__ ## type)
#define igloo_RO_TO_TYPE(x,type) (igloo_RO_IS_VALID((x),type) ? ((igloo_ro_t)(x)).subtype__ ## type : NULL)
#else
#define igloo_RO__GETBASE(x) ((igloo_ro_base_t*)(x))
#define igloo_RO_NULL NULL

View File

@ -29,6 +29,8 @@ extern "C" {
/* For size_t and ssize_t */
#include <sys/types.h>
#include <igloo/config.h>
/* Included in case is not yet included */
#include "typedef.h"
@ -49,7 +51,7 @@ typedef struct igloo_reportxml_database_tag igloo_reportxml_database_t;
typedef struct igloo_ro_base_tag igloo_ro_base_t;
igloo_RO_FORWARD_TYPE(igloo_ro_base_t);
#ifdef igloo_HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
#ifdef IGLOO_CTC_HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
typedef union __attribute__ ((__transparent_union__)) {
/* Those are libigloo's own types */
igloo_RO_TYPE(igloo_ro_base_t)

View File

@ -72,5 +72,5 @@ igloo_ro_t igloo_initialize(void)
igloo_initialize__refc++;
return ret;
return (igloo_ro_t)ret;
}

View File

@ -1137,7 +1137,7 @@ static igloo_reportxml_node_t * __reportxml_database_build_node_ext(igloo_r
}
igloo_thread_mutex_lock(&(db->lock));
if (igloo_avl_get_by_key(db->definitions, igloo_RO_TO_TYPE(search, void *), (void**)&found) != 0) {
if (igloo_avl_get_by_key(db->definitions, (void*)search, (void**)&found) != 0) {
igloo_thread_mutex_unlock(&(db->lock));
igloo_ro_unref(search);
return NULL;

View File

@ -147,9 +147,8 @@ int igloo_ro_unref(igloo_ro_t self)
return -1;
}
if (base->refc > 1) {
base->refc--;
if (base->refc) {
igloo_thread_mutex_unlock(&(base->lock));
return 0;
}
@ -157,6 +156,8 @@ int igloo_ro_unref(igloo_ro_t self)
if (base->type->type_freecb)
base->type->type_freecb(self);
base->refc--;
igloo_ro_unref(base->associated);
if (base->name)

View File

@ -152,21 +152,21 @@ static void test_sizes(void)
{
igloo_ro_t a;
a = igloo_ro_new(ctest_test_type_a_t);
a = (igloo_ro_t)igloo_ro_new(ctest_test_type_a_t);
ctest_test("refobject created with size=sizeof(igloo_ro_base_t) + 1024", !igloo_RO_IS_NULL(a));
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
a = igloo_ro_new(ctest_test_type_b_t);
a = (igloo_ro_t)igloo_ro_new(ctest_test_type_b_t);
ctest_test("refobject created with size=sizeof(igloo_ro_base_t) + 131072", !igloo_RO_IS_NULL(a));
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
a = igloo_ro_new(ctest_test_type_c_t);
a = (igloo_ro_t)igloo_ro_new(ctest_test_type_c_t);
ctest_test("refobject created with size=sizeof(igloo_ro_base_t) - 1", igloo_RO_IS_NULL(a));
if (!igloo_RO_IS_NULL(a)) {
ctest_test("un-referenced", igloo_ro_unref(a) == 0);
}
a = igloo_ro_new(ctest_test_type_d_t);
a = (igloo_ro_t)igloo_ro_new(ctest_test_type_d_t);
ctest_test("refobject created with size=0", igloo_RO_IS_NULL(a));
if (!igloo_RO_IS_NULL(a)) {
ctest_test("un-referenced", igloo_ro_unref(a) == 0);