Use size_t in `union ctlseqs_value`.

This commit is contained in:
CismonX 2020-12-25 19:19:54 +08:00
parent 8ef507792b
commit c4b9ba3aef
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
4 changed files with 11 additions and 9 deletions

View File

@ -279,7 +279,7 @@ sixdraw_prepare(struct sixdraw_ctx *ctx)
bool has_sixel = false;
bool has_dec_locator = false;
union ctlseqs_value *result = ctx->result;
for (size_t i = 1; i <= result[0].num; ++i) {
for (size_t i = 1; i <= result[0].len; ++i) {
if (result[i].num == 4) {
has_sixel = true;
} else if (result[i].num == 29) {

View File

@ -74,7 +74,7 @@
break; \
} \
} \
buf_val[0].num = cnt; \
buf_val[0].len = cnt; \
buf_val[1].str = seq; \
*buf += 2; \
return seq + cnt
@ -250,7 +250,8 @@ ctlseqs_state_transition(enum ctlseqs_state state, char ch)
CTLSEQS_HOT static char const *
ctlseqs_fetch_value(char const *seq, int type, union ctlseqs_value **buf)
{
unsigned long cnt, num;
size_t cnt;
unsigned long num;
char *endptr = NULL;
union ctlseqs_value *buf_val = *buf;
switch (type) {
@ -269,7 +270,7 @@ ctlseqs_fetch_value(char const *seq, int type, union ctlseqs_value **buf)
}
seq = endptr + 1;
}
buf_val[0].num = cnt;
buf_val[0].len = cnt;
*buf += cnt + 1;
return endptr;
case ctlseqs_ph_str:
@ -365,7 +366,7 @@ ctlseqs_do_match(struct ctlseqs_matcher const *matcher, struct ctlseqs_match_arg
}
}
if (retval < 0 || args->save_seq) {
args->result[0].num = idx;
args->result[0].len = idx;
args->result[1].str = seq;
}
args->result_idx = idx;

View File

@ -388,6 +388,7 @@ struct ctlseqs_reader_options {
union ctlseqs_value {
char const *str;
size_t len;
unsigned long num;
};

View File

@ -87,7 +87,7 @@ parse_int(char const *str, int *dest)
static void
print_generic_seq(char const *header, union ctlseqs_value *result, bool newline)
{
size_t length = result[0].num;
size_t length = result[0].len;
char const *seq = result[1].str;
printf("%s %zu", header, length);
for (size_t idx = 0; idx < length; ++idx) {
@ -124,10 +124,10 @@ print_matching_seq(struct tcsgrep_sequence *seq, union ctlseqs_value *result, bo
printf(" %lu", result[idx].num);
break;
case 0x10: // CTLSEQS_PH_STR
printf(" %.*s", (int)result[idx].num, result[idx + 1].str);
printf(" %.*s", (int)result[idx].len, result[idx + 1].str);
break;
case 0x0f: // CTLSEQS_PH_NUMS
for (size_t i = 1; i <= result[idx].num; ++i) {
for (size_t i = 1; i <= result[idx].len; ++i) {
printf(" %lu", result[idx + i].num);
}
break;
@ -421,7 +421,7 @@ main(int argc, char **argv)
case CTLSEQS_NOMEM:
print_generic_seq("NOMEM", result, true);
if (ctx.purge_long_seqs) {
ctlseqs_purge(reader, result[0].num);
ctlseqs_purge(reader, result[0].len);
break;
} else {
status = 1;