Merge pull request #148 from kazarmy/fix-Wformat-overflow
Fix `-Wformat-overflow` warnings due to gcc 12 + ASAN + `-O2`
This commit is contained in:
9
mpc.c
9
mpc.c
@@ -863,6 +863,9 @@ static mpc_err_t *mpc_err_count(mpc_input_t *i, mpc_err_t *x, int n) {
|
|||||||
int digits = n/10 + 1;
|
int digits = n/10 + 1;
|
||||||
char *prefix;
|
char *prefix;
|
||||||
prefix = mpc_malloc(i, digits + strlen(" of ") + 1);
|
prefix = mpc_malloc(i, digits + strlen(" of ") + 1);
|
||||||
|
if (!prefix) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
sprintf(prefix, "%i of ", n);
|
sprintf(prefix, "%i of ", n);
|
||||||
y = mpc_err_repeat(i, x, prefix);
|
y = mpc_err_repeat(i, x, prefix);
|
||||||
mpc_free(i, prefix);
|
mpc_free(i, prefix);
|
||||||
@@ -1651,6 +1654,9 @@ mpc_parser_t *mpc_failf(const char *fmt, ...) {
|
|||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
buffer = malloc(2048);
|
buffer = malloc(2048);
|
||||||
|
if (!buffer) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
vsprintf(buffer, fmt, va);
|
vsprintf(buffer, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
@@ -1725,6 +1731,9 @@ mpc_parser_t *mpc_expectf(mpc_parser_t *a, const char *fmt, ...) {
|
|||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
buffer = malloc(2048);
|
buffer = malloc(2048);
|
||||||
|
if (!buffer) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
vsprintf(buffer, fmt, va);
|
vsprintf(buffer, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user