Skip to content

Commit

Permalink
Remove hidden static in rz_str_pad
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio authored and XVilka committed Jan 6, 2024
1 parent 00b1b93 commit a9131ce
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 52 deletions.
14 changes: 8 additions & 6 deletions librz/analysis/reflines.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,9 @@ static void add_spaces(RzBuffer *b, int level, int pos, bool wide) {
level *= 2;
}
if (pos > level + 1) {
const char *pd = rz_str_pad(' ', pos - level - 1);
rz_buf_append_string(b, pd);
char *pad = rz_str_pad(' ', pos - level - 1);
rz_buf_append_string(b, pad);
free(pad);
}
}
}
Expand All @@ -313,15 +314,16 @@ static void fill_level(RzBuffer *b, int pos, char ch, RzAnalysisRefline *r, bool
if (wide) {
sz *= 2;
}
const char *pd = rz_str_pad(ch, sz - 1);
char *pad = rz_str_pad(ch, sz - 1);
if (pos == -1) {
rz_buf_append_string(b, pd);
rz_buf_append_string(b, pad);
} else {
int pdlen = strlen(pd);
int pdlen = strlen(pad);
if (pdlen > 0) {
rz_buf_write_at(b, pos, (const ut8 *)pd, pdlen);
rz_buf_write_at(b, pos, (const ut8 *)pad, pdlen);
}
}
free(pad);
}

