Print this page
Address Robert's feedback

*** 17,27 **** #include <sys/sysmacros.h> #include <string.h> #include <errno.h> #include <stdlib.h> #include "sysdemangle_int.h" ! #include "cpp.h" #define CHUNK_SIZE (8U) /* * A name_t is essentially a stack of str_pair_t's. Generally, the parsing --- 17,27 ---- #include <sys/sysmacros.h> #include <string.h> #include <errno.h> #include <stdlib.h> #include "sysdemangle_int.h" ! #include "cxx.h" #define CHUNK_SIZE (8U) /* * A name_t is essentially a stack of str_pair_t's. Generally, the parsing
*** 149,178 **** return (B_TRUE); } str_pair_t * ! name_at(name_t *n, size_t idx) { ! if (n->nm_len == 0) ! return (NULL); ! ! ASSERT3U(idx, <=, n->nm_len); return (&n->nm_items[n->nm_len - idx - 1]); } str_pair_t * name_top(name_t *n) { return (name_at(n, 0)); } ! str_pair_t * name_pop(name_t *n, str_pair_t *sp) { if (n->nm_len == 0) ! return (NULL); str_pair_t *top = name_top(n); if (sp != NULL) { *sp = *top; --- 149,176 ---- return (B_TRUE); } str_pair_t * ! name_at(const name_t *n, size_t idx) { ! VERIFY(!name_empty(n)); ! VERIFY3U(idx, <, n->nm_len); return (&n->nm_items[n->nm_len - idx - 1]); } str_pair_t * name_top(name_t *n) { return (name_at(n, 0)); } ! void name_pop(name_t *n, str_pair_t *sp) { if (n->nm_len == 0) ! return; str_pair_t *top = name_top(n); if (sp != NULL) { *sp = *top;
*** 180,200 **** } else { str_pair_fini(top); } n->nm_len--; - return (sp); } boolean_t name_join(name_t *n, size_t amt, const char *sep) { str_pair_t *sp = NULL; str_t res = { 0 }; size_t seplen = strlen(sep); ! ASSERT3U(amt, <=, n->nm_len); /* * A join of 0 elements places an empty string on the stack. This * simplifies code that wants to do things like: * name_join(...); name_fmt(.., "({0})", ...) --- 178,197 ---- } else { str_pair_fini(top); } n->nm_len--; } boolean_t name_join(name_t *n, size_t amt, const char *sep) { str_pair_t *sp = NULL; str_t res = { 0 }; size_t seplen = strlen(sep); ! VERIFY3U(amt, <=, n->nm_len); /* * A join of 0 elements places an empty string on the stack. This * simplifies code that wants to do things like: * name_join(...); name_fmt(.., "({0})", ...)
*** 204,214 **** return (B_TRUE); } /* A join of 1 element just implies merging the top str_pair_t */ if (amt == 1) { ! ASSERT3U(name_len(n), >, 0); return (str_pair_merge(name_top(n))); } (void) str_init(&res, n->nm_ops); --- 201,211 ---- return (B_TRUE); } /* A join of 1 element just implies merging the top str_pair_t */ if (amt == 1) { ! VERIFY3U(name_len(n), >, 0); return (str_pair_merge(name_top(n))); } (void) str_init(&res, n->nm_ops);
*** 226,236 **** sp++; } for (size_t i = 0; i < amt; i++) ! (void) name_pop(n, NULL); /* since we've removed at least 1 entry, this should always succeed */ VERIFY(name_add_str(n, &res, NULL)); return (B_TRUE); --- 223,233 ---- sp++; } for (size_t i = 0; i < amt; i++) ! name_pop(n, NULL); /* since we've removed at least 1 entry, this should always succeed */ VERIFY(name_add_str(n, &res, NULL)); return (B_TRUE);
*** 256,267 **** errno = 0; char *q = NULL; long val = strtol(p + 1, &q, 10); ! ASSERT(val != 0 || errno == 0); ! ASSERT3U(val, <, n->nm_len); str_pair_t *sp = name_at(n, val); if (val > max) max = val; --- 253,264 ---- errno = 0; char *q = NULL; long val = strtol(p + 1, &q, 10); ! VERIFY(val != 0 || errno == 0); ! VERIFY3U(val, <, n->nm_len); str_pair_t *sp = name_at(n, val); if (val > max) max = val;
*** 297,307 **** return (B_TRUE); } /* ! * replace a number of elements in the name stack with a formatted string * for format is a plain string with optional {nnn} or {nnn:L|R} substitutions * where nnn is the stack position of an element and it's contents (both * left and right pieces) are inserted. Optionally, only the left or * right piece can specified using :L|R e.g. {2:L}{3}{2:R} would insert * the left piece of element 2, all of element 3, then the right piece of --- 294,304 ---- return (B_TRUE); } /* ! * Replace a number of elements in the name stack with a formatted string * for format is a plain string with optional {nnn} or {nnn:L|R} substitutions * where nnn is the stack position of an element and it's contents (both * left and right pieces) are inserted. Optionally, only the left or * right piece can specified using :L|R e.g. {2:L}{3}{2:R} would insert * the left piece of element 2, all of element 3, then the right piece of
*** 329,339 **** if (!name_fmt_s(n, &res.strp_r, fmt_r, &max)) goto error; if (max >= 0) { for (size_t i = 0; i <= max; i++) ! (void) name_pop(n, NULL); } n->nm_items[n->nm_len++] = res; return (B_TRUE); --- 326,336 ---- if (!name_fmt_s(n, &res.strp_r, fmt_r, &max)) goto error; if (max >= 0) { for (size_t i = 0; i <= max; i++) ! name_pop(n, NULL); } n->nm_items[n->nm_len++] = res; return (B_TRUE);
*** 427,437 **** name_fini(dest); sub->sub_len--; return (B_FALSE); } ! const str_pair_t *src_sp = name_at((name_t *)n, depth - 1); for (size_t i = 0; i < depth; i++, src_sp++) { str_pair_t copy = { 0 }; str_pair_init(&copy, n->nm_ops); if (!str_pair_copy(src_sp, &copy)) { --- 424,434 ---- name_fini(dest); sub->sub_len--; return (B_FALSE); } ! const str_pair_t *src_sp = name_at(n, depth - 1); for (size_t i = 0; i < depth; i++, src_sp++) { str_pair_t copy = { 0 }; str_pair_init(&copy, n->nm_ops); if (!str_pair_copy(src_sp, &copy)) {
*** 448,458 **** /* push substitution idx onto n */ boolean_t sub_substitute(const sub_t *sub, size_t idx, name_t *n) { ! ASSERT3U(idx, <, sub->sub_len); const name_t *src = &sub->sub_items[idx]; const str_pair_t *sp = src->nm_items; size_t save = name_len(n); --- 445,455 ---- /* push substitution idx onto n */ boolean_t sub_substitute(const sub_t *sub, size_t idx, name_t *n) { ! VERIFY3U(idx, <, sub->sub_len); const name_t *src = &sub->sub_items[idx]; const str_pair_t *sp = src->nm_items; size_t save = name_len(n);
*** 468,478 **** return (B_TRUE); fail: for (size_t i = 0; i < name_len(n) - save; i++) ! (void) name_pop(n, NULL); return (B_FALSE); } void sub_pop(sub_t *sub) --- 465,475 ---- return (B_TRUE); fail: for (size_t i = 0; i < name_len(n) - save; i++) ! name_pop(n, NULL); return (B_FALSE); } void sub_pop(sub_t *sub)
*** 540,550 **** } void templ_pop(templ_t *tpl) { ! ASSERT(!templ_empty(tpl)); sub_t *sub = &tpl->tpl_items[--tpl->tpl_len]; sub_fini(sub); } --- 537,547 ---- } void templ_pop(templ_t *tpl) { ! VERIFY(!templ_empty(tpl)); sub_t *sub = &tpl->tpl_items[--tpl->tpl_len]; sub_fini(sub); }
*** 579,589 **** } boolean_t templ_save(const name_t *n, size_t amt, templ_t *tpl) { ! ASSERT3U(tpl->tpl_len, >, 0); sub_t *s = templ_top(tpl); boolean_t res = B_TRUE; /* a bit of a hack -- want an 'empty' entry when saving 0 params */ --- 576,586 ---- } boolean_t templ_save(const name_t *n, size_t amt, templ_t *tpl) { ! VERIFY3U(tpl->tpl_len, >, 0); sub_t *s = templ_top(tpl); boolean_t res = B_TRUE; /* a bit of a hack -- want an 'empty' entry when saving 0 params */