summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorMitya Selivanov <0x7fffff@guattari.ru>2022-08-21 20:36:36 +0400
committerMitya Selivanov <0x7fffff@guattari.ru>2022-08-21 20:36:36 +0400
commit75e688a31c4566f23087d8f2629b284f865298d0 (patch)
treede321a3c129948e1b3b69c014391559bfc4dd209 /source
parent17c0e154219547a855255e02ff6c5fa513d67866 (diff)
downloadkit-75e688a31c4566f23087d8f2629b284f865298d0.zip
[move_back] no ref for value
Diffstat (limited to 'source')
-rw-r--r--source/kit/move_back.h2
-rw-r--r--source/test/unittests/move_back.test.c22
2 files changed, 8 insertions, 16 deletions
diff --git a/source/kit/move_back.h b/source/kit/move_back.h
index 2df12cd..cf9cb70 100644
--- a/source/kit/move_back.h
+++ b/source/kit/move_back.h
@@ -32,7 +32,7 @@ extern "C" {
ptrdiff_t end_ = (array).size; \
unsigned char temp_[sizeof *(array).values]; \
for (ptrdiff_t i_ = 0; i_ < end_;) { \
- if ((cond) (&(array).values[i_], &(value))) { \
+ if ((cond) ((array).values + i_, (value))) { \
end_--; \
if (i_ != end_) { \
memcpy(temp_, (array).values + end_, \
diff --git a/source/test/unittests/move_back.test.c b/source/test/unittests/move_back.test.c
index df26e03..6799128 100644
--- a/source/test/unittests/move_back.test.c
+++ b/source/test/unittests/move_back.test.c
@@ -7,15 +7,15 @@ static int is_equal(int const x, int const y) {
return x == y;
}
-static int is_equal_ref(int const *const x, int const *const y) {
- return *x == *y;
+static int is_equal_ref(int const *const x, int const y) {
+ return *x == y;
}
static int is_even(int const x, int const _) {
return (x % 2) == 0;
}
-static int is_even_ref(int const *const x, int const *const _) {
+static int is_even_ref(int const *const x, int const _) {
return (*x % 2) == 0;
}
@@ -43,9 +43,7 @@ TEST("move back ref val") {
int *values;
} ref = { .size = sizeof v / sizeof *v, .values = v };
- int const two = 2;
-
- MOVE_BACK_REF(ref.size, ref, two, is_equal_ref);
+ MOVE_BACK_REF(ref.size, ref, 2, is_equal_ref);
REQUIRE(ref.size == 3);
REQUIRE(v[0] == 1);
@@ -109,9 +107,7 @@ TEST("move back ref 1") {
int *values;
} ref = { .size = sizeof v / sizeof *v, .values = v };
- int const nothing = 0;
-
- MOVE_BACK_REF(ref.size, ref, nothing, is_even_ref);
+ MOVE_BACK_REF(ref.size, ref, 0, is_even_ref);
REQUIRE(ref.size == 3);
REQUIRE(v[0] == 1);
@@ -127,9 +123,7 @@ TEST("move back ref 2") {
int *values;
} ref = { .size = sizeof v / sizeof *v, .values = v };
- int const nothing = 0;
-
- MOVE_BACK_REF(ref.size, ref, nothing, is_even_ref);
+ MOVE_BACK_REF(ref.size, ref, 0, is_even_ref);
REQUIRE(ref.size == 3);
REQUIRE(v[0] == 5);
@@ -145,9 +139,7 @@ TEST("move back ref 3") {
int *values;
} ref = { .size = sizeof v / sizeof *v, .values = v };
- int const nothing = 0;
-
- MOVE_BACK_REF(ref.size, ref, nothing, is_even_ref);
+ MOVE_BACK_REF(ref.size, ref, 0, is_even_ref);
REQUIRE(ref.size == 3);
REQUIRE(v[0] == 1);