Skip to content

Commit

Permalink
Getting rid of useless reinterpret_casts, and converting many more
Browse files Browse the repository at this point in the history
to static_casts.
  • Loading branch information
marzojr committed Nov 16, 2018
1 parent d770e7f commit 07ab3ca
Show file tree
Hide file tree
Showing 53 changed files with 347 additions and 354 deletions.
4 changes: 2 additions & 2 deletions audio/AudioMixer.cc
Expand Up @@ -50,7 +50,7 @@ num_channels(num_channels_), channels(0), id_counter(0)
desired.freq = sample_rate_;
desired.channels = stereo_?2:1;
desired.callback = sdlAudioCallback;
desired.userdata = reinterpret_cast<void*>(this);
desired.userdata = this;

// Set update rate to 20 Hz, or there abouts. This should be more then adequate for everyone
desired.samples=1;
Expand Down Expand Up @@ -368,7 +368,7 @@ void AudioMixer::get2DPosition(sint32 instance_id, int &distance, int &angle)

void AudioMixer::sdlAudioCallback(void *userdata, Uint8 *stream, int len)
{
AudioMixer *mixer = reinterpret_cast<AudioMixer *>(userdata);
AudioMixer *mixer = static_cast<AudioMixer *>(userdata);

mixer->MixAudio(reinterpret_cast<sint16*>(stream), len);
}
Expand Down
8 changes: 4 additions & 4 deletions audio/OggAudioSample.cc
Expand Up @@ -103,7 +103,7 @@ bool OggAudioSample::isThis(IDataSource *oggdata)

