/* CC-0 license. */
/* gcc -o test test.c `pkg-config --cflags --libs glib-2.0` */

#include <glib.h>

/* https://bugzilla.gnome.org/show_bug.cgi?id=793394
 *
 * When run, this will produce:
 *
 * ** Message: 15:51:33.540: Normal form? 1
 * **
 * GLib:ERROR:../../source/glib/glib/gvariant-serialiser.c:167:g_variant_serialised_check: assertion failed (alignment & (gsize) serialised.data == 0): (1 == 0)
 * Aborted (core dumped)
 */

int
main (void)
{
  /* A well-formed serialised variant, with a leading nul byte so we can unalign it. */
  const gchar *_data = "\x00\x4c\x6f\x67\x77\x61\x69\x20\x74\x61\x72\x69\x66\x66"
                       "\x00\x01\x00\x74\x65\x73\x74\x2d\x74\x61\x72\x69\x66"
                       "\x66\x00\x00\x00\x00\x00\x0c\x00\x28\x73\x61\x28\x74"
                       "\x74\x71\x75\x74\x29\x29\x0e";
  const guint8 *data = (const guint8 *) _data + 1;  /* make it unaligned, assuming string constants are aligned on this platform */
  const gsize data_len = 46;

  g_autoptr(GBytes) bytes = g_bytes_new_static (data, data_len);
  g_autoptr(GVariant) variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("(sqv)"), bytes, FALSE);

  g_message ("Normal form? %d", g_variant_is_normal_form (variant));

  /* This should assert. */
  g_variant_get (variant, "(&sqv)", NULL, NULL, NULL);

  g_assert_not_reached ();

  return 0;
}
