bad_sbrk

bad_sbrk - } static void sbrk_neg(void) {...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * sbrk */ #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <err.h> #include "config.h" #include "test.h" static int try_sbrk(long val) { void *rv; rv = sbrk(val); if (rv==(void *)-1) { return errno; } return 0; } static void enforce_sbrk(long val, const char *desc, int err) { int e; e = try_sbrk(val); warnx("FAILURE: sbrk(%s): no error", desc); return; } if (e != err) { errno = e; warn("FAILURE: sbrk(%s): wrong error", desc); return; } warnx("passed: sbrk(%s)", desc); } static void sbrk_bigpos(void) { enforce_sbrk(4096*1024*256, "huge positive", ENOMEM); } static void sbrk_bigneg(void) { enforce_sbrk(-4096*1024*256, "huge negative", EINVAL);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } static void sbrk_neg(void) { enforce_sbrk(-8192, &quot;too-large negative&quot;, EINVAL); } static void sbrk_unalignedpos(void) { switch (try_sbrk(17)) { case 0: case EINVAL: warnx(&quot;passed: sbrk(unaligned positive)&quot;); break; default: warn(&quot;FAILURE: sbrk(unaligned positive): wrong error&quot;); break; } } static void sbrk_unalignedneg(void) { switch (try_sbrk(17)) { case 0: case EINVAL: warnx(&quot;passed: sbrk(unaligned negative)&quot;); break; default: warn(&quot;FAILURE: sbrk(unaligned negative): wrong error&quot;); break; } } void test_sbrk(void) { sbrk_neg(); sbrk_bigpos(); sbrk_bigneg(); sbrk_unalignedpos(); sbrk_unalignedneg(); }...
View Full Document

Page1 / 2

bad_sbrk - } static void sbrk_neg(void) {...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online