void OggAudioSample::initDecompressor(void *DecompData) const
{
OggDecompData *decomp = reinterpret_cast<OggDecompData *>(DecompData);
OggDecompData *decomp = static_cast<OggDecompData *>(DecompData);

if (locked)
throw exult_exception("Attempted to play OggAudioSample on more than one channel at the same time.");
Expand Down Expand Up @@ -136,7 +136,7 @@ void OggAudioSample::rewind(void *DecompData) const

void OggAudioSample::freeDecompressor(void *DecompData) const
{
OggDecompData *decomp = reinterpret_cast<OggDecompData *>(DecompData);
OggDecompData *decomp = static_cast<OggDecompData *>(DecompData);
if (decomp->freed)
return;
decomp->freed = true;
Expand All @@ -150,7 +150,7 @@ void OggAudioSample::freeDecompressor(void *DecompData) const

uint32 OggAudioSample::decompressFrame(void *DecompData, void *samples) const
{
OggDecompData *decomp = reinterpret_cast<OggDecompData *>(DecompData);
OggDecompData *decomp = static_cast<OggDecompData *>(DecompData);

vorbis_info *info = ov_info(&decomp->ov,-1);

Expand All @@ -167,7 +167,7 @@ uint32 OggAudioSample::decompressFrame(void *DecompData, void *samples) const
const int bigendianp = 1;
#endif

long count = ov_read(&decomp->ov,reinterpret_cast<char*>(samples),frame_size,bigendianp,2,1,&decomp->bitstream);
long count = ov_read(&decomp->ov,static_cast<char*>(samples),frame_size,bigendianp,2,1,&decomp->bitstream);

//if (count == OV_EINVAL || count == 0) {
if (count <= 0) return 0;
Expand Down
4 changes: 2 additions & 2 deletions audio/RawAudioSample.cc
Expand Up @@ -44,7 +44,7 @@ RawAudioSample::~RawAudioSample()

void RawAudioSample::initDecompressor(void *DecompData) const
{
RawDecompData *decomp = reinterpret_cast<RawDecompData *>(DecompData);
RawDecompData *decomp = static_cast<RawDecompData *>(DecompData);
decomp->pos = start_pos;
}

Expand All @@ -55,7 +55,7 @@ void RawAudioSample::rewind(void *DecompData) const

uint32 RawAudioSample::decompressFrame(void *DecompData, void *samples) const
{
RawDecompData *decomp = reinterpret_cast<RawDecompData *>(DecompData);
RawDecompData *decomp = static_cast<RawDecompData *>(DecompData);

if (decomp->pos == buffer_size) return 0;

Expand Down
8 changes: 4 additions & 4 deletions audio/VocAudioSample.cc
Expand Up @@ -163,7 +163,7 @@ VocAudioSample::~VocAudioSample()

void VocAudioSample::initDecompressor(void *DecompData) const
{
VocDecompData *decomp = reinterpret_cast<VocDecompData *>(DecompData);
VocDecompData *decomp = static_cast<VocDecompData *>(DecompData);
decomp->pos = 0x1a;
decomp->compression = 0;
decomp->adpcm_reference = -1;
Expand Down Expand Up @@ -223,7 +223,7 @@ void VocAudioSample::decode_ADPCM_4(uint8* inBuf,

bool VocAudioSample::advanceChunk(void *DecompData) const
{
VocDecompData *decomp = reinterpret_cast<VocDecompData *>(DecompData);
VocDecompData *decomp = static_cast<VocDecompData *>(DecompData);

if (decomp->pos == buffer_size) return false;

Expand Down Expand Up @@ -291,7 +291,7 @@ bool VocAudioSample::advanceChunk(void *DecompData) const

uint32 VocAudioSample::decompressFrame(void *DecompData, void *samples) const
{
VocDecompData *decomp = reinterpret_cast<VocDecompData *>(DecompData);
VocDecompData *decomp = static_cast<VocDecompData *>(DecompData);

// At end of stream??
if (!decomp->chunk_remain && !advanceChunk(decomp)) return 0;
Expand Down Expand Up @@ -324,7 +324,7 @@ uint32 VocAudioSample::decompressFrame(void *DecompData, void *samples) const
{
bytes_used = num_samples/2;
if (decomp->adpcm_reference == -1) bytes_used++;
decode_ADPCM_4(buffer+decomp->pos, bytes_used, reinterpret_cast<uint8*>(samples), decomp->adpcm_reference, decomp->adpcm_scale);
decode_ADPCM_4(buffer+decomp->pos, bytes_used, static_cast<uint8*>(samples), decomp->adpcm_reference, decomp->adpcm_scale);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion audio/midi_drivers/timidity/timidity_playmidi.cpp
Expand Up @@ -1088,7 +1088,7 @@ void Timidity_GenerateSamples(void *stream, int samples)
do_compute_data(AUDIO_BUFFER_SIZE);
samples -= AUDIO_BUFFER_SIZE;
s32tobuf(stream, common_buffer, channels*AUDIO_BUFFER_SIZE);
stream = AUDIO_BUFFER_SIZE*sample_size + reinterpret_cast<uint8*>(stream);
stream = AUDIO_BUFFER_SIZE*sample_size + static_cast<uint8*>(stream);
buffer_pointer=common_buffer;
buffered_count=0;
}
Expand Down
23 changes: 10 additions & 13 deletions files/databuf.h
Expand Up @@ -115,7 +115,7 @@ class StreamDataSource: public DataSource {
};

void read(void *b, size_t len) {
in->read(reinterpret_cast<char *>(b), len);
in->read(static_cast<char *>(b), len);
};

virtual void read(std::string& s, size_t len) {
Expand Down Expand Up @@ -144,7 +144,7 @@ class StreamDataSource: public DataSource {
};

virtual void write(const void *b, size_t len) {
out->write(reinterpret_cast<const char *>(b), len);
out->write(static_cast<const char *>(b), len);
};

virtual void write(const std::string &s) {
Expand Down Expand Up @@ -209,15 +209,15 @@ class BufferDataSource: public DataSource {
BufferDataSource(const void *data, size_t len) {
// data can be NULL if len is also 0
assert(data != 0 || len == 0);
buf = reinterpret_cast<const unsigned char *>(data);
buf = static_cast<const unsigned char *>(data);
buf_ptr = const_cast<unsigned char *>(buf);
size = len;
};

void load(char *data, size_t len) {
void load(void *data, size_t len) {
// data can be NULL if len is also 0
assert(data != 0 || len == 0);
buf = buf_ptr = reinterpret_cast<unsigned char *>(data);
buf = buf_ptr = static_cast<unsigned char *>(data);
size = len;
};

Expand Down Expand Up @@ -387,8 +387,8 @@ class StackBufferDataSource : protected BufferDataSource {
inline uint32 pop4() {
return read4();
}
inline void pop(uint8 *out, const uint32 size) {
read(reinterpret_cast<char *>(out), size);
inline void pop(void *out, const uint32 size) {
read(static_cast<char *>(out), size);
};

//
Expand Down Expand Up @@ -468,23 +468,20 @@ class ExultDataSource: public BufferDataSource {
ExultDataSource(const File_spec &fname, int index)
: BufferDataSource(0, 0) {
U7object obj(fname, index);
buf = reinterpret_cast<unsigned char *>(obj.retrieve(size));
buf_ptr = const_cast<unsigned char *>(buf);
buf = buf_ptr = reinterpret_cast<unsigned char *>(obj.retrieve(size));
}

ExultDataSource(const File_spec &fname0, const File_spec &fname1, int index)
: BufferDataSource(0, 0) {
U7multiobject obj(fname0, fname1, index);
buf = reinterpret_cast<unsigned char *>(obj.retrieve(size));
buf_ptr = const_cast<unsigned char *>(buf);
buf = buf_ptr = reinterpret_cast<unsigned char *>(obj.retrieve(size));
}

ExultDataSource(const File_spec &fname0, const File_spec &fname1,
const File_spec &fname2, int index)
: BufferDataSource(0, 0) {
U7multiobject obj(fname0, fname1, fname2, index);
buf = reinterpret_cast<unsigned char *>(obj.retrieve(size));
buf_ptr = const_cast<unsigned char *>(buf);
buf = buf_ptr = reinterpret_cast<unsigned char *>(obj.retrieve(size));
}

~ExultDataSource() {
Expand Down
4 changes: 2 additions & 2 deletions files/listfiles.cc
Expand Up @@ -60,7 +60,7 @@ int U7ListFiles(const std::string &mask, FileList &files) {
#ifdef UNICODE
const char *name = path.c_str();
nLen = strlen(name) + 1;
LPTSTR lpszT2 = reinterpret_cast<LPTSTR>(_alloca(nLen * 2));
LPTSTR lpszT2 = static_cast<LPTSTR>(_alloca(nLen * 2));
lpszT = lpszT2;
MultiByteToWideChar(CP_ACP, 0, name, -1, lpszT2, nLen);
#else
Expand Down Expand Up @@ -121,7 +121,7 @@ int U7ListFiles(const std::string &mask, FileList &files) {
);
#ifdef UNICODE
nLen2 = _tcslen(lpMsgBuf) + 1;
str = reinterpret_cast<char *>(_alloca(nLen));
str = static_cast<char *>(_alloca(nLen));
WideCharToMultiByte(CP_ACP, 0, lpMsgBuf, -1, str, nLen2, NULL, NULL);
#else
str = lpMsgBuf;
Expand Down
10 changes: 5 additions & 5 deletions files/snprintf.cc
Expand Up @@ -422,7 +422,7 @@ int asprintf(char **ptr, const char *fmt, /*args*/ ...) {
str_l = portable_vsnprintf(NULL, static_cast<size_t>(0), fmt, ap);
va_end(ap);
assert(str_l >= 0); /* possible integer overflow if str_m > INT_MAX */
*ptr = reinterpret_cast<char *>(malloc(str_m = static_cast<size_t>(str_l) + 1));
*ptr = static_cast<char *>(malloc(str_m = static_cast<size_t>(str_l) + 1));
if (*ptr == NULL) {
errno = ENOMEM;
str_l = -1;
Expand Down Expand Up @@ -450,7 +450,7 @@ int vasprintf(char **ptr, const char *fmt, va_list ap) {
va_end(ap2);
}
assert(str_l >= 0); /* possible integer overflow if str_m > INT_MAX */
*ptr = reinterpret_cast<char *>(malloc(str_m = static_cast<size_t>(str_l) + 1));
*ptr = static_cast<char *>(malloc(str_m = static_cast<size_t>(str_l) + 1));
if (*ptr == NULL) {
errno = ENOMEM;
str_l = -1;
Expand All @@ -476,7 +476,7 @@ int asnprintf(char **ptr, size_t str_m, const char *fmt, /*args*/ ...) {
/* if str_m is 0, no buffer is allocated, just set *ptr to NULL */
if (str_m == 0) { /* not interested in resulting string, just return size */
} else {
*ptr = reinterpret_cast<char *>(malloc(str_m));
*ptr = static_cast<char *>(malloc(str_m));
if (*ptr == NULL) {
errno = ENOMEM;
str_l = -1;
Expand Down Expand Up @@ -508,7 +508,7 @@ int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap) {
/* if str_m is 0, no buffer is allocated, just set *ptr to NULL */
if (str_m == 0) { /* not interested in resulting string, just return size */
} else {
*ptr = reinterpret_cast<char *>(malloc(str_m));
*ptr = static_cast<char *>(malloc(str_m));
if (*ptr == NULL) {
errno = ENOMEM;
str_l = -1;
Expand Down Expand Up @@ -745,7 +745,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) {
else if (precision == 0) str_arg_l = 0;
else {
/* memchr on HP does not like n > 2^31 !!! */
const char *q = reinterpret_cast<const char *>(memchr(str_arg, '\0',
const char *q = static_cast<const char *>(memchr(str_arg, '\0',
precision <= 0x7fffffff ? precision : 0x7fffffff));
str_arg_l = !q ? precision : (q - str_arg);
}
Expand Down
6 changes: 3 additions & 3 deletions files/utils.cc
Expand Up @@ -801,14 +801,14 @@ void U7copy(
throw(e);
}
size_t bufsize = 0x8000;
unsigned char *buf = new unsigned char[0x8000];
char *buf = new char[0x8000];
in.seekg(0, ios::end); // Get filesize.
size_t filesize = in.tellg();
in.seekg(0, ios::beg);
while (filesize > 0) { // Copy.
size_t toread = bufsize < filesize ? bufsize : filesize;
in.read(reinterpret_cast<char *>(buf), toread);
out.write(reinterpret_cast<char *>(buf), toread);
in.read(buf, toread);
out.write(buf, toread);
filesize -= toread;
}
out.flush();
Expand Down
4 changes: 2 additions & 2 deletions files/zip/zip.cc
Expand Up @@ -470,9 +470,9 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const voidp buf, unsigned l
if (file->in_opened_file_inzip == 0)
return ZIP_PARAMERROR;

file->ci.stream.next_in = reinterpret_cast<Bytef *>(buf);
file->ci.stream.next_in = static_cast<Bytef *>(buf);
file->ci.stream.avail_in = len;
file->ci.crc32 = crc32(file->ci.crc32, reinterpret_cast<Bytef *>(buf), len);
file->ci.crc32 = crc32(file->ci.crc32, static_cast<Bytef *>(buf), len);

while ((err == ZIP_OK) && (file->ci.stream.avail_in > 0)) {
if (file->ci.stream.avail_out == 0) {
Expand Down
2 changes: 1 addition & 1 deletion gamemap.cc
Expand Up @@ -1358,7 +1358,7 @@ bool Game_map::insert_terrain(
}
}
} else
memset(reinterpret_cast<char *>(buf), 0, ntiles * nbytes);
memset(buf, 0, ntiles * nbytes);
Chunk_terrain *new_terrain = new Chunk_terrain(&buf[0], v2_chunks);
// Insert in list.
chunk_terrains->insert(chunk_terrains->begin() + tnum + 1, new_terrain);
Expand Down
6 changes: 2 additions & 4 deletions gamewin.cc
Expand Up @@ -2991,9 +2991,7 @@ void Game_window::emulate_cache(Map_chunk *olist, Map_chunk *nlist) {
old_maxy = c_num_chunks + oldy + 2;
if (nmap == omap) { // Same map?
// Set to 0
// No casting _should_ be necessary at this point.
// Who needs this?
memset(reinterpret_cast<char *>(nearby), 0, sizeof(nearby));
memset(nearby, 0, sizeof(nearby));
// Figure new range.
int new_minx = c_num_chunks + newx - 2,
new_maxx = c_num_chunks + newx + 2;
Expand All @@ -3018,7 +3016,7 @@ void Game_window::emulate_cache(Map_chunk *olist, Map_chunk *nlist) {
}
}
} else // New map, so cache out all of old.
memset(reinterpret_cast<char *>(nearby), 0, sizeof(nearby));
memset(nearby, 0, sizeof(nearby));

// Swap out chunks no longer nearby (0).
Game_object_vector removes;
Expand Down
2 changes: 1 addition & 1 deletion imagewin/ArbScaler.h
Expand Up @@ -72,7 +72,7 @@ class ArbScaler {
// Call this to scale a section of the screen
inline bool Scale(SDL_Surface *texture, sint32 sx, sint32 sy, sint32 sw, sint32 sh,
SDL_Surface *dest, sint32 dx, sint32 dy, sint32 dw, sint32 dh, bool clamp_src) const {
uint8 *pixel = reinterpret_cast<uint8 *>(dest->pixels) + dx * dest->format->BytesPerPixel + dy * dest->pitch;
uint8 *pixel = static_cast<uint8 *>(dest->pixels) + dx * dest->format->BytesPerPixel + dy * dest->pitch;
sint32 pitch = dest->pitch;

SDL_PixelFormat *src_format = texture->format;
Expand Down
2 changes: 1 addition & 1 deletion imagewin/BilinearScalerInternal_2x.cpp
Expand Up @@ -30,7 +30,7 @@ bool BilinearScalerInternal_2x(SDL_Surface *tex, sint32 sx, sint32 sy, sint32 sw
ignore_unused_variable_warning(dh);
// Source buffer pointers
int tpitch = tex->pitch / sizeof(uintS);
uintS *texel = reinterpret_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *texel = static_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *tline_end = texel + (sw - 1);
uintS *tex_end = texel + (sh - 4) * tpitch;
int tex_diff = (tpitch * 4) - sw;
Expand Down
2 changes: 1 addition & 1 deletion imagewin/BilinearScalerInternal_Arb.cpp
Expand Up @@ -28,7 +28,7 @@ bool BilinearScalerInternal_Arb(SDL_Surface *tex, sint32 sx, sint32 sy, sint32 s
uint8 *pixel, sint32 dw, sint32 dh, sint32 pitch, bool clamp_src) {
// Source buffer pointers
int tpitch = tex->pitch / sizeof(uintS);
uintS *texel = reinterpret_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *texel = static_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *tline_end = texel + (sw - 1);
uintS *tex_end = texel + (sh - 4) * tpitch;
int tex_diff = (tpitch * 4) - sw;
Expand Down
2 changes: 1 addition & 1 deletion imagewin/BilinearScalerInternal_X1Y12.cpp
Expand Up @@ -29,7 +29,7 @@ bool BilinearScalerInternal_X1Y12(SDL_Surface *tex, sint32 sx, sint32 sy, sint32
ignore_unused_variable_warning(dh);
// Source buffer pointers
int tpitch = tex->pitch / sizeof(uintS);
uintS *texel = reinterpret_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *texel = static_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *tline_end = texel + (sw);
uintS *tex_end = texel + (sh - 5) * tpitch;
int tex_diff = (tpitch * 5) - sw;
Expand Down
2 changes: 1 addition & 1 deletion imagewin/BilinearScalerInternal_X2Y24.cpp
Expand Up @@ -29,7 +29,7 @@ bool BilinearScalerInternal_X2Y24(SDL_Surface *tex, sint32 sx, sint32 sy, sint32
ignore_unused_variable_warning(dh);
// Source buffer pointers
int tpitch = tex->pitch / sizeof(uintS);
uintS *texel = reinterpret_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *texel = static_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *tline_end = texel + (sw - 1);
uintS *tex_end = texel + (sh - 5) * tpitch;
int tex_diff = (tpitch * 5) - sw;
Expand Down
2 changes: 1 addition & 1 deletion imagewin/PointScaler.cpp
Expand Up @@ -32,7 +32,7 @@ template<class uintX, class Manip, class uintS = uintX> class PointScalerInterna
ignore_unused_variable_warning(clamp_src);
// Source buffer pointers
int tpitch = tex->pitch / sizeof(uintS);
uintS *texel = reinterpret_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *texel = static_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *tline_end = texel + sw;
uintS *tex_end = texel + sh * tpitch;
int tex_diff = tpitch - sw;
Expand Down
3 changes: 1 addition & 2 deletions imagewin/ibuf16.cc
Expand Up @@ -146,8 +146,7 @@ void Image_buffer16::copy(
unsigned short *from = get_pixels() + yfrom * line_width + srcx;
// Go through lines.
while (srch--) {
memmove(reinterpret_cast<char *>(to),
reinterpret_cast<char *>(from), srcw * 2);
memmove(to, from, srcw * 2);
to += ynext;
from += ynext;
}
Expand Down
3 changes: 1 addition & 2 deletions imagewin/ibuf8.cc
Expand Up @@ -60,8 +60,7 @@ void Image_buffer8::copy(
unsigned char *from = bits + yfrom * line_width + srcx;
// Go through lines.
while (srch--) {
std::memmove(reinterpret_cast<char *>(to),
reinterpret_cast<char *>(from), srcw);
std::memmove(to, from, srcw);
to += ynext;
from += ynext;
}
Expand Down

0 comments on commit 07ab3ca

Please sign in to comment.