changeset 18357:21b01031dbd7 draft

(svn r23193) -Codechange: don't cast away const unneededly
author rubidium <rubidium@openttd.org>
date Sat, 12 Nov 2011 08:10:22 +0000
parents 2b675888ed9d
children 90d7214be2a3
files src/hotkeys.cpp src/network/core/address.cpp src/network/core/udp.cpp src/newgrf_debug_gui.cpp src/settings.cpp src/table/newgrf_debug_data.h
diffstat 6 files changed, 29 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotkeys.cpp
+++ b/src/hotkeys.cpp
@@ -75,7 +75,7 @@
 	if (end - start == 1) {
 		if (*start >= 'a' && *start <= 'z') return *start - ('a'-'A');
 		/* Ignore invalid keycodes */
-		if (*(uint8*)start < 128) return *start;
+		if (*(const uint8 *)start < 128) return *start;
 	}
 	return 0;
 }
--- a/src/network/core/address.cpp
+++ b/src/network/core/address.cpp
@@ -39,10 +39,10 @@
 	switch (this->address.ss_family) {
 		case AF_UNSPEC:
 		case AF_INET:
-			return ntohs(((struct sockaddr_in *)&this->address)->sin_port);
+			return ntohs(((const struct sockaddr_in *)&this->address)->sin_port);
 
 		case AF_INET6:
-			return ntohs(((struct sockaddr_in6 *)&this->address)->sin6_port);
+			return ntohs(((const struct sockaddr_in6 *)&this->address)->sin6_port);
 
 		default:
 			NOT_REACHED();
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -101,7 +101,7 @@
 #endif
 
 		/* Send the buffer */
-		int res = sendto(s->second, (const char*)p->buffer, p->size, 0, (struct sockaddr *)send.GetAddress(), send.GetAddressLength());
+		int res = sendto(s->second, (const char*)p->buffer, p->size, 0, (const struct sockaddr *)send.GetAddress(), send.GetAddressLength());
 		DEBUG(net, 7, "[udp] sendto(%s)", send.GetAddressAsString());
 
 		/* Check for any errors, but ignore it otherwise */
--- a/src/newgrf_debug_gui.cpp
+++ b/src/newgrf_debug_gui.cpp
@@ -189,7 +189,7 @@
 	 * @param grfid Parameter for the PSA. Only required for items with parameters.
 	 * @return Pointer to the first position of the storage array or NULL if not present.
 	 */
-	virtual int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
+	virtual const int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
 	{
 		return NULL;
 	}
@@ -398,7 +398,7 @@
 		}
 
 		uint psa_size = nih->GetPSASize(index, this->caller_grfid);
