From 7b6b473ec4f218a92868eeb8275c093dc5e2693e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2015 11:28:04 +0200 Subject: [PATCH] - some GCC fixed by Edward-san. --- src/autosegs.h | 3 ++- src/d_dehacked.cpp | 2 +- src/d_netinfo.cpp | 2 +- src/dobjtype.cpp | 4 ++-- src/tarray.h | 23 +++++++++++++++++++---- src/thingdef/thingdef_codeptr.cpp | 4 ++-- src/thingdef/thingdef_expression.cpp | 2 +- src/zscript/ast.cpp | 2 +- src/zscript/vm.h | 4 ++-- src/zscript/zcc_expr.cpp | 2 ++ 10 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/autosegs.h b/src/autosegs.h index b32594d84..61872610c 100644 --- a/src/autosegs.h +++ b/src/autosegs.h @@ -37,6 +37,7 @@ #define REGMARKER(x) (x) typedef void * const REGINFO; +typedef void * NCREGINFO; // List of Action functons extern REGINFO ARegHead; @@ -72,7 +73,7 @@ class FAutoSegIterator } Probe = Head; } - REGINFO operator*() const + NCREGINFO operator*() const { return *Probe; } diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 9d7bcd6b5..1f346d526 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -792,7 +792,7 @@ void SetDehParams(FState *state, int codepointer) sym = dyn_cast(RUNTIME_CLASS(AInventory)->Symbols.FindSymbol(FName(MBFCodePointers[codepointer].name), true)); if (sym == NULL) return; - if (codepointer < 0 || codepointer >= countof(MBFCodePointerFactories)) + if (codepointer < 0 || (unsigned)codepointer >= countof(MBFCodePointerFactories)) { // This simply should not happen. Printf("Unmanaged dehacked codepointer alias num %i\n", codepointer); diff --git a/src/d_netinfo.cpp b/src/d_netinfo.cpp index 8bec1bcca..5814c0327 100644 --- a/src/d_netinfo.cpp +++ b/src/d_netinfo.cpp @@ -723,7 +723,7 @@ void D_WriteUserInfoStrings (int pnum, BYTE **stream, bool compact) case NAME_PlayerClass: *stream += sprintf(*((char **)stream), "\\%s", info->GetPlayerClassNum() == -1 ? "Random" : - D_EscapeUserInfo(info->GetPlayerClassType()->DisplayName.GetChars())); + D_EscapeUserInfo(info->GetPlayerClassType()->DisplayName.GetChars()).GetChars()); break; case NAME_Skin: diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 18a3b47f0..cc0a077f2 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -101,7 +101,7 @@ void DumpTypeTable() for (size_t i = 0; i < countof(TypeTable.TypeHash); ++i) { int len = 0; - Printf("%4d:", i); + Printf("%4zu:", i); for (PType *ty = TypeTable.TypeHash[i]; ty != NULL; ty = ty->HashNext) { Printf(" -> %s", ty->IsKindOf(RUNTIME_CLASS(PNamedType)) ? static_cast(ty)->TypeName.GetChars(): ty->GetClass()->TypeName.GetChars()); @@ -122,7 +122,7 @@ void DumpTypeTable() } Printf("\n"); } - Printf("Used buckets: %d/%u (%.2f%%) for %d entries\n", used, countof(TypeTable.TypeHash), double(used)/countof(TypeTable.TypeHash)*100, all); + Printf("Used buckets: %d/%lu (%.2f%%) for %d entries\n", used, countof(TypeTable.TypeHash), double(used)/countof(TypeTable.TypeHash)*100, all); Printf("Min bucket size: %d\n", min); Printf("Max bucket size: %d\n", max); Printf("Avg bucket size: %.2f\n", double(all) / used); diff --git a/src/tarray.h b/src/tarray.h index 84a21728c..d62d75e28 100644 --- a/src/tarray.h +++ b/src/tarray.h @@ -389,7 +389,7 @@ public: if ((*this)[i] != NULL) delete (*this)[i]; } - Clear(); + this->Clear(); } }; @@ -461,7 +461,12 @@ template struct THashTraits { // Returns the hash value for a key. hash_t Hash(const KT key) { return (hash_t)(intptr_t)key; } - hash_t Hash(double key) { return ((hash_t *)&key)[0] ^ ((hash_t *)&key)[1]; } + hash_t Hash(double key) + { + hash_t keyhash[2]; + memcpy(&keyhash, &key, sizeof(keyhash)); + return keyhash[0] ^ keyhash[1]; + } // Compares two keys, returning zero if they are the same. int Compare(const KT left, const KT right) { return left != right; } @@ -470,14 +475,24 @@ template struct THashTraits template<> struct THashTraits { // Use all bits when hashing singles instead of converting them to ints. - hash_t Hash(float key) { return *((hash_t *)&key); } + hash_t Hash(float key) + { + hash_t keyhash; + memcpy(&keyhash, &key, sizeof(keyhash)); + return keyhash; + } int Compare(float left, float right) { return left != right; } }; template<> struct THashTraits { // Use all bits when hashing doubles instead of converting them to ints. - hash_t Hash(double key) { return ((hash_t *)&key)[0] ^ ((hash_t *)&key)[1]; } + hash_t Hash(double key) + { + hash_t keyhash[2]; + memcpy(&keyhash, &key, sizeof(keyhash)); + return keyhash[0] ^ keyhash[1]; + } int Compare(double left, double right) { return left != right; } }; diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index aaaf2d4f4..302d22f68 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -4350,8 +4350,8 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetRoll) { PARAM_ACTION_PROLOGUE; PARAM_ANGLE (roll); - PARAM_INT_OPT (flags); { flags = 0; } - PARAM_INT_OPT (ptr); { ptr = AAPTR_DEFAULT; } + PARAM_INT_OPT (flags) { flags = 0; } + PARAM_INT_OPT (ptr) { ptr = AAPTR_DEFAULT; } AActor *ref = COPY_AAPTR(self, ptr); if (ref != NULL) diff --git a/src/thingdef/thingdef_expression.cpp b/src/thingdef/thingdef_expression.cpp index 1ab720c35..a877a4e1a 100644 --- a/src/thingdef/thingdef_expression.cpp +++ b/src/thingdef/thingdef_expression.cpp @@ -3130,7 +3130,7 @@ FxExpression *FxVMFunctionCall::Resolve(FCompileContext& ctx) return NULL; } TArray &rets = Function->Variants[0].Proto->ReturnTypes; - if (rets.Size() == NULL) + if (rets.Size() == 0) { ReturnType = TypeVoid; } diff --git a/src/zscript/ast.cpp b/src/zscript/ast.cpp index c7ebf801e..bc1966142 100644 --- a/src/zscript/ast.cpp +++ b/src/zscript/ast.cpp @@ -83,7 +83,7 @@ public: NeedSpace = false; if (NestDepth > 0) { - Str.AppendFormat("%*s", NestDepth, ""); + Str.AppendFormat("%*s", (int)NestDepth, ""); } if (ConsecOpens > 0) { diff --git a/src/zscript/vm.h b/src/zscript/vm.h index 06f289bb4..1bbded861 100644 --- a/src/zscript/vm.h +++ b/src/zscript/vm.h @@ -476,8 +476,8 @@ struct VMValue { Kill(); a = v; - atag = atag; - Type = atag; + this->atag = atag; + Type = REGT_POINTER; } void SetNil() { diff --git a/src/zscript/zcc_expr.cpp b/src/zscript/zcc_expr.cpp index 32d0c9374..3ab977a2f 100644 --- a/src/zscript/zcc_expr.cpp +++ b/src/zscript/zcc_expr.cpp @@ -663,7 +663,9 @@ static void DtoS(ZCC_ExprConstant *expr, FSharedStringArena &str_arena) // Convert to a string with enough precision such that converting // back to a double will not lose any data. char str[64]; + IGNORE_FORMAT_PRE int len = mysnprintf(str, countof(str), "%H", expr->DoubleVal); + IGNORE_FORMAT_POST expr->StringVal = str_arena.Alloc(str, len); expr->Type = TypeString; }