summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-11-12 08:10:22 +0000
committerrubidium <rubidium@openttd.org>2011-11-12 08:10:22 +0000
commitbd64bf6372399bad1a92565ae7d3c243658d241f (patch)
tree7af646337e5ddafe68f0d701711c41ef89d21491 /src
parenta8d33a4d89f11c45b9690481b08df3c800292005 (diff)
downloadopenttd-bd64bf6372399bad1a92565ae7d3c243658d241f.tar.xz
(svn r23193) -Codechange: don't cast away const unneededly
Diffstat (limited to 'src')
-rw-r--r--src/hotkeys.cpp2
-rw-r--r--src/network/core/address.cpp4
-rw-r--r--src/network/core/udp.cpp2
-rw-r--r--src/newgrf_debug_gui.cpp20
-rw-r--r--src/settings.cpp24
-rw-r--r--src/table/newgrf_debug_data.h6
6 files changed, 29 insertions, 29 deletions
diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp
index 674c10c73..70fe72aea 100644
--- a/src/hotkeys.cpp
+++ b/src/hotkeys.cpp
@@ -75,7 +75,7 @@ static uint16 ParseCode(const char *start, const char *end)
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;
}
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp
index 371f53403..3b3c9f4aa 100644
--- a/src/network/core/address.cpp
+++ b/src/network/core/address.cpp
@@ -39,10 +39,10 @@ uint16 NetworkAddress::GetPort() const
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();
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index 482f67d93..4a0029eed 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -101,7 +101,7 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a
#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 */
diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp
index f1d628712..46a885a6f 100644
--- a/src/newgrf_debug_gui.cpp
+++ b/src/newgrf_debug_gui.cpp
@@ -189,7 +189,7 @@ public:
* @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 @@ struct NewGRFInspectWindow : Window {
}
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 @@ struct NewGRFInspectWindow : Window {
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 @@ struct NewGRFInspectWindow : Window {
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();
}
diff --git a/src/settings.cpp b/src/settings.cpp
index cd6003cdc..b407f39f6 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -248,17 +248,17 @@ static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
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 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
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 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
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 @@ void IConsoleListSettings(const char *prefilter)
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));
}
diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h
index a07ccc006..9ccbc5544 100644
--- a/src/table/newgrf_debug_data.h
+++ b/src/table/newgrf_debug_data.h
@@ -298,9 +298,9 @@ class NIHIndustry : public NIHelper {
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 @@ class NIHTown : public NIHelper {
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);