--- JSON-XS/XS.xs 2007/05/09 16:33:53 1.31 +++ JSON-XS/XS.xs 2007/05/09 16:41:12 1.32 @@ -1011,16 +1011,7 @@ *dec.end = 0; // this should basically be a nop, too, but make sure it's there sv = decode_sv (&dec); - if (offset_return || !sv) - { - offset = dec.flags & F_UTF8 - ? dec.cur - SvPVX (string) - : utf8_distance (dec.cur, SvPVX (string)); - - if (offset_return) - *offset_return = offset; - } - else + if (!(offset_return || !sv)) { // check for trailing garbage decode_ws (&dec); @@ -1033,6 +1024,16 @@ } } + if (offset_return || !sv) + { + offset = dec.flags & F_UTF8 + ? dec.cur - SvPVX (string) + : utf8_distance (dec.cur, SvPVX (string)); + + if (offset_return) + *offset_return = offset; + } + if (!sv) { SV *uni = sv_newmortal ();