From b9399c504837301169ceb3c39f275d241c87ca75 Mon Sep 17 00:00:00 2001 From: Kp Date: Fri, 19 Aug 2016 03:41:41 +0000 Subject: [PATCH] Switch multi_process_bigdata to use inttypes format macros Most 64-bit systems use `unsigned long` for `uint_fast32_t`. Some 32-bit systems use `unsigned int` for `uint_fast32_t`. To handle this, multi_process_bigdata used casts to `unsigned long` and a format string of `%lu`. Switch to inttypes format macros so that the format strings are correct without requiring a cast to handle systems where `uint_fast32_t` is not `unsigned long`. --- similar/main/multi.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/similar/main/multi.cpp b/similar/main/multi.cpp index f60f46243..a41352fa5 100644 --- a/similar/main/multi.cpp +++ b/similar/main/multi.cpp @@ -2434,7 +2434,7 @@ static void multi_reset_object_texture(object_base &objp) } -void multi_process_bigdata(const playernum_t pnum, const ubyte *buf, uint_fast32_t len) +void multi_process_bigdata(const playernum_t pnum, const ubyte *const buf, const uint_fast32_t len) { // Takes a bunch of messages, check them for validity, // and pass them to multi_process_data. @@ -2442,19 +2442,19 @@ void multi_process_bigdata(const playernum_t pnum, const ubyte *buf, uint_fast32 uint_fast32_t bytes_processed = 0; while( bytes_processed < len ) { - uint_fast32_t type = buf[bytes_processed]; + const uint_fast32_t type = buf[bytes_processed]; if ( (type>= sizeof(message_length)/sizeof(message_length[0]))) { - con_printf( CON_DEBUG,"multi_process_bigdata: Invalid packet type %lu!", static_cast(type)); + con_printf(CON_DEBUG, "multi_process_bigdata: Invalid packet type %" PRIuFAST32 "!", type); return; } - uint_fast32_t sub_len = message_length[type]; + const uint_fast32_t sub_len = message_length[type]; Assert(sub_len > 0); if ( (bytes_processed+sub_len) > len ) { - con_printf(CON_DEBUG, "multi_process_bigdata: packet type %u too short (%lu>%lu)!", static_cast(type), static_cast(bytes_processed+sub_len), static_cast(len)); + con_printf(CON_DEBUG, "multi_process_bigdata: packet type %" PRIuFAST32 " too short (%" PRIuFAST32 " > %" PRIuFAST32 ")!", type, bytes_processed + sub_len, len); Int3(); return; }