Print this page
Rich's feedback

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libsysdemangle/common/cxx_util.c
          +++ new/usr/src/lib/libdemangle/common/cxx_util.c
↓ open down ↓ 10 lines elided ↑ open up ↑
  11   11  
  12   12  /*
  13   13   * Copyright 2017 Jason King
  14   14   */
  15   15  
  16   16  #include <sys/debug.h>
  17   17  #include <sys/sysmacros.h>
  18   18  #include <string.h>
  19   19  #include <errno.h>
  20   20  #include <stdlib.h>
  21      -#include "sysdemangle_int.h"
       21 +#include "demangle_int.h"
  22   22  #include "cxx.h"
  23   23  
  24   24  #define CHUNK_SIZE  (8U)
  25   25  
  26   26  /*
  27   27   * A name_t is essentially a stack of str_pair_t's.  Generally, the parsing
  28   28   * code will push (via name_add() or the like) portions of the demangled
  29   29   * name into a name_t, and periodically combine them via name_join().
  30   30   *
  31   31   * As such it should be noted that since items are added at the end of
↓ open down ↓ 39 lines elided ↑ open up ↑
  71   71  name_clear(name_t *n)
  72   72  {
  73   73          if (n == NULL)
  74   74                  return;
  75   75  
  76   76          for (size_t i = 0; i < n->nm_len; i++) {
  77   77                  str_pair_t *sp = &n->nm_items[i];
  78   78                  sysdem_ops_t *ops = sp->strp_l.str_ops;
  79   79  
  80   80                  str_pair_fini(sp);
  81      -                str_pair_init(sp, ops);
       81 +                (void) str_pair_init(sp, ops);
  82   82          }
  83   83  
  84   84          n->nm_len = 0;
  85   85  }
  86   86  
  87   87  static boolean_t
  88   88  name_reserve(name_t *n, size_t amt)
  89   89  {
  90   90          size_t newlen = n->nm_len + amt;
  91   91  
↓ open down ↓ 31 lines elided ↑ open up ↑
 123  123          str_set(&sl, l, l_len);
 124  124          str_set(&sr, r, r_len);
 125  125          return (name_add_str(n, &sl, &sr));
 126  126  }
 127  127  
 128  128  boolean_t
 129  129  name_add_str(name_t *n, str_t *l, str_t *r)
 130  130  {
 131  131          str_pair_t sp;
 132  132  
 133      -        str_pair_init(&sp, n->nm_ops);
      133 +        (void) str_pair_init(&sp, n->nm_ops);
 134  134  
 135  135          if (!name_reserve(n, 1))
 136  136                  return (B_FALSE);
 137  137  
 138  138          if (l != NULL) {
 139  139                  sp.strp_l = *l;
 140  140                  (void) memset(l, 0, sizeof (*l));
 141  141          }
 142  142  
 143  143          if (r != NULL) {
↓ open down ↓ 46 lines elided ↑ open up ↑
 190  190          size_t seplen = strlen(sep);
 191  191  
 192  192          VERIFY3U(amt, <=, n->nm_len);
 193  193  
 194  194          /*
 195  195           * A join of 0 elements places an empty string on the stack.  This
 196  196           * simplifies code that wants to do things like:
 197  197           *   name_join(...); name_fmt(.., "({0})", ...)
 198  198           */
 199  199          if (amt == 0) {
 200      -                name_add(n, "", 0, "", 0);
      200 +                (void) name_add(n, "", 0, "", 0);
 201  201                  return (B_TRUE);
 202  202          }
 203  203  
 204  204          /* A join of 1 element just implies merging the top str_pair_t */
 205  205          if (amt == 1) {
 206  206                  VERIFY3U(name_len(n), >, 0);
 207  207                  return (str_pair_merge(name_top(n)));
 208  208          }
 209  209  
 210  210          (void) str_init(&res, n->nm_ops);
↓ open down ↓ 29 lines elided ↑ open up ↑
 240  240  name_fmt_s(name_t *n, str_t *s, const char *fmt, long *maxp)
 241  241  {
 242  242          const char *p;
 243  243          long max = -1;
 244  244  
 245  245          if (fmt == NULL)
 246  246                  return (B_TRUE);
 247  247  
 248  248          for (p = fmt; *p != '\0'; p++) {
 249  249                  if (*p != '{') {
 250      -                        str_append_c(s, *p);
      250 +                        (void) str_append_c(s, *p);
 251  251                          continue;
 252  252                  }
 253  253  
 254  254                  errno = 0;
 255  255                  char *q = NULL;
 256  256                  long val = strtol(p + 1, &q, 10);
 257  257  
 258  258                  VERIFY(val != 0 || errno == 0);
 259  259                  VERIFY3U(val, <, n->nm_len);
 260  260  
↓ open down ↓ 162 lines elided ↑ open up ↑
 423  423          if (!name_reserve(dest, depth)) {
 424  424                  name_fini(dest);
 425  425                  sub->sub_len--;
 426  426                  return (B_FALSE);
 427  427          }
 428  428  
 429  429          const str_pair_t *src_sp = name_at(n, depth - 1);
 430  430  
 431  431          for (size_t i = 0; i < depth; i++, src_sp++) {
 432  432                  str_pair_t copy = { 0 };
 433      -                str_pair_init(&copy, n->nm_ops);
      433 +                (void) str_pair_init(&copy, n->nm_ops);
 434  434                  if (!str_pair_copy(src_sp, &copy)) {
 435  435                          str_pair_fini(&copy);
 436  436                          name_fini(dest);
 437  437                          return (B_FALSE);
 438  438                  }
 439  439  
 440  440                  VERIFY(name_add_str(dest, &copy.strp_l, &copy.strp_r));
 441  441          }
 442  442  
 443  443          return (B_TRUE);
↓ open down ↓ 157 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX