[PATCH 1/2] os: fix vararg length calculation
Peter Hutterer
peter.hutterer at who-t.net
Thu Jun 28 22:30:51 PDT 2012
Make %u and %x sizeof(unsigned int), %p sizeof(void*). This is printf
behaviour and we can't guarantee that void* is uint64_t anyway.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
This needs to be squashed into:
Add LogMessageVerbSigSafe() for logging messages while in signal context
Fixes the test/input crash on 32-bit userspace
os/log.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/os/log.c b/os/log.c
index 3ae8fd4..6399eba 100644
--- a/os/log.c
+++ b/os/log.c
@@ -289,6 +289,7 @@ pnprintf(char *string, size_t size, const char *f, va_list args)
char number[21];
int p_len;
int i;
+ uint64_t ui;
for (; f_idx < f_len && s_idx < size - 1; f_idx++) {
if (f[f_idx] != '%') {
@@ -306,7 +307,8 @@ pnprintf(char *string, size_t size, const char *f, va_list args)
break;
case 'u':
- FormatUInt64(va_arg(args, uint64_t), number);
+ ui = va_arg(args, unsigned);
+ FormatUInt64(ui, number);
p_len = strlen_sigsafe(number);
for (i = 0; i < p_len && s_idx < size - 1; i++)
@@ -317,10 +319,17 @@ pnprintf(char *string, size_t size, const char *f, va_list args)
string[s_idx++] = '0';
if (s_idx < size - 1)
string[s_idx++] = 'x';
- /* Intentional fall-through */
+ ui = (uint64_t)va_arg(args, void*);
+ FormatUInt64Hex(ui, number);
+ p_len = strlen_sigsafe(number);
+
+ for (i = 0; i < p_len && s_idx < size - 1; i++)
+ string[s_idx++] = number[i];
+ break;
case 'x':
- FormatUInt64Hex(va_arg(args, uint64_t), number);
+ ui = va_arg(args, unsigned);
+ FormatUInt64Hex(ui, number);
p_len = strlen_sigsafe(number);
for (i = 0; i < p_len && s_idx < size - 1; i++)
--
1.7.10.2
More information about the xorg-devel
mailing list