Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some minor undefined behaviours #1810

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hts.c
Original file line number Diff line number Diff line change
Expand Up @@ -3826,7 +3826,7 @@ void hts_itr_destroy(hts_itr_t *iter)
}
}

static inline long long push_digit(long long i, char c)
static inline unsigned long long push_digit(unsigned long long i, char c)
{
// ensure subtraction occurs first, avoiding overflow for >= MAX-48 or so
int digit = c - '0';
Expand All @@ -3835,7 +3835,7 @@ static inline long long push_digit(long long i, char c)

long long hts_parse_decimal(const char *str, char **strend, int flags)
{
long long n = 0;
unsigned long long n = 0;
int digits = 0, decimals = 0, e = 0, lost = 0;
char sign = '+', esign = '+';
const char *s, *str_orig = str;
Expand Down
12 changes: 9 additions & 3 deletions hts_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,10 @@ static int bitand_expr(hts_filter_t *filt, void *data, hts_expr_sym_func *fn,
} else if (res->is_str || val.is_str) {
hts_expr_val_free(&val);
return -1;
} else {
res->is_true =
(res->d = ((int64_t)res->d & (int64_t)val.d)) != 0;
}
res->is_true = (res->d = ((int64_t)res->d & (int64_t)val.d)) != 0;
} else {
break;
}
Expand Down Expand Up @@ -560,8 +562,10 @@ static int bitxor_expr(hts_filter_t *filt, void *data, hts_expr_sym_func *fn,
} else if (res->is_str || val.is_str) {
hts_expr_val_free(&val);
return -1;
} else {
res->is_true =
(res->d = ((int64_t)res->d ^ (int64_t)val.d)) != 0;
}
res->is_true = (res->d = ((int64_t)res->d ^ (int64_t)val.d)) != 0;
} else {
break;
}
Expand Down Expand Up @@ -593,8 +597,10 @@ static int bitor_expr(hts_filter_t *filt, void *data, hts_expr_sym_func *fn,
} else if (res->is_str || val.is_str) {
hts_expr_val_free(&val);
return -1;
} else {
res->is_true =
(res->d = ((int64_t)res->d | (int64_t)val.d)) != 0;
}
res->is_true = (res->d = ((int64_t)res->d | (int64_t)val.d)) != 0;
} else {
break;
}
Expand Down
5 changes: 4 additions & 1 deletion vcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -4020,7 +4020,10 @@ int vcf_format(const bcf_hdr_t *h, const bcf1_t *v, kstring_t *s)

kputc_('\t', s); // INFO
if (v->n_info) {
uint8_t *ptr = (uint8_t *)v->shared.s + v->unpack_size[0] + v->unpack_size[1] + v->unpack_size[2];
uint8_t *ptr = v->shared.s
? (uint8_t *)v->shared.s + v->unpack_size[0] +
v->unpack_size[1] + v->unpack_size[2]
: NULL;
int first = 1;
bcf_info_t *info = v->d.info;

Expand Down