static inline bool refline_kept(RzAnalysisRefline *ref, bool middle_after, ut64 addr) {
Expand Down
4 changes: 3 additions & 1 deletion librz/cons/dietline.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,9 @@ static void selection_widget_draw(void) {
} else {
pos_y = rz_cons_get_cur_line();
if (pos_y + sel_widget->h > cons->rows) {
printf("%s\n", rz_str_pad('\n', sel_widget->h));
char *pad = rz_str_pad('\n', sel_widget->h);
printf("%s\n", pad);
free(pad);
pos_y = cons->rows - sel_widget->h - 1;
}
}
Expand Down
6 changes: 4 additions & 2 deletions librz/core/cmd/cmd_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -2804,12 +2804,13 @@ RZ_IPI RzCmdStatus rz_analysis_function_vars_stackframe_handler(RzCore *core, in
if (p->storage.type != RZ_ANALYSIS_VAR_STORAGE_STACK) {
continue;
}
const char *pad = rz_str_pad(' ', 10 - strlen(p->name));
char *pad = rz_str_pad(' ', 10 - strlen(p->name));
char *ptype = rz_type_as_string(core->analysis->typedb, p->type);
st64 off = p->storage.stack_off;
char sign = off < 0 ? '-' : '+';
rz_cons_printf("%c0x%08" PFMT64x " %s:%s%s\n", sign, RZ_ABS(off), p->name, pad, ptype);
free(ptype);
free(pad);
}
rz_pvector_free(vars);
return RZ_CMD_STATUS_OK;
Expand Down Expand Up @@ -5824,8 +5825,9 @@ RZ_IPI RzCmdStatus rz_list_mne_handler(RzCore *core, int argc, const char **argv
*nl = 0;
char *desc = rz_asm_describe(core->rasm, ptr);
if (desc) {
const char *pad = rz_str_pad(' ', 16 - strlen(ptr));
char *pad = rz_str_pad(' ', 16 - strlen(ptr));
rz_cons_printf("%s%s%s\n", ptr, pad, desc);
free(pad);
free(desc);
} else {
rz_cons_printf("%s\n", ptr);
Expand Down
3 changes: 2 additions & 1 deletion librz/core/cmd/cmd_cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ static bool core_cmp_bits(RzCore *core, RzCompareData *cmp) {
const char *color_end = scr_color ? Color_RESET : "";
if (rz_config_get_i(core->config, "hex.header")) {
char *n = rz_str_newf("0x%08" PFMT64x, cmp->addr1);
const char *extra = rz_str_pad(' ', strlen(n) - 10);
char *extra = rz_str_pad(' ', strlen(n) - 10);
free(n);
rz_cons_printf("%s- offset -%s 7 6 5 4 3 2 1 0%s\n", color, extra, color_end);
free(extra);
}
color = scr_color ? pal->graph_false : "";
color_end = scr_color ? Color_RESET : "";
Expand Down
4 changes: 3 additions & 1 deletion librz/core/cmd/cmd_flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ static void __printRecursive(RzCore *core, RzList /*<RzFlagItem *>*/ *flags, con
rz_cons_printf("agn %s %s\n", fn, fn + name_len);
rz_cons_printf("age %s %s\n", RZ_STR_ISNOTEMPTY(name) ? name : "root", fn);
} else {
rz_cons_printf("%s %s\n", rz_str_pad(' ', name_len), fn + name_len);
char *pad = rz_str_pad(' ', name_len);
rz_cons_printf("%s %s\n", pad, fn + name_len);
free(pad);
}
// rz_cons_printf (".fg %s\n", fn);
__printRecursive(core, flags, fn, mode, depth + 1);
Expand Down
3 changes: 2 additions & 1 deletion librz/core/cmd/cmd_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ RZ_IPI RzCmdStatus rz_list_rizin_vars_handler(RzCore *core, int argc, const char
if (argc > 1 && strcmp(argv[1], var->name)) {
continue;
}
const char *pad = rz_str_pad(' ', 6 - strlen(var->name));
char *pad = rz_str_pad(' ', 6 - strlen(var->name));
if (wideOffsets) {
rz_cons_printf("%s %s 0x%016" PFMT64x "\n", var->name, pad, rz_num_math(core->num, var->name));
} else {
rz_cons_printf("%s %s 0x%08" PFMT64x "\n", var->name, pad, rz_num_math(core->num, var->name));
}
free(pad);
}
return RZ_CMD_STATUS_OK;
}
Expand Down
12 changes: 8 additions & 4 deletions librz/core/cmd/cmd_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -3151,23 +3151,26 @@ RZ_API void rz_print_offset_sg(RzPrint *p, ut64 off, int invert, int offseg, int
if (label) {
const int label_padding = 10;
if (delta > 0) {
const char *pad = rz_str_pad(' ', sz - sz2 + label_padding);
char *pad = rz_str_pad(' ', sz - sz2 + label_padding);
if (offdec) {
rz_cons_printf("%s%s%s%s+%d%s", k, inv, label, reset, delta, pad);
} else {
rz_cons_printf("%s%s%s%s+0x%x%s", k, inv, label, reset, delta, pad);
}
free(pad);
} else {
const char *pad = rz_str_pad(' ', sz + label_padding);
char *pad = rz_str_pad(' ', sz + label_padding);
rz_cons_printf("%s%s%s%s%s", k, inv, label, reset, pad);
free(pad);
}
} else {
const char *pad = rz_str_pad(' ', sz - sz2);
char *pad = rz_str_pad(' ', sz - sz2);
if (offdec) {
rz_cons_printf("%s+%d%s", pad, delta, reset);
} else {
rz_cons_printf("%s+0x%x%s", pad, delta, reset);
}
free(pad);
}
} else {
if (offdec) {
Expand Down Expand Up @@ -3197,13 +3200,14 @@ RZ_API void rz_print_offset_sg(RzPrint *p, ut64 off, int invert, int offseg, int
} else {
int sz = lenof(off, 0);
int sz2 = lenof(delta, 1);
const char *pad = rz_str_pad(' ', sz - 5 - sz2 - 3);
if (delta > 0) {
char *pad = rz_str_pad(' ', sz - 5 - sz2 - 3);
if (offdec) {
rz_cons_printf("%s+%d%s", pad, delta, reset);
} else {
rz_cons_printf("%s+0x%x%s", pad, delta, reset);
}
free(pad);
} else {
if (offdec) {
snprintf(space, sizeof(space), "%" PFMT64u, off);
Expand Down
8 changes: 4 additions & 4 deletions librz/core/cmd/cmd_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,20 +772,20 @@ RZ_API RZ_OWN char *rz_core_clippy(RZ_NONNULL RzCore *core, RZ_NONNULL const cha
}
const char *f;
int msglen = rz_str_len_utf8(msg);
char *s = strdup(rz_str_pad(' ', msglen));
char *s = rz_str_pad(' ', msglen);
char *l;

if (type == RZ_AVATAR_ORANGG) {
l = strdup(rz_str_pad('-', msglen));
l = rz_str_pad('-', msglen);
f = avatar_orangg[0];
} else if (type == RZ_AVATAR_CYBCAT) {
l = strdup(rz_str_pad('-', msglen));
l = rz_str_pad('-', msglen);
f = avatar_cybcat[rz_num_rand32(RZ_ARRAY_SIZE(avatar_cybcat))];
} else if (rz_config_get_i(core->config, "scr.utf8")) {
l = (char *)rz_str_repeat("─", msglen);
f = avatar_clippy_utf8[rz_num_rand32(RZ_ARRAY_SIZE(avatar_clippy_utf8))];
} else {
l = strdup(rz_str_pad('-', msglen));
l = rz_str_pad('-', msglen);
f = avatar_clippy[rz_num_rand32(RZ_ARRAY_SIZE(avatar_clippy))];
}

Expand Down
4 changes: 3 additions & 1 deletion librz/core/cprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ static inline char *ut64_to_hex(const ut64 x, const ut8 width) {
rz_strbuf_appendf(sb, "%" PFMT64x, x);
ut8 len = rz_strbuf_length(sb);
if (len < width) {
rz_strbuf_prepend(sb, rz_str_pad('0', width - len));
char *pad = rz_str_pad('0', width - len);
rz_strbuf_prepend(sb, pad);
free(pad);
}
rz_strbuf_prepend(sb, "0x");
return rz_strbuf_drain(sb);
Expand Down
4 changes: 3 additions & 1 deletion librz/core/csign.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ static void flirt_print_node_pattern(const RzFlirtNode *node) {
}

static void flirt_print_indentation(int indent) {
rz_cons_printf("%s", rz_str_pad(' ', indent));
char *pad = rz_str_pad(' ', indent);
rz_cons_printf("%s", pad);
free(pad);
}

static void flirt_print_node(const RzFlirtNode *node, int indent) {
Expand Down
3 changes: 2 additions & 1 deletion librz/core/disasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3338,8 +3338,9 @@ static void ds_print_optype(RzDisasmState *ds) {
if (ds->show_optype) {
const char *optype = rz_analysis_optype_to_string(ds->analysis_op.type);
ds_print_color_reset(ds);
const char *pad = rz_str_pad(' ', 8 - strlen(optype));
char *pad = rz_str_pad(' ', 8 - strlen(optype));
rz_cons_printf("[%s]%s", optype, pad);
free(pad);
}
}

Expand Down
6 changes: 3 additions & 3 deletions librz/core/tui/esil.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ RZ_IPI bool rz_core_visual_esil(RzCore *core) {
const char *expr = rz_strbuf_get(&aop.esil);
rz_cons_printf(Color_RESET "esil: %s\n" Color_RESET, expr);
int wp = wordpos(expr, x);
char *pas = strdup(rz_str_pad(' ', wp ? wp + 1 : 0));
char *pas = rz_str_pad(' ', wp ? wp + 1 : 0);
int wp2 = wordpos(expr, x + 1);
free(word);
word = rz_str_ndup(expr + (wp ? (wp + 1) : 0), (wp2 - wp) - (wp ? 1 : 0));
Expand All @@ -90,10 +90,10 @@ RZ_IPI bool rz_core_visual_esil(RzCore *core) {
free(pas);
continue;
}
const char *pad = rz_str_pad('-', wp2 - ((wp > 0) ? wp + 1 : 0));
char *pad = rz_str_pad('-', wp2 - ((wp > 0) ? wp + 1 : 0));
rz_cons_printf(Color_RESET " %s%s\n" Color_RESET, pas, pad);
free(pas);
// free (pad);
free(pad);
}
rz_cons_printf("esil regs:\n");
showreg(esil, "$$", "address");
Expand Down
12 changes: 6 additions & 6 deletions librz/core/tui/panels.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,16 +999,16 @@ void __update_help_contents(RzPanels *panels, RzPanel *panel) {
RzConsCanvas *can = panels->can;
(void)rz_cons_canvas_gotoxy(can, x + 2, y + 2);
if (sx < 0) {
char *white = (char *)rz_str_pad(' ', 128);
int idx = RZ_MIN(-sx, strlen(white) - 1);
white[idx] = 0;
int idx = RZ_MIN(-sx, 127);
char *white = rz_str_pad(' ', idx);
text = rz_str_ansi_crop(read_only,
0, sy, w + sx - 3, h - 2 + sy);
char *newText = rz_str_prefix_all(text, white);
if (newText) {
free(text);
text = newText;
}
free(white);
} else {
text = rz_str_ansi_crop(read_only,
sx, sy, w + sx - 3, h - 2 + sy);
Expand Down Expand Up @@ -1063,16 +1063,16 @@ void __update_panel_contents(RzCore *core, RzPanel *panel, const char *cmdstr) {
RzConsCanvas *can = panels->can;
(void)rz_cons_canvas_gotoxy(can, x + 2, y + 2);
if (sx < 0) {
char *white = (char *)rz_str_pad(' ', 128);
int idx = RZ_MIN(-sx, strlen(white) - 1);
white[idx] = 0;
int idx = RZ_MIN(-sx, 127);
char *white = rz_str_pad(' ', idx);
text = rz_str_ansi_crop(cmdstr,
0, sy + graph_pad, w + sx - 3, h - 2 + sy);
char *newText = rz_str_prefix_all(text, white);
if (newText) {
free(text);
text = newText;
}
free(white);
} else {
text = rz_str_ansi_crop(cmdstr, sx, sy + graph_pad, w + sx - 3, h - 2 + sy);
}
Expand Down
4 changes: 3 additions & 1 deletion librz/core/tui/tabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ RZ_IPI RZ_OWN char *rz_core_visual_tab_string(RzCore *core, const char *kolor) {
if (str) {
int n = 79 - rz_str_ansi_len(str);
if (n > 0) {
str = rz_str_append(str, rz_str_pad('_', n));
char *pad = rz_str_pad('_', n);
str = rz_str_append(str, pad);
free(pad);
}
str = rz_str_append(str, "\n" Color_RESET);
}
Expand Down
6 changes: 4 additions & 2 deletions librz/core/tui/visual.c
Original file line number Diff line number Diff line change
Expand Up @@ -3078,14 +3078,16 @@ static void visual_flagzone(RzCore *core) {
char *title = rz_str_newf("[ 0x%08" PFMT64x " ]", core->offset);
title_size = strlen(title);
padsize -= strlen(title) / 2;
const char *halfpad = rz_str_pad(' ', padsize);
char *halfpad = rz_str_pad(' ', padsize);
rz_cons_printf("%s%s", halfpad, title);
free(title);
free(halfpad);
}
if (b) {
padsize = (w / 2) - title_size - strlen(b) - 4;
const char *halfpad = padsize > 1 ? rz_str_pad(' ', padsize) : "";
char *halfpad = rz_str_pad(' ', padsize);
rz_cons_printf("%s[%s >>]", halfpad, b);
free(halfpad);
}
if (a || b) {
rz_cons_newline();
Expand Down
2 changes: 1 addition & 1 deletion librz/include/rz_util/rz_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef int (*RzStrRangeCallback)(void *, int);
RZ_API const char *rz_str_enc_as_string(RzStrEnc enc);
RZ_API RzStrEnc rz_str_enc_string_as_type(RZ_NULLABLE const char *enc);
RZ_API char *rz_str_repeat(const char *ch, int sz);
RZ_API const char *rz_str_pad(const char ch, int len);
RZ_API RZ_OWN char *rz_str_pad(const char ch, int len);
RZ_API const char *rz_str_rstr(const char *base, const char *p);
RZ_API const char *rz_strstr_ansi(RZ_NONNULL const char *a, RZ_NONNULL const char *b, bool icase);
RZ_API const char *rz_str_rchr(const char *base, const char *p, int ch);
Expand Down
3 changes: 2 additions & 1 deletion librz/sign/pat.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ static bool flirt_pat_write_line(RZ_NONNULL const RzFlirtNode *node, RZ_NONNULL
}

if (prelude_len < (RZ_FLIRT_MAX_PRELUDE_SIZE << 1)) {
const char *pad = rz_str_pad('.', (RZ_FLIRT_MAX_PRELUDE_SIZE << 1) - prelude_len);
char *pad = rz_str_pad('.', (RZ_FLIRT_MAX_PRELUDE_SIZE << 1) - prelude_len);
rz_strbuf_append(prelude, pad);
free(pad);
}

char tmp[32];
Expand Down
14 changes: 10 additions & 4 deletions librz/util/asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ static void asn1_print_hex(RzASN1Object *object, char *buffer, ut32 size, ut32 d
char *p = buffer;
char *end = buffer + size;
if (depth > 0 && !structured) {
const char *pad = rz_str_pad(' ', (depth * 2) - 2);
char *pad = rz_str_pad(' ', (depth * 2) - 2);
snprintf(p, end - p, "%s", pad);
p += strlen(pad);
free(pad);
}
for (ut32 i = 0; i < object->length && p < end; i++) {
snprintf(p, end - p, "%02x", object->sector[i]);
Expand All @@ -214,7 +215,6 @@ static void asn1_print_hex(RzASN1Object *object, char *buffer, ut32 size, ut32 d
}

static void asn1_print_padded(RzStrBuf *sb, RzASN1Object *object, int depth, const char *k, const char *v) {
const char *pad = rz_str_pad(' ', (depth * 2) - 2);
if (object->form && !*v) {
return;
}
Expand All @@ -225,20 +225,25 @@ static void asn1_print_padded(RzStrBuf *sb, RzASN1Object *object, int depth, con
case RZ_ASN1_TAG_INTEGER:
case RZ_ASN1_TAG_REAL:
if (*rz_str_trim_head_ro(v)) {
char *pad = rz_str_pad(' ', (depth * 2) - 2);
rz_strbuf_appendf(sb, "%s%s\n%s%s\n", pad, k, pad, v);
free(pad);
}
break;
case RZ_ASN1_TAG_BITSTRING:
default:
if (*rz_str_trim_head_ro(v)) {
char *pad = rz_str_pad(' ', (depth * 2) - 2);
rz_strbuf_appendf(sb, "%s%s\n", pad, v);
free(pad);
}
break;
}
}

static RzASN1String *asn1_print_hexdump_padded(RzASN1Object *object, ut32 depth, bool structured) {
const char *pad;
const char *pad = NULL;
char *allocated = NULL;
ut32 i, j;
char readable[20] = { 0 };
if (!object || !object->sector || object->length < 1) {
Expand All @@ -248,7 +253,7 @@ static RzASN1String *asn1_print_hexdump_padded(RzASN1Object *object, ut32 depth,
if (structured) {
pad = " : ";
} else {
pad = rz_str_pad(' ', depth * 2);
pad = allocated = rz_str_pad(' ', depth * 2);
rz_strbuf_appendf(sb, " ");
}

Expand All @@ -262,6 +267,7 @@ static RzASN1String *asn1_print_hexdump_padded(RzASN1Object *object, ut32 depth,
rz_strbuf_appendf(sb, "%02x ", c);
readable[j] = IS_PRINTABLE(c) ? c : '.';
}
free(allocated);

while ((i % 16) != 0) {
rz_strbuf_appendf(sb, " ");
Expand Down
Loading

0 comments on commit a9131ce

Please sign in to comment.