From 6e96ff3e0073139bbb77f57c4eda4dfaa1b1c2f7 Mon Sep 17 00:00:00 2001 From: Kp Date: Thu, 2 Apr 2015 02:36:52 +0000 Subject: [PATCH] Fix ambiguous use of INTEL_SHORT/INTEL_INT --- common/2d/bitblt.cpp | 6 +++--- common/2d/rle.cpp | 4 ++-- common/include/byteutil.h | 28 ++++++++++++++++++---------- common/main/multi.h | 4 ++-- similar/main/gameseq.cpp | 4 +--- similar/main/multi.cpp | 4 ++-- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/common/2d/bitblt.cpp b/common/2d/bitblt.cpp index 5b9bf317d..32b7389f7 100644 --- a/common/2d/bitblt.cpp +++ b/common/2d/bitblt.cpp @@ -399,7 +399,7 @@ static void gr_bm_ubitblt00_rle(unsigned w, unsigned h, int dx, int dy, int sx, data_offset = 2; auto sbits = &src.get_bitmap_data()[4 + (src.bm_h*data_offset)]; for (uint_fast32_t i = 0; i != sy; ++i) - sbits += (int)(INTEL_SHORT(src.bm_data[4+(i*data_offset)])); + sbits += src.bm_data[4+(i*data_offset)]; auto dbits = &dest.get_bitmap_data()[(dest.bm_rowsize * dy) + dx]; // No interlacing, copy the whole buffer. for (uint_fast32_t i = 0; i != h; ++i) @@ -422,7 +422,7 @@ static void gr_bm_ubitblt00m_rle(unsigned w, unsigned h, int dx, int dy, int sx, data_offset = 2; auto sbits = &src.get_bitmap_data()[4 + (src.bm_h*data_offset)]; for (uint_fast32_t i = 0; i != sy; ++i) - sbits += (int)(INTEL_SHORT(src.bm_data[4+(i*data_offset)])); + sbits += src.bm_data[4+(i*data_offset)]; auto dbits = &dest.get_bitmap_data()[(dest.bm_rowsize * dy) + dx]; // No interlacing, copy the whole buffer. for (uint_fast32_t i = 0; i != h; ++i) @@ -446,7 +446,7 @@ static void gr_bm_ubitblt0x_rle(unsigned w, unsigned h, int dx, int dy, int sx, data_offset = 2; auto sbits = &src.bm_data[4 + (src.bm_h*data_offset)]; for (uint_fast32_t i = 0; i != sy; ++i) - sbits += (int)(INTEL_SHORT(src.bm_data[4+(i*data_offset)])); + sbits += src.bm_data[4 + (i * data_offset)]; for (uint_fast32_t y1 = 0; y1 != h; ++y1) { diff --git a/common/2d/rle.cpp b/common/2d/rle.cpp index b9cff3511..4928622cf 100644 --- a/common/2d/rle.cpp +++ b/common/2d/rle.cpp @@ -549,7 +549,7 @@ void rle_swap_0_255(grs_bitmap &bmp) } } if (rle_big) // set line size - *((unsigned short *)&temp[4 + 2 * i]) = INTEL_SHORT(ptr2 - start); + PUT_INTEL_SHORT(&temp[4 + 2 * i], static_cast(ptr2 - start)); else temp[4 + i] = ptr2 - start; ptr += line_size; // go to next line @@ -596,7 +596,7 @@ void rle_remap(grs_bitmap &bmp, array &colormap) } } if (rle_big) // set line size - *((unsigned short *)&temp[4 + 2 * i]) = INTEL_SHORT(ptr2 - start); + PUT_INTEL_SHORT(&temp[4 + 2 * i], static_cast(ptr2 - start)); else temp[4 + i] = ptr2 - start; ptr += line_size; // go to next line diff --git a/common/include/byteutil.h b/common/include/byteutil.h index 7d5d0f143..fa873e95b 100644 --- a/common/include/byteutil.h +++ b/common/include/byteutil.h @@ -61,22 +61,30 @@ static inline int32_t SWAPINT(const int32_t &i) #define SWAPINT64(x) ((((x) & 0xff00000000000000LL)/(2^56)) | (((x) & 0x00ff000000000000LL)/(2^40)) | (((x) & 0x0000ff0000000000LL)/(2^24)) | (((x) & 0x000000ff00000000LL)/(2^8)) | (((x) & 0x00000000ff000000LL)*(2^8)) | (((x) & 0x0000000000ff0000LL)*(2^24)) | (((x) & 0x000000000000ff00LL)*(2^40)) | (((x) & 0x00000000000000ffLL)*(2^56))) #endif -#ifndef WORDS_BIGENDIAN -#define INTEL_INT64(x) x -#define INTEL_INT(x) x -#define INTEL_SHORT(x) x -#else // ! WORDS_BIGENDIAN -#define INTEL_INT64(x) SWAPINT64(x) -#define INTEL_INT(x) SWAPINT(x) -#define INTEL_SHORT(x) SWAPSHORT(x) -#endif // ! WORDS_BIGENDIAN - #ifndef WORDS_NEED_ALIGNMENT +/* Always resolve F(a), so ambiguous calls are flagged even on little + * endian. + */ +#define byteutil_choose_endian(F,a) (static_cast(static_cast(0)), a) #define byteutil_unaligned_copy(dt, d, s) (static_cast
(d) = *reinterpret_cast(s)) #else // ! WORDS_NEED_ALIGNMENT +#define byteutil_choose_endian(F,a) (F(a)) #define byteutil_unaligned_copy(dt, d, s) memcpy(&static_cast
(d), reinterpret_cast(s), sizeof(d)) #endif // ! WORDS_NEED_ALIGNMENT +template +static inline T INTEL_SHORT(const T &x) +{ + return byteutil_choose_endian(SWAPSHORT, x); +} + +template +static inline T INTEL_INT(const T &x) +{ + return byteutil_choose_endian(SWAPINT, x); +} +#undef byteutil_choose_endian + template static inline uint32_t GET_INTEL_INT(const T *p) { diff --git a/common/main/multi.h b/common/main/multi.h index bc2a9b605..7e7b8fe1f 100644 --- a/common/main/multi.h +++ b/common/main/multi.h @@ -87,7 +87,7 @@ extern int multi_protocol; // set and determinate used protocol #define MULTI_PROTO_UDP 1 // UDP protocol // What version of the multiplayer protocol is this? Increment each time something drastic changes in Multiplayer without the version number changes. Reset to 0 each time the version of the game changes -#define MULTI_PROTO_VERSION 17 +#define MULTI_PROTO_VERSION static_cast(18) // PROTOCOL VARIABLES AND DEFINES - END // limits for Packets (i.e. positional updates) per sec @@ -499,7 +499,7 @@ uint_fast32_t multi_powerup_is_allowed(const unsigned id, const unsigned Allowed extern void multi_send_stolen_items(); void multi_send_trigger_specific(playernum_t pnum,char trig); void multi_send_door_open_specific(playernum_t pnum,segnum_t segnum, int side,ubyte flag); -void multi_send_wall_status_specific (playernum_t pnum,int wallnum,ubyte type,ubyte flags,ubyte state); +void multi_send_wall_status_specific(playernum_t pnum,uint16_t wallnum,ubyte type,ubyte flags,ubyte state); void multi_send_light_specific (playernum_t pnum,segnum_t segnum,ubyte val); void multi_send_capture_bonus (playernum_t pnum); int multi_all_players_alive(); diff --git a/similar/main/gameseq.cpp b/similar/main/gameseq.cpp index 8e1fec142..a39421351 100644 --- a/similar/main/gameseq.cpp +++ b/similar/main/gameseq.cpp @@ -627,7 +627,7 @@ static ushort netmisc_calc_checksum() s = INTEL_SHORT(j); do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); } - range_for (uint16_t j, Segments[i].verts) + range_for (const uint16_t j, Segments[i].verts) { s = INTEL_SHORT(j); do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); @@ -641,8 +641,6 @@ static ushort netmisc_calc_checksum() do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); t = INTEL_INT(((int)Segments[i].static_light)); do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2); - s = INTEL_SHORT(0); // no matter if we need alignment on our platform, if we have editor we MUST consider this integer to get the same checksum as non-editor games calculate - do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); #endif } sum2 %= 255; diff --git a/similar/main/multi.cpp b/similar/main/multi.cpp index d43761810..46abc6925 100644 --- a/similar/main/multi.cpp +++ b/similar/main/multi.cpp @@ -3525,7 +3525,7 @@ void multi_send_drop_weapon(objnum_t objnum, int seed) count++; multibuf[count++]=(char)get_powerup_id(objp); PUT_INTEL_SHORT(multibuf+count, objnum); count += 2; - PUT_INTEL_SHORT(multibuf+count, ammo_count); count += 2; + PUT_INTEL_SHORT(multibuf+count, static_cast(ammo_count)); count += 2; PUT_INTEL_INT(multibuf+count, seed); count += 4; @@ -3655,7 +3655,7 @@ static void multi_do_stolen_items (const ubyte *buf) } } -void multi_send_wall_status_specific (const playernum_t pnum,int wallnum,ubyte type,ubyte flags,ubyte state) +void multi_send_wall_status_specific(const playernum_t pnum,uint16_t wallnum,ubyte type,ubyte flags,ubyte state) { // Send wall states a specific rejoining player