#include <stdio.h>
#include <my_global.h>
#include <mysql.h>
#include <my_sys.h> /* for all_charsets */


MYSQL mysql;

void check_charsets()
{
  int counter;
  CHARSET_INFO *cs;

  for (counter=0; counter<256; counter++)
    {
      cs = all_charsets[counter]; 
      if (cs == NULL) 
	printf ("NULL ");
      else
	printf ("%s ",cs->csname);
    }
  printf("\n");
}


int main()
{
   mysql_server_init( 0, NULL, NULL );
   mysql_init(&mysql);
   mysql_real_connect(&mysql,NULL,"root","test",NULL,0,NULL,0);
   check_charsets(); 
   mysql_close(&mysql);
   mysql_server_end();
   mysql_server_init( 0, NULL, NULL );
   // all_charsets now contains pointers to unalllocated memory
   // do some malloc()s until we happen to reallocate and overwrite this memory
   mysql_init(&mysql);
   mysql_real_connect(&mysql,NULL,"root","test",NULL,0,NULL,0);
   check_charsets();
   mysql_close(&mysql);
   mysql_server_end();
}
