Skip to content
Permalink
Browse files
Fix the buggy default array_list equality implementation.
  • Loading branch information
PengZheng committed Dec 30, 2021
1 parent 70d6219 commit 63256a0be0f58d68dafcec1397ff1feebf563542
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifndef CELIX_CELIX_BUILD_ASSERT_H
#define CELIX_CELIX_BUILD_ASSERT_H

#define BUILD_ASSERT(cond) \
do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)

#endif //CELIX_CELIX_BUILD_ASSERT_H
@@ -31,6 +31,7 @@
#include "array_list.h"
#include "celix_array_list.h"
#include "array_list_private.h"
#include "celix_build_assert.h"

static celix_status_t arrayList_elementEquals(const void *a, const void *b, bool *equals);
static bool celix_arrayList_defaultEquals(const celix_array_list_entry_t a, const celix_array_list_entry_t b);
@@ -60,7 +61,8 @@ static celix_status_t arrayList_elementEquals(const void *a, const void *b, bool
}

static bool celix_arrayList_defaultEquals(celix_array_list_entry_t a, celix_array_list_entry_t b) {
return a.longVal == b.longVal; //just compare as long int
BUILD_ASSERT(sizeof(a.voidPtrVal) == sizeof(a));
return a.voidPtrVal== b.voidPtrVal;
}

static bool celix_arrayList_equalsForElement(celix_array_list_t *list, celix_array_list_entry_t a, celix_array_list_entry_t b) {
@@ -495,7 +497,7 @@ void celix_arrayList_removeEntry(celix_array_list_t *list, celix_array_list_entr

void celix_arrayList_remove(celix_array_list_t *list, void *ptr) {
celix_array_list_entry_t entry;
memset(&entry, 0, sizeof(entry));
memset(&entry, 0, sizeof(entry));
entry.voidPtrVal = ptr;
celix_arrayList_removeEntry(list, entry);
}

0 comments on commit 63256a0

Please sign in to comment.