X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=util.c;h=e634186bd0b56efcf4c1d4c83abcd41202fe5dfe;hb=24763aad65b8a6cb7fda9e038ee058b2ea02b875;hp=4253bd3cd53c18ed66575f02bc2ae6bae7dafd02;hpb=b52cf4d47e2e833c89a4aeeae7633cda834e5cae;p=xonotic%2Fgmqcc.git diff --git a/util.c b/util.c index 4253bd3..e634186 100644 --- a/util.c +++ b/util.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012, 2013 + * Copyright (C) 2012, 2013, 2014 * Dale Weiler * Wolfgang Bumiller * @@ -22,6 +22,7 @@ * SOFTWARE. */ #define GMQCC_PLATFORM_HEADER +#include #include "gmqcc.h" #include "platform.h" @@ -84,6 +85,7 @@ const char *util_instr_str[VINSTR_END] = { d[l] = (v << 32) | (v >> 32); } */ + l *= 2; size_t i; for (i = 0; i < l; i += 2) { uint32_t v1 = d[i]; @@ -94,32 +96,34 @@ const char *util_instr_str[VINSTR_END] = { } #endif -void util_endianswap(void *_data, size_t length, unsigned int typesize) { +void util_endianswap(void *_data, size_t count, unsigned int typesize) { # if PLATFORM_BYTE_ORDER == -1 /* runtime check */ if (*((char*)&typesize)) return; #else - /* prevent unused warnings */ - (void) _data; - (void) length; - (void) typesize; # if PLATFORM_BYTE_ORDER == GMQCC_BYTE_ORDER_LITTLE + /* prevent unused warnings */ + (void) _data; + (void) count; + (void) typesize; return; # else switch (typesize) { case 1: return; case 2: - util_swap16((uint16_t*)_data, length>>1); + util_swap16((uint16_t*)_data, count); return; case 4: - util_swap32((uint32_t*)_data, length>>2); + util_swap32((uint32_t*)_data, count); return; case 8: - util_swap64((uint32_t*)_data, length>>3); + util_swap64((uint32_t*)_data, count); return; - default: exit(EXIT_FAILURE); /* please blow the fuck up! */ + default: + con_err ("util_endianswap: I don't know how to swap a %u byte structure!\n", typesize); + exit(EXIT_FAILURE); /* please blow the fuck up! */ } # endif #endif @@ -456,11 +460,11 @@ static const uint16_t util_crc16_table[8][256] = {{ }}; /* Non - Reflected */ -uint16_t util_crc16(uint16_t current, const char *k, size_t len) { +uint16_t util_crc16(uint16_t current, const char *GMQCC_RESTRICT k, size_t len) { register uint16_t h = current; /* don't load twice */ - uint8_t *GMQCC_RESTRICT data = (uint8_t *GMQCC_RESTRICT)k; + const uint8_t *GMQCC_RESTRICT data = (const uint8_t *GMQCC_RESTRICT)k; size_t n; /* deal with the first bytes as bytes until we reach an 8 byte boundary */ @@ -482,8 +486,12 @@ uint16_t util_crc16(uint16_t current, const char *k, size_t len) { SELECT_DATA(1) ^ SELECT_DATA(0); data += 8; + len -= 8; } + #undef SELECT_BULK + #undef SELECT_DATA + /* deal with the rest with the byte method */ for (n = len & 7; n; --n) h = (uint16_t)(h << 8) ^ (*util_crc16_table)[(h >> 8) ^ *data++]; @@ -495,7 +503,7 @@ uint16_t util_crc16(uint16_t current, const char *k, size_t len) { * modifier is the match to make and the transposition from it, while add is the upper-value that determines the * transposition from uppercase to lower case. */ -static GMQCC_INLINE size_t util_strtransform(const char *in, char *out, size_t outsz, const char *mod, int add) { +static size_t util_strtransform(const char *in, char *out, size_t outsz, const char *mod, int add) { size_t sz = 1; for (; *in && sz < outsz; ++in, ++out, ++sz) { *out = (*in == mod[0])