Make fatal() check for printf attributes.

This commit is contained in:
ckolivas 2026-02-13 11:15:16 +11:00
parent 96931e7019
commit 4b2a0a4714
3 changed files with 14 additions and 14 deletions

View file

@ -211,7 +211,7 @@ static i64 unzip_match(rzip_control *control, void *ss, i64 len, uint32 *cksum,
if (unlikely(offset == -1))
return -1;
if (unlikely(seekto_fdhist(control, cur_pos - offset) == -1))
fatal_return(("Seek failed by %d from %d on history file in unzip_match\n",
fatal_return(("Seek failed by %"PRId64" from %"PRId64" on history file in unzip_match\n",
offset, cur_pos), -1);
n = MIN(len, offset);
@ -224,7 +224,7 @@ static i64 unzip_match(rzip_control *control, void *ss, i64 len, uint32 *cksum,
if (unlikely(read_fdhist(control, buf, (size_t)n) != (ssize_t)n)) {
dealloc(buf);
fatal_return(("Failed to read %d bytes in unzip_match\n", n), -1);
fatal_return(("Failed to read %"PRId64" bytes in unzip_match\n", n), -1);
}
while (len) {
@ -234,7 +234,7 @@ static i64 unzip_match(rzip_control *control, void *ss, i64 len, uint32 *cksum,
if (unlikely(write_1g(control, buf, (size_t)n) != (ssize_t)n)) {
dealloc(buf);
fatal_return(("Failed to write %d bytes in unzip_match\n", n), -1);
fatal_return(("Failed to write %"PRId64" bytes in unzip_match\n", n), -1);
}
if (!HAS_MD5)

View file

@ -1420,7 +1420,7 @@ retry:
* later */
if (ENCRYPT) {
if (unlikely(write_val(control, 0, SALT_LEN)))
fatal_goto(("Failed to write_buf blank salt in compthread %d\n", i), error);
fatal_goto(("Failed to write_buf blank salt in compthread %ld\n", i), error);
ctis->cur_pos += SALT_LEN;
}
ctis->s[j].last_head = ctis->cur_pos + 1 + (write_len * 2);
@ -1435,10 +1435,10 @@ retry:
print_maxverbose("Compthread %ld seeking to %"PRId64" to store length %d\n", i, ctis->s[cti->streamno].last_head, write_len);
if (unlikely(seekto(control, ctis, ctis->s[cti->streamno].last_head)))
fatal_goto(("Failed to seekto in compthread %d\n", i), error);
fatal_goto(("Failed to seekto in compthread %ld\n", i), error);
if (unlikely(write_val(control, ctis->cur_pos, write_len)))
fatal_goto(("Failed to write_val cur_pos in compthread %d\n", i), error);
fatal_goto(("Failed to write_val cur_pos in compthread %ld\n", i), error);
if (ENCRYPT)
rewrite_encrypted(control, ctis, ctis->s[cti->streamno].last_head - 17);
@ -1448,13 +1448,13 @@ retry:
print_maxverbose("Compthread %ld seeking to %"PRId64" to write header\n", i, ctis->cur_pos);
if (unlikely(seekto(control, ctis, ctis->cur_pos)))
fatal_goto(("Failed to seekto cur_pos in compthread %d\n", i), error);
fatal_goto(("Failed to seekto cur_pos in compthread %ld\n", i), error);
print_maxverbose("Thread %ld writing %"PRId64" compressed bytes from stream %d\n", i, padded_len, cti->streamno);
if (ENCRYPT) {
if (unlikely(write_val(control, 0, SALT_LEN)))
fatal_goto(("Failed to write_buf header salt in compthread %d\n", i), error);
fatal_goto(("Failed to write_buf header salt in compthread %ld\n", i), error);
ctis->cur_pos += SALT_LEN;
ctis->s[cti->streamno].last_headofs = ctis->cur_pos;
}
@ -1463,7 +1463,7 @@ retry:
write_val(control, cti->c_len, write_len) ||
write_val(control, cti->s_len, write_len) ||
write_val(control, 0, write_len))) {
fatal_goto(("Failed write in compthread %d\n", i), error);
fatal_goto(("Failed write in compthread %ld\n", i), error);
}
ctis->cur_pos += 1 + (write_len * 3);
@ -1471,7 +1471,7 @@ retry:
if (unlikely(!get_rand(control, cti->salt, SALT_LEN)))
goto error;
if (unlikely(write_buf(control, cti->salt, SALT_LEN)))
fatal_goto(("Failed to write_buf block salt in compthread %d\n", i), error);
fatal_goto(("Failed to write_buf block salt in compthread %ld\n", i), error);
if (unlikely(!lrz_encrypt(control, cti->s_buf, padded_len, cti->salt)))
goto error;
ctis->cur_pos += SALT_LEN;
@ -1480,7 +1480,7 @@ retry:
print_maxverbose("Compthread %ld writing data at %"PRId64"\n", i, ctis->cur_pos);
if (unlikely(write_buf(control, cti->s_buf, padded_len)))
fatal_goto(("Failed to write_buf s_buf in compthread %d\n", i), error);
fatal_goto(("Failed to write_buf s_buf in compthread %ld\n", i), error);
ctis->cur_pos += padded_len;
dealloc(cti->s_buf);
@ -1697,7 +1697,7 @@ fill_another:
fsync(control->fd_out);
if (unlikely(u_len > control->maxram))
fatal_return(("Unable to allocate enough memory for %"PRId64" specified in possibly corrupt archive\n"), -1);
fatal_return(("Unable to allocate enough memory for %"PRId64" specified in possibly corrupt archive\n", u_len), -1);
max_len = MAX(u_len, MIN_SIZE);
max_len = MAX(max_len, c_len);
s_buf = malloc(max_len);

4
util.h
View file

@ -1,5 +1,5 @@
/*
Copyright (C) 2006-2016 Con Kolivas
Copyright (C) 2006-2016,2026 Con Kolivas
Copyright (C) 2011 Peter Hyman
Copyright (C) 1998 Andrew Tridgell
@ -32,7 +32,7 @@ void unlink_files(rzip_control *control);
void register_outputfile(rzip_control *control, FILE *f);
void fatal_exit(rzip_control *control);
/* Failure when there is likely to be a meaningful error in perror */
static inline void fatal(const rzip_control *control, unsigned int line, const char *file, const char *func, const char *format, ...)
static inline void __attribute__((format(printf, 5, 6))) fatal(const rzip_control *control, unsigned int line, const char *file, const char *func, const char *format, ...)
{
va_list ap;