Print this page
5005 libnvpair JSON output broken by lint fixes
5006 libnvpair JSON cannot print int16 arrays
Reviewed by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libnvpair/nvpair_json.c
          +++ new/usr/src/lib/libnvpair/nvpair_json.c
↓ open down ↓ 1 lines elided ↑ open up ↑
   2    2   * This file and its contents are supplied under the terms of the
   3    3   * Common Development and Distribution License ("CDDL"), version 1.0.
   4    4   * You may only use this file in accordance with the terms of version
   5    5   * 1.0 of the CDDL.
   6    6   *
   7    7   * A full copy of the text of the CDDL should have accompanied this
   8    8   * source.  A copy of the CDDL is also available via the Internet at
   9    9   * http://www.illumos.org/license/CDDL.
  10   10   */
  11   11  /*
  12      - * Copyright (c) 2013, Joyent, Inc. All rights reserved.
       12 + * Copyright (c) 2014, Joyent, Inc. All rights reserved.
  13   13   */
  14   14  
  15   15  #include <stdio.h>
  16   16  #include <stdlib.h>
  17   17  #include <strings.h>
  18   18  #include <wchar.h>
  19   19  #include <sys/debug.h>
  20   20  
  21   21  #include "libnvpair.h"
  22   22  
  23      -#define FPRINTF(fp, ...)                        \
  24      -        if (fprintf(fp, __VA_ARGS__) < 0)       \
  25      -                return (-1)                     \
       23 +#define FPRINTF(fp, ...)                                \
       24 +        do {                                            \
       25 +                if (fprintf(fp, __VA_ARGS__) < 0)       \
       26 +                        return (-1);                    \
       27 +        } while (0)
  26   28  
  27   29  /*
  28   30   * When formatting a string for JSON output we must escape certain characters,
  29   31   * as described in RFC4627.  This applies to both member names and
  30   32   * DATA_TYPE_STRING values.
  31   33   *
  32   34   * This function will only operate correctly if the following conditions are
  33   35   * met:
  34   36   *
  35   37   *       1. The input String is encoded in the current locale.
↓ open down ↓ 285 lines elided ↑ open up ↑
 321  323                  }
 322  324  
 323  325                  case DATA_TYPE_INT16_ARRAY: {
 324  326                          int16_t *val;
 325  327                          uint_t valsz, i;
 326  328                          VERIFY0(nvpair_value_int16_array(curr, &val, &valsz));
 327  329                          FPRINTF(fp, "[");
 328  330                          for (i = 0; i < valsz; i++) {
 329  331                                  if (i > 0)
 330  332                                          FPRINTF(fp, ",");
 331      -                                FPRINTF(fp, "%hhd", val[i]);
      333 +                                FPRINTF(fp, "%hd", val[i]);
 332  334                          }
 333  335                          FPRINTF(fp, "]");
 334  336                          break;
 335  337                  }
 336  338  
 337  339                  case DATA_TYPE_UINT32_ARRAY: {
 338  340                          uint32_t *val;
 339  341                          uint_t valsz, i;
 340  342                          VERIFY0(nvpair_value_uint32_array(curr, &val, &valsz));
 341  343                          FPRINTF(fp, "[");
↓ open down ↓ 60 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX