1
0
Fork 0

Fixed 64 bit pointer casting

development
Marco Paland 8 years ago
parent 002234f209
commit c355eaa2b0

@ -32,6 +32,7 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include "printf.h"
@ -270,7 +271,7 @@ static size_t _ftoa(double value, char* buffer, size_t maxlen, unsigned int prec
// greater than 0.5, round up, e.g. 1.6 -> 2
++whole;
}
else if (diff == 0.5 && (whole & 1)) {
else if ((diff == 0.5) && (whole & 1)) {
// exactly 0.5 and ODD, then round up
// 1.5 -> 2, but 2.5 -> 2
++whole;
@ -551,13 +552,13 @@ static size_t _vsnprintf(char* buffer, size_t buffer_len, const char* format, va
case 'p' : {
width = sizeof(void*) * 2U;
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
if (sizeof(void*) == sizeof(long long)) {
if (sizeof(uintptr_t) == sizeof(long long)) {
#if defined(PRINTF_LONG_LONG_SUPPORT)
idx += _ntoa_long_long(&buffer[idx], (unsigned long long)va_arg(va, void*), false, 16U, buffer_len - idx, precision, width, flags);
idx += _ntoa_long_long(&buffer[idx], (uintptr_t)va_arg(va, void*), false, 16U, buffer_len - idx, precision, width, flags);
#endif
}
else {
idx += _ntoa_long(&buffer[idx], (unsigned long)va_arg(va, void*), false, 16U, buffer_len - idx, precision, width, flags);
idx += _ntoa_long(&buffer[idx], (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16U, buffer_len - idx, precision, width, flags);
}
format++;
break;

@ -977,11 +977,12 @@ TEST_CASE("pointer", "[]" ) {
REQUIRE(!strcmp(buffer, "0000000012345678"));
}
test::sprintf(buffer, "%p", (void*)0xFFFFFFFFLU);
if (sizeof(void*) == 4U) {
if (sizeof(void*) == sizeof(long)) {
test::sprintf(buffer, "%p", (void*)(long)0xFFFFFFFFU);
REQUIRE(!strcmp(buffer, "FFFFFFFF"));
}
else {
test::sprintf(buffer, "%p", (void*)(unsigned long long)0xFFFFFFFFU);
REQUIRE(!strcmp(buffer, "00000000FFFFFFFF"));
}
}

Loading…
Cancel
Save