
/*
 gcc $(pkg-config json-glib-1.0 --cflags --libs) json-bad-double-deserialize.c
 */

#include <json-glib/json-glib.h>
#include <string.h>

int
main(void)
{
	GError *error = NULL;
	JsonNode *node;
	GVariant *var;
	JsonGenerator *generator;
	gchar *string;
	JsonParser *parser;

	/* Turn a double variant into a json string */
	var = g_variant_new_double(17);
	node = json_gvariant_serialize(var);
	g_variant_unref (var);
	generator = json_generator_new ();
	json_generator_set_root (generator, node);
	string = json_generator_to_data (generator, NULL);
	g_object_unref (generator);
	json_node_free (node);

	/* Turn json string into a double variant */
	parser = json_parser_new ();
  	json_parser_load_from_data (parser, string, strlen (string), &error);
	g_assert_no_error (error);
	var = json_gvariant_deserialize(json_parser_get_root (parser), "d", &error);
	g_assert_no_error (error);
	g_object_unref (parser);

	/* Lets see what came out */
	g_print ("%s\n", g_variant_print (var, TRUE));
	g_variant_unref (var);

	return 0;
}

