diff --git a/lib/libnvpair/libnvpair_json.c b/lib/libnvpair/libnvpair_json.c index 37a392391f..15b6f4afaf 100644 --- a/lib/libnvpair/libnvpair_json.c +++ b/lib/libnvpair/libnvpair_json.c @@ -54,6 +54,13 @@ nvlist_print_json_string(FILE *fp, const char *input) FPRINTF(fp, "\""); while ((sz = mbrtowc(&c, input, MB_CUR_MAX, &mbr)) > 0) { + if (sz == (size_t)-1 || sz == (size_t)-2) { + /* + * We last read an invalid multibyte character sequence, + * so return an error. + */ + return (-1); + } switch (c) { case '"': FPRINTF(fp, "\\\""); @@ -97,14 +104,6 @@ nvlist_print_json_string(FILE *fp, const char *input) input += sz; } - if (sz == (size_t)-1 || sz == (size_t)-2) { - /* - * We last read an invalid multibyte character sequence, - * so return an error. - */ - return (-1); - } - FPRINTF(fp, "\""); return (0); }