X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=perl-module%2FPSPP.xs;h=e80b3cf22baf01ecd6c63cab928f7230a317a611;hb=f15c854d8500105766b2f5666bb62b983ff24f88;hp=13386588b62c9738a6346a758717da61937cdb82;hpb=5c3291dc396b795696e94f47780308fd7ace6fc4;p=pspp-builds.git diff --git a/perl-module/PSPP.xs b/perl-module/PSPP.xs index 13386588..e80b3cf2 100644 --- a/perl-module/PSPP.xs +++ b/perl-module/PSPP.xs @@ -177,9 +177,7 @@ CODE: union value uv; char *s; make_value_from_scalar (&uv, val, var); - s = malloc (fmt->w); - memset (s, '\0', fmt->w); - data_out (&uv, fmt, s); + s = data_out (&uv, fmt); value_destroy (&uv, var_get_width (var)); ret = newSVpv (s, fmt->w); free (s); @@ -404,26 +402,27 @@ INIT: sv_setpv (errstr, ""); CODE: union value the_value; + int width = var_get_width (var); + int ok; + value_init (&the_value, width); if ( var_is_numeric (var)) { if ( ! looks_like_number (key)) { sv_setpv (errstr, "Cannot add label with string key to a numeric variable"); + value_destroy (&the_value, width); XSRETURN_IV (0); } the_value.f = SvNV (key); } else { - if ( var_is_long_string (var) ) - { - sv_setpv (errstr, "Cannot add label to a long string variable"); - XSRETURN_IV (0); - } - strncpy (the_value.short_string, SvPV_nolen(key), MAX_SHORT_STRING); + value_copy_str_rpad (&the_value, width, SvPV_nolen(key), ' '); } - if (! var_add_value_label (var, &the_value, label) ) + ok = var_add_value_label (var, &the_value, label); + value_destroy (&the_value, width); + if (!ok) { sv_setpv (errstr, "Something went wrong"); XSRETURN_IV (0);