X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fvalue-variant.c;h=7c85786f6c1745a2b7d0cb281c3022612109b055;hb=65d602ed236d685ffec00ad1552a193cf47b2e4d;hp=0789717ab70e91ac162e36b359dd5877d79ae758;hpb=17ca35e4ca8abf4ba0c0ae82920b985fa17648cf;p=pspp diff --git a/src/ui/gui/value-variant.c b/src/ui/gui/value-variant.c index 0789717ab7..7c85786f6c 100644 --- a/src/ui/gui/value-variant.c +++ b/src/ui/gui/value-variant.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2016 Free Software Foundation + Copyright (C) 2016, 2020 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,11 +17,9 @@ #include #include -#include #include "value-variant.h" #include "data/value.h" - enum { IDX_WIDTH, @@ -40,20 +38,11 @@ value_variant_new (const union value *in, int width) if (width == 0) vv[IDX_DATA] = g_variant_new_double (in->f); - else if (width <= MAX_SHORT_STRING) - { - char xx[MAX_SHORT_STRING + 1]; - memset (xx, '\0', MAX_SHORT_STRING + 1); - memcpy (xx, in->short_string, width); - vv[IDX_DATA] = g_variant_new_bytestring (xx); - } else { - gchar *q = xmalloc (width + 1); - memcpy (q, in->long_string, width); - q[width] = '\0'; - vv[IDX_DATA] = g_variant_new_from_data (G_VARIANT_TYPE_BYTESTRING, q, - width + 1, FALSE, NULL, NULL); + vv[IDX_DATA] = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + in->s, width, + sizeof (gchar)); } return g_variant_new_tuple (vv, 2); @@ -86,13 +75,13 @@ value_variant_get (union value *val, GVariant *v) val->f = g_variant_get_double (vdata); else { - const gchar *data = g_variant_get_bytestring (vdata); - if (width <= MAX_SHORT_STRING) - memcpy (val->short_string, data, MAX_SHORT_STRING); - else - { - val->long_string = xmemdup (data, width); - } + gsize w; + const gchar *data = + g_variant_get_fixed_array (vdata, &w, sizeof (gchar)); + + if (w != width) + g_critical ("Value variant's width does not match its array size"); + val->s = xmemdup (data, w); } g_variant_unref (vdata);