-		int32 *psa = nih->GetPSAFirstPosition(index, this->caller_grfid);
+		const int32 *psa = nih->GetPSAFirstPosition(index, this->caller_grfid);
 		if (psa_size != 0 && psa != NULL) {
 			if (nih->PSAWithParameter()) {
 				this->DrawString(r, i++, "Persistent storage [%08X]:", BSWAP32(this->caller_grfid));
@@ -414,12 +414,12 @@
 		if (nif->properties != NULL) {
 			this->DrawString(r, i++, "Properties:");
 			for (const NIProperty *nip = nif->properties; nip->name != NULL; nip++) {
-				void *ptr = (byte*)base + nip->offset;
+				const void *ptr = (const byte *)base + nip->offset;
 				uint value;
 				switch (nip->read_size) {
-					case 1: value = *(uint8  *)ptr; break;
-					case 2: value = *(uint16 *)ptr; break;
-					case 4: value = *(uint32 *)ptr; break;
+					case 1: value = *(const uint8  *)ptr; break;
+					case 2: value = *(const uint16 *)ptr; break;
+					case 4: value = *(const uint32 *)ptr; break;
 					default: NOT_REACHED();
 				}
 
@@ -448,12 +448,12 @@
 			this->DrawString(r, i++, "Callbacks:");
 			for (const NICallback *nic = nif->callbacks; nic->name != NULL; nic++) {
 				if (nic->cb_bit != CBM_NO_BIT) {
-					void *ptr = (byte*)base_spec + nic->offset;
+					const void *ptr = (const byte *)base_spec + nic->offset;
 					uint value;
 					switch (nic->read_size) {
-						case 1: value = *(uint8  *)ptr; break;
-						case 2: value = *(uint16 *)ptr; break;
-						case 4: value = *(uint32 *)ptr; break;
+						case 1: value = *(const uint8  *)ptr; break;
+						case 2: value = *(const uint16 *)ptr; break;
+						case 4: value = *(const uint32 *)ptr; break;
 						default: NOT_REACHED();
 					}
 
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -248,17 +248,17 @@
 static void MakeIntList(char *buf, const char *last, const void *array, int nelems, VarType type)
 {
 	int i, v = 0;
-	byte *p = (byte*)array;
+	const byte *p = (const byte *)array;
 
 	for (i = 0; i != nelems; i++) {
 		switch (type) {
 		case SLE_VAR_BL:
-		case SLE_VAR_I8:  v = *(int8*)p;   p += 1; break;
-		case SLE_VAR_U8:  v = *(byte*)p;   p += 1; break;
-		case SLE_VAR_I16: v = *(int16*)p;  p += 2; break;
-		case SLE_VAR_U16: v = *(uint16*)p; p += 2; break;
-		case SLE_VAR_I32: v = *(int32*)p;  p += 4; break;
-		case SLE_VAR_U32: v = *(uint32*)p; p += 4; break;
+		case SLE_VAR_I8:  v = *(const   int8 *)p; p += 1; break;
+		case SLE_VAR_U8:  v = *(const  uint8 *)p; p += 1; break;
+		case SLE_VAR_I16: v = *(const  int16 *)p; p += 2; break;
+		case SLE_VAR_U16: v = *(const uint16 *)p; p += 2; break;
+		case SLE_VAR_I32: v = *(const  int32 *)p; p += 4; break;
+		case SLE_VAR_U32: v = *(const uint32 *)p; p += 4; break;
 		default: NOT_REACHED();
 		}
 		buf += seprintf(buf, last, (i == 0) ? "%d" : ",%d", v);
@@ -493,7 +493,7 @@
 					free(*(char**)ptr);
 					*(char**)ptr = p == NULL ? NULL : strdup((const char*)p);
 					break;
-				case SLE_VAR_CHAR: if (p != NULL) *(char*)ptr = *(char*)p; break;
+				case SLE_VAR_CHAR: if (p != NULL) *(char *)ptr = *(const char *)p; break;
 				default: NOT_REACHED();
 			}
 			break;
@@ -1947,10 +1947,10 @@
 	ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
 
 	if (sd->desc.cmd == SDT_STRING) {
-		IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char **)ptr : (const char *)ptr);
+		IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr);
 	} else {
 		if (sd->desc.cmd == SDT_BOOLX) {
-			snprintf(value, sizeof(value), (*(bool*)ptr == 1) ? "on" : "off");
+			snprintf(value, sizeof(value), (*(const bool*)ptr != 0) ? "on" : "off");
 		} else {
 			snprintf(value, sizeof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
 		}
@@ -1976,9 +1976,9 @@
 		const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
 
 		if (sd->desc.cmd == SDT_BOOLX) {
-			snprintf(value, lengthof(value), (*(bool*)ptr == 1) ? "on" : "off");
+			snprintf(value, lengthof(value), (*(const bool *)ptr != 0) ? "on" : "off");
 		} else if (sd->desc.cmd == SDT_STRING) {
-			snprintf(value, sizeof(value), "%s", (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char **)ptr : (const char *)ptr);
+			snprintf(value, sizeof(value), "%s", (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr);
 		} else {
 			snprintf(value, lengthof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
 		}
--- a/src/table/newgrf_debug_data.h
+++ b/src/table/newgrf_debug_data.h
@@ -298,9 +298,9 @@
 	void Resolve(ResolverObject *ro, uint32 index) const { extern void GetIndustryResolver(ResolverObject *ro, uint index); GetIndustryResolver(ro, index); }
 	uint GetPSASize(uint index, uint32 grfid) const      { return cpp_lengthof(PersistentStorage, storage); }
 
-	int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
+	const int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
 	{
-		Industry *i = (Industry *)this->GetInstance(index);
+		const Industry *i = (const Industry *)this->GetInstance(index);
 		if (i->psa == NULL) return NULL;
 		return (int32 *)(&i->psa->storage);
 	}
@@ -446,7 +446,7 @@
 	bool PSAWithParameter() const                        { return true; }
 	uint GetPSASize(uint index, uint32 grfid) const      { return cpp_lengthof(PersistentStorage, storage); }
 
-	int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
+	const int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
 	{
 		Town *t = Town::Get(index);