builtin-stringop-chk-2.c [plain text]
#include "../gcc.c-torture/execute/builtins/chk.h"
void *bar (int);
extern void *malloc (__SIZE_TYPE__);
struct A
{
int i, j, k;
};
void
foo (const struct A *x, int y, const unsigned char *z)
{
unsigned int b;
unsigned char *c = 0;
b = (x->i & 0xff) == 1 ? 3 : 4;
if (y)
c = bar (x->j * x->k);
const unsigned char *d = z;
unsigned char *e = c;
unsigned char *f = c + x->j * x->k;
int g = 0;
while (e < f)
{
unsigned int h = *d++;
if (h & 128)
{
h = h - 128;
g = e + h * b > f;
if (g)
h = (f - e) / b;
if (b < 4)
do
{
memcpy (e, d, 3);
e += 3;
}
while (--h);
else
do
{
memcpy (e, d, 4);
e += 4;
}
while (--h);
d += b;
}
else
{
h *= b;
g = e + h > f;
if (g)
h = f - e;
memcpy (e, d, h);
e += h;
d += h;
}
}
}
unsigned char *
baz (const struct A *x, const unsigned char *z)
{
unsigned int b;
unsigned char *c = 0;
b = (x->i & 0xff) == 1 ? 3 : 4;
c = malloc (512);
const unsigned char *d = z;
unsigned char *e = c;
unsigned char *f = c + x->j * x->k;
int g = 0;
while (e < f)
{
unsigned int h = *d++;
if (h & 128)
{
h = h - 128;
g = e + h * b > f;
if (g)
h = (f - e) / b;
if (b < 4)
do
{
memcpy (e, d, 3);
e += 3;
}
while (--h);
else
do
{
memcpy (e, d, 513);
e += 4;
}
while (--h);
d += b;
}
else
{
h *= b;
g = e + h > f;
if (g)
h = f - e;
memcpy (e, d, h);
e += 16;
d += h;
}
}
return c;
}