Back to index

glibc  2.9
tst-obprintf.c
Go to the documentation of this file.
00001 #include <mcheck.h>
00002 #include <obstack.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 
00006 
00007 int
00008 main (void)
00009 {
00010   struct obstack ob;
00011   int n;
00012 
00013   mcheck_pedantic (NULL);
00014 
00015 #define obstack_chunk_alloc malloc
00016 #define obstack_chunk_free free
00017 
00018   obstack_init (&ob);
00019 
00020   for (n = 0; n < 40000; ++n)
00021     {
00022       mcheck_check_all ();
00023       obstack_printf (&ob, "%.*s%05d", 1 + n % 7, "foobarbaz", n);
00024       if (n % 777 == 0)
00025        obstack_finish (&ob);
00026     }
00027 
00028   /* Another loop where we finish all objects, each of size 1.  This will
00029      manage to call `obstack_print' with all possible positions inside
00030      an obstack chunk.  */
00031   for (n = 0; n < 40000; ++n)
00032     {
00033       mcheck_check_all ();
00034       obstack_printf (&ob, "%c", 'a' + n % 26);
00035       obstack_finish (&ob);
00036     }
00037 
00038   /* And a final check.  */
00039   mcheck_check_all ();
00040 
00041   return 0;
00042 }