This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nscd/9750] nscd gc() segmentation fault by estimation failure of alloca()'s stack usage


------- Additional Comments From j-nomura at ce dot jp dot nec dot com  2009-01-29 05:24 -------
In case anyone have archs other than i386/x86_64, try the following test program
to see whether the default alloca_account works.

----------------------------------------------------------------------------
#include <stdio.h>
#include <alloca.h>

#if !defined(alloca_account)
#define alloca_account(size, avar) \
  ({ size_t size__ = (size);       \
     avar += size__;               \
     alloca (size__); })
#endif

int test_alloc_size[] = { 4, 8, 16, 32, 48, 64, 100, };

void
test_alloca(size_t sz)
{
	int i;
	char *cur, *prev;
	int stk_usage = 0, stk_usage_real = 0;

	printf("unit allocation size = %d\n", sz);

	prev = alloca(sz);

	for (i = 0; i < 3; i++) {
		cur = alloca_account(sz, stk_usage);
		stk_usage_real += prev - cur;
		prev = cur;
		printf("#  [%d] stack used: %d (accounted as %d)\n",
			i, stk_usage_real, stk_usage);
	}

	if (stk_usage != stk_usage_real)
		printf("FAIL: accounted usage differs from the real usage\n");
	else
		printf("PASS\n");
	printf("\n");
}

int
main(int argc, char **argv)
{
	int n = 0;

	while (test_alloc_size[n]) {
		test_alloca(test_alloc_size[n]);
		n++;
	}
}
----------------------------------------------------------------------------


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=9750

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]