[PATCH] libga68: Fix format specifiers for error messages
Pietro Monteiro
pietro@sociotechnical.xyz
Fri Oct 24 23:15:35 GMT 2025
Fixes the warnings when building with -Wformat.
ChangeLog:
* libga68/ga68-error.c (_libga68_derefnil): Use %u for
unsigned int.
(_libga68_invalidcharerror): Likewise.
(_libga68_bitsboundserror): Use %u for
unsigned int, and %zd ssize_t.
(_libga68_unreachable): Use %u for
unsigned int.
(_libga68_lower_bound): Use %u for
unsigned int, and %zd ssize_t.
(_libga68_upper_bound): Likewise.
(_libga68_bounds): Likewise.
(_libga68_dim): Use %u for
unsigned int, %zd ssize_t, and %zu for size_t.
(_libga68_bounds_mismatch): Likewise.
* libga68/ga68.h (_libga68_abort): Add attributes to prototype.
Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
---
libga68/ga68-error.c | 22 +++++++++++-----------
libga68/ga68.h | 5 ++++-
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/libga68/ga68-error.c b/libga68/ga68-error.c
index 14edef242f4..28f71659645 100644
--- a/libga68/ga68-error.c
+++ b/libga68/ga68-error.c
@@ -62,7 +62,7 @@ _libga68_assert (const char *filename, unsigned int lineno)
void
_libga68_derefnil (const char *filename, unsigned int lineno)
{
- _libga68_abort ("%s:%d: runtime error: attempt to dereference NIL\n",
+ _libga68_abort ("%s:%u: runtime error: attempt to dereference NIL\n",
filename, lineno);
}
@@ -73,9 +73,9 @@ _libga68_invalidcharerror (const char *filename, unsigned int lineno,
int c)
{
if (c < 0)
- _libga68_abort ("%s:%d: runtime error: %d is not a valid character point\n",
+ _libga68_abort ("%s:%u: runtime error: %d is not a valid character point\n",
filename, lineno, c);
- _libga68_abort ("%s:%d: runtime error: U+%x is not a valid character point\n",
+ _libga68_abort ("%s:%u: runtime error: U+%x is not a valid character point\n",
filename, lineno, c);
}
@@ -85,7 +85,7 @@ void
_libga68_bitsboundserror (const char *filename, unsigned int lineno,
ssize_t pos)
{
- _libga68_abort ("%s:%d: runtime error: bound %d out of range in ELEM\n",
+ _libga68_abort ("%s:%u: runtime error: bound %zd out of range in ELEM\n",
filename, lineno, pos);
}
@@ -94,7 +94,7 @@ _libga68_bitsboundserror (const char *filename, unsigned int lineno,
void
_libga68_unreachable (const char *filename, unsigned int lineno)
{
- _libga68_abort ("%s:%d: runtime error: unreachable reached\n",
+ _libga68_abort ("%s:%u: runtime error: unreachable reached\n",
filename, lineno);
}
@@ -104,7 +104,7 @@ void
_libga68_lower_bound (const char *filename, unsigned int lineno,
ssize_t index, ssize_t lower_bound)
{
- _libga68_abort ("%s:%d: runtime error: lower bound %d must be >= %d\n",
+ _libga68_abort ("%s:%u: runtime error: lower bound %zd must be >= %zd\n",
filename, lineno, index, lower_bound);
}
@@ -114,7 +114,7 @@ void
_libga68_upper_bound (const char *filename, unsigned int lineno,
ssize_t index, ssize_t upper_bound)
{
- _libga68_abort ("%s:%d: runtime error: upper bound %d must be <= %d\n",
+ _libga68_abort ("%s:%u: runtime error: upper bound %zd must be <= %zd\n",
filename, lineno, index, upper_bound);
}
@@ -124,7 +124,7 @@ void
_libga68_bounds (const char *filename, unsigned int lineno,
ssize_t index, ssize_t lower_bound, ssize_t upper_bound)
{
- _libga68_abort ("%s:%d: runtime error: bound %d out of range [%d:%d]\n",
+ _libga68_abort ("%s:%u: runtime error: bound %zd out of range [%zd:%zd]\n",
filename, lineno, index, lower_bound, upper_bound);
}
@@ -134,7 +134,7 @@ void
_libga68_dim (const char *filename, unsigned int lineno,
size_t dim, size_t index)
{
- _libga68_abort ("%s:%d: runtime error: invalid dimension %d; shall be > 0 and <= %d\n",
+ _libga68_abort ("%s:%u: runtime error: invalid dimension %zd; shall be > 0 and <= %zu\n",
filename, lineno, index, dim);
}
@@ -145,7 +145,7 @@ _libga68_bounds_mismatch (const char *filename, unsigned int lineno,
size_t dim, ssize_t lb1, ssize_t ub1,
ssize_t lb2, ssize_t ub2)
{
- _libga68_abort ("%s:%d: runtime error: multiple bounds mismatch in \
-assignation: dim %d: [%d:%d] /= [%d:%d]\n",
+ _libga68_abort ("%s:%u: runtime error: multiple bounds mismatch in \
+assignation: dim %zu: [%zd:%zd] /= [%zd:%zd]\n",
filename, lineno, dim, lb1, ub1, lb2, ub2);
}
diff --git a/libga68/ga68.h b/libga68/ga68.h
index 083c9315090..4149d81c484 100644
--- a/libga68/ga68.h
+++ b/libga68/ga68.h
@@ -33,7 +33,10 @@
/* ga68-error.c */
-void _libga68_abort (const char *fmt, ...);
+void _libga68_abort (const char *fmt, ...)
+ __attribute__ ((__format__ (__printf__, 1, 2), __nonnull__ (1),
+ __noreturn__));
+
void _libga68_assert (const char *filename, unsigned int lineno);
void _libga68_derefnil (const char *filename, unsigned int lineno);
void _libga68_invalidcharerror (const char *filename, unsigned int lineno,
--
2.43.0
More information about the Algol68
mailing list