When posting code, try to make a minimally complete example out of it.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
int check_buf(void *buf, int size, int full_size)
{
if (size / 2 && memcmp(buf, buf + size / 2, size / 2) == 0)
{
if (!check_buf(buf, size / 2, full_size))
{
printf("Mirrored memory.");
assert(0);
}
return 1;
}
else
{
return 0;
}
}
int main()
{
char buff1[] = "ABCDDCBA";
char buff2[] = "12345678";
char buff3[] = "AAAAAAAA";
printf("R1=%d\n", check_buf(buff1, 8, 8));
printf("R2=%d\n", check_buf(buff2, 8, 8));
printf("R3=%d\n", check_buf(buff3, 8, 8));
return 0;
}
$ gcc -Wall foo.c
$ ./a.out
R1=0
R2=0
a.out: foo.c:13: check_buf: Assertion `0' failed.
Aborted (core dumped)
2. Calling assert is dumb.
You do all that work and bomb out with a segfault.
3. Cite your source. I'm assuming you found this code somewhere and are confused.
Knowing the context of how it is used where you found it could be useful.
> Does this code look sane?
The recursion is weird to say the least.
> I'm supposed to be checking mirrored values for card images
Define "mirrored".
To me, two mirrored memory cards would compare identical with a single memcmp.
All this size/2 and recursion is baffling.