1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Migrate from astyle to clang-format (#8464)

This commit is contained in:
Maxim Prokhorov
2022-02-20 19:23:33 +03:00
committed by Max Prokhorov
parent 46190b61f1
commit 19b7a29720
241 changed files with 15925 additions and 16197 deletions

View File

@ -55,140 +55,132 @@
#define TOO_MANY_ERRORS 11
int errors = 0;
#define DEBUGP \
if (errors == TOO_MANY_ERRORS) \
printf ("Further errors omitted\n"); \
else if (errors < TOO_MANY_ERRORS) \
printf
#define DEBUGP \
if (errors == TOO_MANY_ERRORS) \
printf("Further errors omitted\n"); \
else if (errors < TOO_MANY_ERRORS) \
printf
/* A safe target-independent memmove. */
void
mymemmove (unsigned char *dest, unsigned char *src, size_t n)
void mymemmove(unsigned char* dest, unsigned char* src, size_t n)
{
if ((src <= dest && src + n <= dest)
|| src >= dest)
while (n-- > 0)
*dest++ = *src++;
else
if ((src <= dest && src + n <= dest) || src >= dest)
while (n-- > 0)
*dest++ = *src++;
else
{
dest += n;
src += n;
while (n-- > 0)
*--dest = *--src;
dest += n;
src += n;
while (n-- > 0)
*--dest = *--src;
}
}
/* It's either the noinline attribute or forcing the test framework to
pass -fno-builtin-memmove. */
void
xmemmove (unsigned char *dest, unsigned char *src, size_t n)
__attribute__ ((__noinline__));
void xmemmove(unsigned char* dest, unsigned char* src, size_t n) __attribute__((__noinline__));
void
xmemmove (unsigned char *dest, unsigned char *src, size_t n)
void xmemmove(unsigned char* dest, unsigned char* src, size_t n)
{
void *retp;
retp = memmove (dest, src, n);
void* retp;
retp = memmove(dest, src, n);
if (retp != dest)
if (retp != dest)
{
errors++;
DEBUGP ("memmove of n bytes returned %p instead of dest=%p\n",
retp, dest);
errors++;
DEBUGP("memmove of n bytes returned %p instead of dest=%p\n", retp, dest);
}
}
/* Fill the array with something we can associate with a position, but
not exactly the same as the position index. */
void
fill (unsigned char dest[MAX*3])
void fill(unsigned char dest[MAX * 3])
{
size_t i;
for (i = 0; i < MAX*3; i++)
dest[i] = (10 + i) % MAX;
size_t i;
for (i = 0; i < MAX * 3; i++)
dest[i] = (10 + i) % MAX;
}
void memmove_main(void)
{
size_t i;
int errors = 0;
size_t i;
int errors = 0;
/* Leave some room before and after the area tested, so we can detect
overwrites of up to N bytes, N being the amount tested. If you
want to test using valgrind, make these malloced instead. */
unsigned char from_test[MAX*3];
unsigned char to_test[MAX*3];
unsigned char from_known[MAX*3];
unsigned char to_known[MAX*3];
/* Leave some room before and after the area tested, so we can detect
overwrites of up to N bytes, N being the amount tested. If you
want to test using valgrind, make these malloced instead. */
unsigned char from_test[MAX * 3];
unsigned char to_test[MAX * 3];
unsigned char from_known[MAX * 3];
unsigned char to_known[MAX * 3];
/* Non-overlap. */
for (i = 0; i < MAX; i++)
/* Non-overlap. */
for (i = 0; i < MAX; i++)
{
/* Do the memmove first before setting the known array, so we know
it didn't change any of the known array. */
fill (from_test);
fill (to_test);
xmemmove (to_test + MAX, 1 + from_test + MAX, i);
/* Do the memmove first before setting the known array, so we know
it didn't change any of the known array. */
fill(from_test);
fill(to_test);
xmemmove(to_test + MAX, 1 + from_test + MAX, i);
fill (from_known);
fill (to_known);
mymemmove (to_known + MAX, 1 + from_known + MAX, i);
fill(from_known);
fill(to_known);
mymemmove(to_known + MAX, 1 + from_known + MAX, i);
if (memcmp (to_known, to_test, sizeof (to_known)) != 0)
{
errors++;
DEBUGP ("memmove failed non-overlap test for %d bytes\n", i);
}
if (memcmp(to_known, to_test, sizeof(to_known)) != 0)
{
errors++;
DEBUGP("memmove failed non-overlap test for %d bytes\n", i);
}
}
/* Overlap-from-before. */
for (i = 0; i < MAX; i++)
/* Overlap-from-before. */
for (i = 0; i < MAX; i++)
{
size_t j;
for (j = 0; j < i; j++)
{
fill (to_test);
xmemmove (to_test + MAX * 2 - i, to_test + MAX * 2 - i - j, i);
size_t j;
for (j = 0; j < i; j++)
{
fill(to_test);
xmemmove(to_test + MAX * 2 - i, to_test + MAX * 2 - i - j, i);
fill (to_known);
mymemmove (to_known + MAX * 2 - i, to_known + MAX * 2 - i - j, i);
fill(to_known);
mymemmove(to_known + MAX * 2 - i, to_known + MAX * 2 - i - j, i);
if (memcmp (to_known, to_test, sizeof (to_known)) != 0)
{
errors++;
DEBUGP ("memmove failed for %d bytes,"
" with src %d bytes before dest\n",
i, j);
}
}
if (memcmp(to_known, to_test, sizeof(to_known)) != 0)
{
errors++;
DEBUGP("memmove failed for %d bytes,"
" with src %d bytes before dest\n",
i, j);
}
}
}
/* Overlap-from-after. */
for (i = 0; i < MAX; i++)
/* Overlap-from-after. */
for (i = 0; i < MAX; i++)
{
size_t j;
for (j = 0; j < i; j++)
{
fill (to_test);
xmemmove (to_test + MAX, to_test + MAX + j, i);
size_t j;
for (j = 0; j < i; j++)
{
fill(to_test);
xmemmove(to_test + MAX, to_test + MAX + j, i);
fill (to_known);
mymemmove (to_known + MAX, to_known + MAX + j, i);
fill(to_known);
mymemmove(to_known + MAX, to_known + MAX + j, i);
if (memcmp (to_known, to_test, sizeof (to_known)) != 0)
{
errors++;
DEBUGP ("memmove failed when moving %d bytes,"
" with src %d bytes after dest\n",
i, j);
}
}
if (memcmp(to_known, to_test, sizeof(to_known)) != 0)
{
errors++;
DEBUGP("memmove failed when moving %d bytes,"
" with src %d bytes after dest\n",
i, j);
}
}
}
if (errors != 0)
abort ();
printf("ok\n");
if (errors != 0)
abort();
printf("ok\n");
}