diff options
Diffstat (limited to 'src/lib/util')
37 files changed, 722 insertions, 721 deletions
diff --git a/src/lib/util/avhuff.cpp b/src/lib/util/avhuff.cpp index b9b9057193c..277f056c7ad 100644 --- a/src/lib/util/avhuff.cpp +++ b/src/lib/util/avhuff.cpp @@ -754,7 +754,7 @@ avhuff_error avhuff_decoder::decode_data(const UINT8 *source, UINT32 complength, // if we are decoding raw, set up the output parameters UINT8 *metastart, *videostart, *audiostart[16]; UINT32 audioxor, videoxor, videostride; - if (dest != NULL) + if (dest != nullptr) { // create a header dest[0] = 'c'; @@ -793,7 +793,7 @@ avhuff_error avhuff_decoder::decode_data(const UINT8 *source, UINT32 complength, metastart = m_config.metadata; for (int chnum = 0; chnum < channels; chnum++) audiostart[chnum] = (UINT8 *)m_config.audio[chnum]; - videostart = (m_config.video.valid()) ? reinterpret_cast<UINT8 *>(&m_config.video.pix(0)) : NULL; + videostart = (m_config.video.valid()) ? reinterpret_cast<UINT8 *>(&m_config.video.pix(0)) : nullptr; videostride = (m_config.video.valid()) ? m_config.video.rowpixels() * 2 : 0; // data is assumed to be native-endian @@ -805,22 +805,22 @@ avhuff_error avhuff_decoder::decode_data(const UINT8 *source, UINT32 complength, if (m_config.video.valid() && (m_config.video.width() < width || m_config.video.height() < height)) return AVHERR_VIDEO_TOO_LARGE; for (int chnum = 0; chnum < channels; chnum++) - if (m_config.audio[chnum] != NULL && m_config.maxsamples < samples) + if (m_config.audio[chnum] != nullptr && m_config.maxsamples < samples) return AVHERR_AUDIO_TOO_LARGE; - if (m_config.metadata != NULL && m_config.maxmetalength < metasize) + if (m_config.metadata != nullptr && m_config.maxmetalength < metasize) return AVHERR_METADATA_TOO_LARGE; // set the output values - if (m_config.actsamples != NULL) + if (m_config.actsamples != nullptr) *m_config.actsamples = samples; - if (m_config.actmetalength != NULL) + if (m_config.actmetalength != nullptr) *m_config.actmetalength = metasize; } // copy the metadata first if (metasize > 0) { - if (metastart != NULL) + if (metastart != nullptr) memcpy(metastart, source + srcoffs, metasize); srcoffs += metasize; } @@ -842,7 +842,7 @@ avhuff_error avhuff_decoder::decode_data(const UINT8 *source, UINT32 complength, } // decode the video data - if (width > 0 && height > 0 && videostart != NULL) + if (width > 0 && height > 0 && videostart != nullptr) { // decode the video avhuff_error err = decode_video(width, height, source + srcoffs, complength - srcoffs, videostart, videostride, videoxor); @@ -897,7 +897,7 @@ avhuff_error avhuff_decoder::decode_audio(int channels, int samples, const UINT8 // only process if the data is requested UINT8 *curdest = dest[chnum]; - if (curdest != NULL) + if (curdest != nullptr) { // reset and decode if (!m_flac_decoder.reset(48000, 1, samples, source, size)) @@ -941,7 +941,7 @@ avhuff_error avhuff_decoder::decode_audio(int channels, int samples, const UINT8 // only process if the data is requested UINT8 *curdest = dest[chnum]; - if (curdest != NULL) + if (curdest != nullptr) { INT16 prevsample = 0; diff --git a/src/lib/util/avhuff.h b/src/lib/util/avhuff.h index 26873292fdc..cdaa3ec5f3a 100644 --- a/src/lib/util/avhuff.h +++ b/src/lib/util/avhuff.h @@ -57,10 +57,10 @@ class avhuff_decompress_config public: avhuff_decompress_config() : maxsamples(0), - actsamples(NULL), + actsamples(nullptr), maxmetalength(0), - actmetalength(NULL), - metadata(NULL) + actmetalength(nullptr), + metadata(nullptr) { memset(audio, 0, sizeof(audio)); } @@ -90,7 +90,7 @@ public: // static helpers static UINT32 raw_data_size(const UINT8 *data); static UINT32 raw_data_size(UINT32 width, UINT32 height, UINT8 channels, UINT32 numsamples, UINT32 metadatasize = 0) { return 12 + channels * numsamples * 2 + width * height * 2; } - static avhuff_error assemble_data(dynamic_buffer &buffer, bitmap_yuy16 &bitmap, UINT8 channels, UINT32 numsamples, INT16 **samples, UINT8 *metadata = NULL, UINT32 metadatasize = 0); + static avhuff_error assemble_data(dynamic_buffer &buffer, bitmap_yuy16 &bitmap, UINT8 channels, UINT32 numsamples, INT16 **samples, UINT8 *metadata = nullptr, UINT32 metadatasize = 0); private: // delta-RLE Huffman encoder diff --git a/src/lib/util/aviio.cpp b/src/lib/util/aviio.cpp index 06b603e0e31..95d96ca6422 100644 --- a/src/lib/util/aviio.cpp +++ b/src/lib/util/aviio.cpp @@ -626,7 +626,7 @@ INLINE avi_stream *get_video_stream(avi_file *file) if (file->stream[streamnum].type == STREAMTYPE_VIDS) return &file->stream[streamnum]; - return NULL; + return nullptr; } @@ -657,14 +657,14 @@ INLINE avi_stream *get_audio_stream(avi_file *file, int channel, int *offset) { if (channel < file->stream[streamnum].channels) { - if (offset != NULL) + if (offset != nullptr) *offset = channel; return &file->stream[streamnum]; } channel -= file->stream[streamnum].channels; } - return NULL; + return nullptr; } @@ -693,9 +693,9 @@ INLINE avi_error set_stream_chunk_info(avi_stream *stream, UINT32 index, UINT64 { UINT32 newcount = MAX(index, stream->chunksalloc + 1000); avi_chunk_list *newchunks = (avi_chunk_list *)malloc(newcount * sizeof(stream->chunk[0])); - if (newchunks == NULL) + if (newchunks == nullptr) return AVIERR_NO_MEMORY; - if (stream->chunk != NULL) + if (stream->chunk != nullptr) { memcpy(newchunks, stream->chunk, stream->chunksalloc * sizeof(stream->chunk[0])); free(stream->chunk); @@ -818,9 +818,9 @@ INLINE avi_error expand_tempbuffer(avi_file *file, UINT32 length) { file->tempbuffersize = 2 * length; UINT8 *newbuffer = (UINT8 *)malloc(file->tempbuffersize); - if (newbuffer == NULL) + if (newbuffer == nullptr) return AVIERR_NO_MEMORY; - if (file->tempbuffer != NULL) + if (file->tempbuffer != nullptr) free(file->tempbuffer); file->tempbuffer = newbuffer; } @@ -850,14 +850,14 @@ INLINE avi_error expand_tempbuffer(avi_file *file, UINT32 length) avi_error avi_open(const char *filename, avi_file **file) { - avi_file *newfile = NULL; + avi_file *newfile = nullptr; file_error filerr; avi_error avierr; UINT64 length; /* allocate the file */ newfile = (avi_file *)malloc(sizeof(*newfile)); - if (newfile == NULL) + if (newfile == nullptr) return AVIERR_NO_MEMORY; memset(newfile, 0, sizeof(*newfile)); newfile->type = FILETYPE_READ; @@ -886,9 +886,9 @@ avi_error avi_open(const char *filename, avi_file **file) error: /* clean up after an error */ - if (newfile != NULL) + if (newfile != nullptr) { - if (newfile->file != NULL) + if (newfile->file != nullptr) osd_close(newfile->file); free(newfile); } @@ -914,7 +914,7 @@ error: avi_error avi_create(const char *filename, const avi_movie_info *info, avi_file **file) { - avi_file *newfile = NULL; + avi_file *newfile = nullptr; file_error filerr; avi_stream *stream; avi_error avierr; @@ -935,7 +935,7 @@ avi_error avi_create(const char *filename, const avi_movie_info *info, avi_file /* allocate the file */ newfile = (avi_file *)malloc(sizeof(*newfile)); - if (newfile == NULL) + if (newfile == nullptr) return AVIERR_NO_MEMORY; memset(newfile, 0, sizeof(*newfile)); newfile->type = FILETYPE_CREATE; @@ -955,7 +955,7 @@ avi_error avi_create(const char *filename, const avi_movie_info *info, avi_file /* allocate two streams */ newfile->stream = (avi_stream *)malloc(2 * sizeof(newfile->stream[0])); - if (newfile->stream == NULL) + if (newfile->stream == nullptr) { avierr = AVIERR_NO_MEMORY; goto error; @@ -1000,11 +1000,11 @@ avi_error avi_create(const char *filename, const avi_movie_info *info, avi_file error: /* clean up after an error */ - if (newfile != NULL) + if (newfile != nullptr) { - if (newfile->stream != NULL) + if (newfile->stream != nullptr) free(newfile->stream); - if (newfile->file != NULL) + if (newfile->file != nullptr) { osd_close(newfile->file); osd_rmfile(filename); @@ -1073,26 +1073,26 @@ avi_error avi_close(avi_file *file) for (strnum = 0; strnum < file->streams; strnum++) { avi_stream *stream = &file->stream[strnum]; - if (stream->huffyuv != NULL) + if (stream->huffyuv != nullptr) { huffyuv_data *huffyuv = stream->huffyuv; int table; for (table = 0; table < ARRAY_LENGTH(huffyuv->table); table++) - if (huffyuv->table[table].extralookup != NULL) + if (huffyuv->table[table].extralookup != nullptr) free(huffyuv->table[table].extralookup); free(huffyuv); } - if (stream->chunk != NULL) + if (stream->chunk != nullptr) free(stream->chunk); } /* free the file itself */ - if (file->soundbuf != NULL) + if (file->soundbuf != nullptr) free(file->soundbuf); - if (file->stream != NULL) + if (file->stream != nullptr) free(file->stream); - if (file->tempbuffer != NULL) + if (file->tempbuffer != nullptr) free(file->tempbuffer); free(file); return avierr; @@ -1228,7 +1228,7 @@ avi_error avi_read_video_frame(avi_file *file, UINT32 framenum, bitmap_yuy16 &bi /* get the video stream */ stream = get_video_stream(file); - if (stream == NULL) + if (stream == nullptr) return AVIERR_INVALID_STREAM; /* validate our ability to handle the data */ @@ -1301,7 +1301,7 @@ avi_error avi_read_sound_samples(avi_file *file, int channel, UINT32 firstsample /* get the audio stream */ stream = get_audio_stream(file, channel, &offset); - if (stream == NULL) + if (stream == nullptr) return AVIERR_INVALID_STREAM; /* validate our ability to handle the data */ @@ -1579,7 +1579,7 @@ static avi_error read_chunk_data(avi_file *file, const avi_chunk *chunk, UINT8 * /* allocate memory for the data */ *buffer = (UINT8 *)malloc(chunk->size); - if (*buffer == NULL) + if (*buffer == nullptr) return AVIERR_NO_MEMORY; /* read from the file */ @@ -1587,7 +1587,7 @@ static avi_error read_chunk_data(avi_file *file, const avi_chunk *chunk, UINT8 * if (filerr != FILERR_NONE || bytes_read != chunk->size) { free(*buffer); - *buffer = NULL; + *buffer = nullptr; return AVIERR_READ_ERROR; } @@ -1614,8 +1614,8 @@ static avi_error read_chunk_data(avi_file *file, const avi_chunk *chunk, UINT8 * static avi_error get_first_chunk(avi_file *file, const avi_chunk *parent, avi_chunk *newchunk) { - UINT64 startoffset = (parent != NULL && parent->type != 0) ? parent->offset + 12 : 0; - if (parent != NULL && parent->type != CHUNKTYPE_LIST && parent->type != CHUNKTYPE_RIFF && parent->type != 0) + UINT64 startoffset = (parent != nullptr && parent->type != 0) ? parent->offset + 12 : 0; + if (parent != nullptr && parent->type != CHUNKTYPE_LIST && parent->type != CHUNKTYPE_RIFF && parent->type != 0) return AVIERR_INVALID_DATA; return get_next_chunk_internal(file, parent, newchunk, startoffset); } @@ -1790,7 +1790,7 @@ static avi_error get_next_chunk_internal(avi_file *file, const avi_chunk *parent UINT32 bytesread; /* NULL parent implies the root */ - if (parent == NULL) + if (parent == nullptr) parent = &file->rootchunk; /* start at the current offset */ @@ -1843,7 +1843,7 @@ static avi_error read_movie_data(avi_file *file) int strindex; /* find the RIFF chunk */ - avierr = find_first_chunk(file, CHUNKTYPE_RIFF, NULL, &riff); + avierr = find_first_chunk(file, CHUNKTYPE_RIFF, nullptr, &riff); if (avierr != AVIERR_NONE) goto error; @@ -1954,7 +1954,7 @@ static avi_error extract_movie_info(avi_file *file) /* get the video stream */ stream = get_video_stream(file); - if (stream != NULL) + if (stream != nullptr) { /* fill in the info */ file->info.video_format = stream->format; @@ -1966,8 +1966,8 @@ static avi_error extract_movie_info(avi_file *file) } /* get the first audio stream */ - stream = get_audio_stream(file, 0, NULL); - if (stream != NULL) + stream = get_audio_stream(file, 0, nullptr); + if (stream != nullptr) { /* fill in the info */ file->info.audio_format = stream->format; @@ -1984,8 +1984,8 @@ static avi_error extract_movie_info(avi_file *file) while (1) { /* get the stream info */ - stream = get_audio_stream(file, file->info.audio_channels, NULL); - if (stream == NULL) + stream = get_audio_stream(file, file->info.audio_channels, nullptr); + if (stream == nullptr) break; file->info.audio_channels++; @@ -2021,7 +2021,7 @@ static avi_error extract_movie_info(avi_file *file) static avi_error parse_avih_chunk(avi_file *file, avi_chunk *avih) { - UINT8 *chunkdata = NULL; + UINT8 *chunkdata = nullptr; avi_error avierr; /* read the data */ @@ -2034,12 +2034,12 @@ static avi_error parse_avih_chunk(avi_file *file, avi_chunk *avih) /* allocate memory for the streams */ file->stream = (avi_stream *)malloc(sizeof(*file->stream) * file->streams); - if (file->stream == NULL) + if (file->stream == nullptr) goto error; memset(file->stream, 0, sizeof(*file->stream) * file->streams); error: - if (chunkdata != NULL) + if (chunkdata != nullptr) free(chunkdata); return avierr; } @@ -2064,7 +2064,7 @@ error: static avi_error parse_strh_chunk(avi_file *file, avi_stream *stream, avi_chunk *strh) { - UINT8 *chunkdata = NULL; + UINT8 *chunkdata = nullptr; avi_error avierr; /* read the data */ @@ -2079,7 +2079,7 @@ static avi_error parse_strh_chunk(avi_file *file, avi_stream *stream, avi_chunk stream->samples = fetch_32bits(&chunkdata[32]); error: - if (chunkdata != NULL) + if (chunkdata != nullptr) free(chunkdata); return avierr; } @@ -2104,7 +2104,7 @@ error: static avi_error parse_strf_chunk(avi_file *file, avi_stream *stream, avi_chunk *strf) { - UINT8 *chunkdata = NULL; + UINT8 *chunkdata = nullptr; avi_error avierr; /* read the data */ @@ -2136,7 +2136,7 @@ static avi_error parse_strf_chunk(avi_file *file, avi_stream *stream, avi_chunk } error: - if (chunkdata != NULL) + if (chunkdata != nullptr) free(chunkdata); return avierr; } @@ -2161,7 +2161,7 @@ error: static avi_error parse_indx_chunk(avi_file *file, avi_stream *stream, avi_chunk *strf) { UINT32 entries, entry; - UINT8 *chunkdata = NULL; + UINT8 *chunkdata = nullptr; UINT16 longs_per_entry; UINT8 type; UINT64 baseoffset; @@ -2238,7 +2238,7 @@ static avi_error parse_indx_chunk(avi_file *file, avi_stream *stream, avi_chunk } error: - if (chunkdata != NULL) + if (chunkdata != nullptr) free(chunkdata); return avierr; } @@ -2262,7 +2262,7 @@ error: static avi_error parse_idx1_chunk(avi_file *file, UINT64 baseoffset, avi_chunk *idx1) { - UINT8 *chunkdata = NULL; + UINT8 *chunkdata = nullptr; avi_error avierr; UINT32 entries; UINT32 entry; @@ -2300,7 +2300,7 @@ static avi_error parse_idx1_chunk(avi_file *file, UINT64 baseoffset, avi_chunk * } error: - if (chunkdata != NULL) + if (chunkdata != nullptr) free(chunkdata); return avierr; } @@ -2841,7 +2841,7 @@ static avi_error write_indx_chunk(avi_file *file, avi_stream *stream, int initia /* allocate memory */ tempbuf = (UINT8 *)malloc(24 + 8 * chunks_this_index); - if (tempbuf == NULL) + if (tempbuf == nullptr) return AVIERR_NO_MEMORY; memset(tempbuf, 0, 24 + 8 * chunks_this_index); @@ -2920,7 +2920,7 @@ static avi_error write_idx1_chunk(avi_file *file) /* allocate a temporary buffer */ tempbuf = (UINT8 *)malloc(tempbuflength); - if (tempbuf == NULL) + if (tempbuf == nullptr) return AVIERR_NO_MEMORY; /* fill it in */ @@ -2971,15 +2971,15 @@ static avi_error write_idx1_chunk(avi_file *file) static avi_error soundbuf_initialize(avi_file *file) { - avi_stream *audio = get_audio_stream(file, 0, NULL); + avi_stream *audio = get_audio_stream(file, 0, nullptr); avi_stream *video = get_video_stream(file); /* we require a video stream */ - if (video == NULL) + if (video == nullptr) return AVIERR_UNSUPPORTED_VIDEO_FORMAT; /* skip if no audio stream */ - if (audio == NULL) + if (audio == nullptr) return AVIERR_NONE; /* determine the number of samples we want in our buffer; 2 seconds should be enough */ @@ -2987,7 +2987,7 @@ static avi_error soundbuf_initialize(avi_file *file) /* allocate a buffer */ file->soundbuf = (INT16 *)malloc(file->soundbuf_samples * file->info.audio_channels * sizeof(file->soundbuf[0])); - if (file->soundbuf == NULL) + if (file->soundbuf == nullptr) return AVIERR_NO_MEMORY; memset(file->soundbuf, 0, file->soundbuf_samples * file->info.audio_channels * sizeof(file->soundbuf[0])); @@ -3015,12 +3015,12 @@ static avi_error soundbuf_initialize(avi_file *file) static avi_error soundbuf_write_chunk(avi_file *file, UINT32 framenum) { - avi_stream *stream = get_audio_stream(file, 0, NULL); + avi_stream *stream = get_audio_stream(file, 0, nullptr); avi_error avierr; UINT32 length; /* skip if no audio stream */ - if (stream == NULL) + if (stream == nullptr) return AVIERR_NONE; /* determine the length of this chunk */ @@ -3058,7 +3058,7 @@ static avi_error soundbuf_write_chunk(avi_file *file, UINT32 framenum) static avi_error soundbuf_flush(avi_file *file, int only_flush_full) { - avi_stream *stream = get_audio_stream(file, 0, NULL); + avi_stream *stream = get_audio_stream(file, 0, nullptr); INT32 channelsamples = file->soundbuf_samples; INT32 processedsamples = 0; UINT32 bytes_per_sample; @@ -3069,7 +3069,7 @@ static avi_error soundbuf_flush(avi_file *file, int only_flush_full) int channel; /* skip if no stream */ - if (stream == NULL) + if (stream == nullptr) return AVIERR_NONE; /* get the chunk ID for this stream */ @@ -3337,7 +3337,7 @@ static avi_error huffyuv_extract_tables(avi_stream *stream, const UINT8 *chunkda /* allocate memory for the data */ stream->huffyuv = (huffyuv_data *)malloc(sizeof(*stream->huffyuv)); - if (stream->huffyuv == NULL) + if (stream->huffyuv == nullptr) { avierr = AVIERR_NO_MEMORY; goto error; @@ -3425,7 +3425,7 @@ static avi_error huffyuv_extract_tables(avi_stream *stream, const UINT8 *chunkda if (bitsat16 > 0) { table->extralookup = (UINT16 *)malloc(bitsat16 * 65536 * sizeof(table->extralookup[0])); - if (table->extralookup == NULL) + if (table->extralookup == nullptr) { avierr = AVIERR_NO_MEMORY; goto error; @@ -3454,10 +3454,10 @@ static avi_error huffyuv_extract_tables(avi_stream *stream, const UINT8 *chunkda } error: - if (avierr != AVIERR_NONE && stream->huffyuv != NULL) + if (avierr != AVIERR_NONE && stream->huffyuv != nullptr) { free(stream->huffyuv); - stream->huffyuv = NULL; + stream->huffyuv = nullptr; } return avierr; } @@ -3759,7 +3759,7 @@ static void printf_chunk_recursive(avi_file *file, avi_chunk *container, int ind /* print data within the chunk */ if (chunksize > 0 && curchunk.size < 1024 * 1024) { - UINT8 *data = NULL; + UINT8 *data = nullptr; int i; /* read the data for a chunk */ diff --git a/src/lib/util/bitmap.cpp b/src/lib/util/bitmap.cpp index aeb9852ca1c..2436e474136 100644 --- a/src/lib/util/bitmap.cpp +++ b/src/lib/util/bitmap.cpp @@ -77,11 +77,11 @@ inline void bitmap_t::compute_base(int xslop, int yslop) */ bitmap_t::bitmap_t(bitmap_format format, int bpp, int width, int height, int xslop, int yslop) - : m_alloc(NULL), + : m_alloc(nullptr), m_allocbytes(0), m_format(format), m_bpp(bpp), - m_palette(NULL) + m_palette(nullptr) { // allocate intializes all other fields allocate(width, height, xslop, yslop); @@ -101,7 +101,7 @@ bitmap_t::bitmap_t(bitmap_format format, int bpp, int width, int height, int xsl */ bitmap_t::bitmap_t(bitmap_format format, int bpp, void *base, int width, int height, int rowpixels) - : m_alloc(NULL), + : m_alloc(nullptr), m_allocbytes(0), m_base(base), m_rowpixels(rowpixels), @@ -109,7 +109,7 @@ bitmap_t::bitmap_t(bitmap_format format, int bpp, void *base, int width, int hei m_height(height), m_format(format), m_bpp(bpp), - m_palette(NULL), + m_palette(nullptr), m_cliprect(0, width - 1, 0, height - 1) { } @@ -126,7 +126,7 @@ bitmap_t::bitmap_t(bitmap_format format, int bpp, void *base, int width, int hei */ bitmap_t::bitmap_t(bitmap_format format, int bpp, bitmap_t &source, const rectangle &subrect) - : m_alloc(NULL), + : m_alloc(nullptr), m_allocbytes(0), m_base(source.raw_pixptr(subrect.min_y, subrect.min_x)), m_rowpixels(source.m_rowpixels), @@ -134,7 +134,7 @@ bitmap_t::bitmap_t(bitmap_format format, int bpp, bitmap_t &source, const rectan m_height(subrect.height()), m_format(format), m_bpp(bpp), - m_palette(NULL), + m_palette(nullptr), m_cliprect(0, subrect.width() - 1, 0, subrect.height() - 1) { assert(format == source.m_format); @@ -258,10 +258,10 @@ void bitmap_t::resize(int width, int height, int xslop, int yslop) void bitmap_t::reset() { // delete any existing stuff - set_palette(NULL); + set_palette(nullptr); delete[] m_alloc; - m_alloc = NULL; - m_base = NULL; + m_alloc = nullptr; + m_base = nullptr; // reset all fields m_rowpixels = 0; @@ -339,14 +339,14 @@ void bitmap_t::wrap(const bitmap_t &source, const rectangle &subrect) void bitmap_t::set_palette(palette_t *palette) { // first dereference any existing palette - if (m_palette != NULL) + if (m_palette != nullptr) { m_palette->deref(); - m_palette = NULL; + m_palette = nullptr; } // then reference any new palette - if (palette != NULL) + if (palette != nullptr) { palette->ref(); m_palette = palette; diff --git a/src/lib/util/bitmap.h b/src/lib/util/bitmap.h index 91d693124e1..23d05af90df 100644 --- a/src/lib/util/bitmap.h +++ b/src/lib/util/bitmap.h @@ -141,7 +141,7 @@ public: INT32 rowbytes() const { return m_rowpixels * m_bpp / 8; } UINT8 bpp() const { return m_bpp; } bitmap_format format() const { return m_format; } - bool valid() const { return (m_base != NULL); } + bool valid() const { return (m_base != nullptr); } palette_t *palette() const { return m_palette; } const rectangle &cliprect() const { return m_cliprect; } diff --git a/src/lib/util/cdrom.cpp b/src/lib/util/cdrom.cpp index e3cb14e8f0c..917cb355839 100644 --- a/src/lib/util/cdrom.cpp +++ b/src/lib/util/cdrom.cpp @@ -225,8 +225,8 @@ cdrom_file *cdrom_open(const char *inputfile) /* allocate memory for the CD-ROM file */ file = new cdrom_file(); - if (file == NULL) - return NULL; + if (file == nullptr) + return nullptr; /* setup the CDROM module and get the disc info */ chd_error err = chdcd_parse_toc(inputfile, file->cdtoc, file->track_info); @@ -234,11 +234,11 @@ cdrom_file *cdrom_open(const char *inputfile) { fprintf(stderr, "Error reading input file: %s\n", chd_file::error_string(err)); delete file; - return NULL; + return nullptr; } /* fill in the data */ - file->chd = NULL; + file->chd = nullptr; LOG(("CD has %d tracks\n", file->cdtoc.numtrks)); @@ -249,7 +249,7 @@ cdrom_file *cdrom_open(const char *inputfile) { fprintf(stderr, "Unable to open file: %s\n", file->track_info.track[i].fname.c_str()); cdrom_close(file); - return NULL; + return nullptr; } } /* calculate the starting frame for each track, keeping in mind that CHDMAN @@ -322,18 +322,18 @@ cdrom_file *cdrom_open(chd_file *chd) /* punt if no CHD */ if (!chd) - return NULL; + return nullptr; /* validate the CHD information */ if (chd->hunk_bytes() % CD_FRAME_SIZE != 0) - return NULL; + return nullptr; if (chd->unit_bytes() != CD_FRAME_SIZE) - return NULL; + return nullptr; /* allocate memory for the CD-ROM file */ file = new cdrom_file(); - if (file == NULL) - return NULL; + if (file == nullptr) + return nullptr; /* fill in the data */ file->chd = chd; @@ -343,7 +343,7 @@ cdrom_file *cdrom_open(chd_file *chd) if (err != CHDERR_NONE) { delete file; - return NULL; + return nullptr; } LOG(("CD has %d tracks\n", file->cdtoc.numtrks)); @@ -411,10 +411,10 @@ cdrom_file *cdrom_open(chd_file *chd) void cdrom_close(cdrom_file *file) { - if (file == NULL) + if (file == nullptr) return; - if (file->chd == NULL) + if (file->chd == nullptr) { for (int i = 0; i < file->cdtoc.numtrks; i++) { @@ -461,7 +461,7 @@ chd_error read_partial_sector(cdrom_file *file, void *dest, UINT32 lbasector, UI } // if a CHD, just read - if (file->chd != NULL) + if (file->chd != nullptr) { result = file->chd->read_bytes(UINT64(chdsector) * UINT64(CD_FRAME_SIZE) + startoffs, dest, length); /* swap CDDA in the case of LE GDROMs */ @@ -521,7 +521,7 @@ chd_error read_partial_sector(cdrom_file *file, void *dest, UINT32 lbasector, UI UINT32 cdrom_read_data(cdrom_file *file, UINT32 lbasector, void *buffer, UINT32 datatype, bool phys) { - if (file == NULL) + if (file == nullptr) return 0; // compute CHD sector and tracknumber @@ -606,7 +606,7 @@ UINT32 cdrom_read_data(cdrom_file *file, UINT32 lbasector, void *buffer, UINT32 UINT32 cdrom_read_subcode(cdrom_file *file, UINT32 lbasector, void *buffer, bool phys) { - if (file == NULL) + if (file == nullptr) return ~0; // compute CHD sector and tracknumber @@ -656,7 +656,7 @@ UINT32 cdrom_get_track(cdrom_file *file, UINT32 frame) { UINT32 track = 0; - if (file == NULL) + if (file == nullptr) return ~0; /* convert to a CHD sector offset and get track information */ @@ -684,7 +684,7 @@ UINT32 cdrom_get_track(cdrom_file *file, UINT32 frame) UINT32 cdrom_get_track_start(cdrom_file *file, UINT32 track) { - if (file == NULL) + if (file == nullptr) return ~0; /* handle lead-out specially */ @@ -712,7 +712,7 @@ UINT32 cdrom_get_track_start(cdrom_file *file, UINT32 track) UINT32 cdrom_get_track_start_phys(cdrom_file *file, UINT32 track) { - if (file == NULL) + if (file == nullptr) return ~0; /* handle lead-out specially */ @@ -743,7 +743,7 @@ UINT32 cdrom_get_track_start_phys(cdrom_file *file, UINT32 track) int cdrom_get_last_track(cdrom_file *file) { - if (file == NULL) + if (file == nullptr) return -1; return file->cdtoc.numtrks; @@ -768,7 +768,7 @@ int cdrom_get_last_track(cdrom_file *file) int cdrom_get_adr_control(cdrom_file *file, int track) { - if (file == NULL) + if (file == nullptr) return -1; if (track == 0xaa || file->cdtoc.tracks[track].trktype == CD_TRACK_AUDIO) @@ -797,7 +797,7 @@ int cdrom_get_adr_control(cdrom_file *file, int track) int cdrom_get_track_type(cdrom_file *file, int track) { - if (file == NULL) + if (file == nullptr) return -1; return file->cdtoc.tracks[track].trktype; @@ -821,8 +821,8 @@ int cdrom_get_track_type(cdrom_file *file, int track) const cdrom_toc *cdrom_get_toc(cdrom_file *file) { - if (file == NULL) - return NULL; + if (file == nullptr) + return nullptr; return &file->cdtoc; } diff --git a/src/lib/util/chd.cpp b/src/lib/util/chd.cpp index 07e98d03b85..9f1b79081c5 100644 --- a/src/lib/util/chd.cpp +++ b/src/lib/util/chd.cpp @@ -186,7 +186,7 @@ inline void chd_file::be_write_sha1(UINT8 *base, sha1_t value) inline void chd_file::file_read(UINT64 offset, void *dest, UINT32 length) { // no file = failure - if (m_file == NULL) + if (m_file == nullptr) throw CHDERR_NOT_OPEN; // seek and read @@ -205,7 +205,7 @@ inline void chd_file::file_read(UINT64 offset, void *dest, UINT32 length) inline void chd_file::file_write(UINT64 offset, const void *source, UINT32 length) { // no file = failure - if (m_file == NULL) + if (m_file == nullptr) throw CHDERR_NOT_OPEN; // seek and write @@ -225,7 +225,7 @@ inline void chd_file::file_write(UINT64 offset, const void *source, UINT32 lengt inline UINT64 chd_file::file_append(const void *source, UINT32 length, UINT32 alignment) { // no file = failure - if (m_file == NULL) + if (m_file == nullptr) throw CHDERR_NOT_OPEN; // seek to the end and align if necessary @@ -288,7 +288,7 @@ inline UINT8 chd_file::bits_for_value(UINT64 value) */ chd_file::chd_file() - : m_file(NULL), + : m_file(nullptr), m_owns_file(false) { // reset state @@ -554,7 +554,7 @@ void chd_file::set_raw_sha1(sha1_t rawdata) void chd_file::set_parent_sha1(sha1_t parent) { // if no file, fail - if (m_file == NULL) + if (m_file == nullptr) throw CHDERR_INVALID_FILE; // create a big-endian version @@ -585,7 +585,7 @@ void chd_file::set_parent_sha1(sha1_t parent) chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4]) { // make sure we don't already have a file open - if (m_file != NULL) + if (m_file != nullptr) return CHDERR_ALREADY_OPEN; // set the header parameters @@ -593,7 +593,7 @@ chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbyte m_hunkbytes = hunkbytes; m_unitbytes = unitbytes; memcpy(m_compression, compression, sizeof(m_compression)); - m_parent = NULL; + m_parent = nullptr; // take ownership of the file m_file = &file; @@ -620,7 +620,7 @@ chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbyte chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, chd_codec_type compression[4], chd_file &parent) { // make sure we don't already have a file open - if (m_file != NULL) + if (m_file != nullptr) return CHDERR_ALREADY_OPEN; // set the header parameters @@ -655,11 +655,11 @@ chd_error chd_file::create(core_file &file, UINT64 logicalbytes, UINT32 hunkbyte chd_error chd_file::create(const char *filename, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4]) { // make sure we don't already have a file open - if (m_file != NULL) + if (m_file != nullptr) return CHDERR_ALREADY_OPEN; // create the new file - core_file *file = NULL; + core_file *file = nullptr; file_error filerr = core_fopen(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file); if (filerr != FILERR_NONE) return CHDERR_FILE_NOT_FOUND; @@ -696,11 +696,11 @@ chd_error chd_file::create(const char *filename, UINT64 logicalbytes, UINT32 hun chd_error chd_file::create(const char *filename, UINT64 logicalbytes, UINT32 hunkbytes, chd_codec_type compression[4], chd_file &parent) { // make sure we don't already have a file open - if (m_file != NULL) + if (m_file != nullptr) return CHDERR_ALREADY_OPEN; // create the new file - core_file *file = NULL; + core_file *file = nullptr; file_error filerr = core_fopen(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file); if (filerr != FILERR_NONE) return CHDERR_FILE_NOT_FOUND; @@ -735,12 +735,12 @@ chd_error chd_file::create(const char *filename, UINT64 logicalbytes, UINT32 hun chd_error chd_file::open(const char *filename, bool writeable, chd_file *parent) { // make sure we don't already have a file open - if (m_file != NULL) + if (m_file != nullptr) return CHDERR_ALREADY_OPEN; // open the file UINT32 openflags = writeable ? (OPEN_FLAG_READ | OPEN_FLAG_WRITE) : OPEN_FLAG_READ; - core_file *file = NULL; + core_file *file = nullptr; file_error filerr = core_fopen(filename, openflags, &file); if (filerr != FILERR_NONE) return CHDERR_FILE_NOT_FOUND; @@ -775,7 +775,7 @@ chd_error chd_file::open(const char *filename, bool writeable, chd_file *parent) chd_error chd_file::open(core_file &file, bool writeable, chd_file *parent) { // make sure we don't already have a file open - if (m_file != NULL) + if (m_file != nullptr) return CHDERR_ALREADY_OPEN; // open the file @@ -796,9 +796,9 @@ chd_error chd_file::open(core_file &file, bool writeable, chd_file *parent) void chd_file::close() { // reset file characteristics - if (m_owns_file && m_file != NULL) + if (m_owns_file && m_file != nullptr) core_fclose(m_file); - m_file = NULL; + m_file = nullptr; m_owns_file = false; m_allow_reads = false; m_allow_writes = false; @@ -813,7 +813,7 @@ void chd_file::close() m_unitbytes = 0; m_unitcount = 0; memset(m_compression, 0, sizeof(m_compression)); - m_parent = NULL; + m_parent = nullptr; m_parent_missing = false; // reset key offsets within the header @@ -828,10 +828,10 @@ void chd_file::close() m_rawmap.clear(); // reset compression management - for (int decompnum = 0; decompnum < ARRAY_LENGTH(m_decompressor); decompnum++) + for (auto & elem : m_decompressor) { - delete m_decompressor[decompnum]; - m_decompressor[decompnum] = NULL; + delete elem; + elem = nullptr; } m_compressed.clear(); @@ -869,7 +869,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) try { // punt if no file - if (m_file == NULL) + if (m_file == nullptr) throw CHDERR_NOT_OPEN; // return an error if out of range @@ -896,7 +896,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) blocklen = be_read(&rawmap[12], 2) + (rawmap[14] << 16); file_read(blockoffs, &m_compressed[0], blocklen); m_decompressor[0]->decompress(&m_compressed[0], blocklen, dest, m_hunkbytes); - if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && dest != NULL && crc32_creator::simple(dest, m_hunkbytes) != blockcrc) + if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && dest != nullptr && crc32_creator::simple(dest, m_hunkbytes) != blockcrc) throw CHDERR_DECOMPRESSION_ERROR; return CHDERR_NONE; @@ -936,7 +936,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) file_read(blockoffs, dest, m_hunkbytes); else if (m_parent_missing) throw CHDERR_REQUIRES_PARENT; - else if (m_parent != NULL) + else if (m_parent != nullptr) m_parent->read_hunk(hunknum, dest); else memset(dest, 0, m_hunkbytes); @@ -955,7 +955,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) case COMPRESSION_TYPE_3: file_read(blockoffs, &m_compressed[0], blocklen); m_decompressor[rawmap[0]]->decompress(&m_compressed[0], blocklen, dest, m_hunkbytes); - if (!m_decompressor[rawmap[0]]->lossy() && dest != NULL && crc16_creator::simple(dest, m_hunkbytes) != blockcrc) + if (!m_decompressor[rawmap[0]]->lossy() && dest != nullptr && crc16_creator::simple(dest, m_hunkbytes) != blockcrc) throw CHDERR_DECOMPRESSION_ERROR; if (m_decompressor[rawmap[0]]->lossy() && crc16_creator::simple(&m_compressed[0], blocklen) != blockcrc) throw CHDERR_DECOMPRESSION_ERROR; @@ -1014,7 +1014,7 @@ chd_error chd_file::write_hunk(UINT32 hunknum, const void *buffer) try { // punt if no file - if (m_file == NULL) + if (m_file == nullptr) throw CHDERR_NOT_OPEN; // return an error if out of range @@ -1249,7 +1249,7 @@ chd_error chd_file::read_metadata(chd_metadata_tag searchtag, UINT32 searchindex // read the metadata // TODO: how to properly allocate a dynamic char buffer? - char* metabuf = new char[metaentry.length+1]; + auto metabuf = new char[metaentry.length+1]; memset(metabuf, 0x00, metaentry.length+1); file_read(metaentry.offset + METADATA_HEADER_SIZE, metabuf, metaentry.length); output.assign(metabuf); @@ -2268,25 +2268,25 @@ chd_error chd_file::create_common() m_metaoffset = 0; // if we have a parent, it must be V3 or later - if (m_parent != NULL && m_parent->version() < 3) + if (m_parent != nullptr && m_parent->version() < 3) throw CHDERR_UNSUPPORTED_VERSION; // must be an even number of units per hunk if (m_hunkbytes % m_unitbytes != 0) throw CHDERR_INVALID_PARAMETER; - if (m_parent != NULL && m_unitbytes != m_parent->unit_bytes()) + if (m_parent != nullptr && m_unitbytes != m_parent->unit_bytes()) throw CHDERR_INVALID_PARAMETER; // verify the compression types bool found_zero = false; - for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_compression); codecnum++) + for (auto & elem : m_compression) { // once we hit an empty slot, all later slots must be empty as well - if (m_compression[codecnum] == CHD_CODEC_NONE) + if (elem == CHD_CODEC_NONE) found_zero = true; else if (found_zero) throw CHDERR_INVALID_PARAMETER; - else if (!chd_codec_list::codec_exists(m_compression[codecnum])) + else if (!chd_codec_list::codec_exists(elem)) throw CHDERR_UNKNOWN_COMPRESSION; } @@ -2306,7 +2306,7 @@ chd_error chd_file::create_common() be_write(&rawheader[60], m_unitbytes, 4); be_write_sha1(&rawheader[64], sha1_t::null); be_write_sha1(&rawheader[84], sha1_t::null); - be_write_sha1(&rawheader[104], (m_parent != NULL) ? m_parent->sha1() : sha1_t::null); + be_write_sha1(&rawheader[104], (m_parent != nullptr) ? m_parent->sha1() : sha1_t::null); // write the resulting header file_write(0, rawheader, sizeof(rawheader)); @@ -2412,12 +2412,12 @@ chd_error chd_file::open_common(bool writeable) // make sure we have a parent if we need one (and don't if we don't) if (parentsha1 != sha1_t::null) { - if (m_parent == NULL) + if (m_parent == nullptr) m_parent_missing = true; else if (m_parent->sha1() != parentsha1) throw CHDERR_INVALID_PARENT; } - else if (m_parent != NULL) + else if (m_parent != nullptr) throw CHDERR_INVALID_PARAMETER; // finish opening the file @@ -2450,7 +2450,7 @@ void chd_file::create_open_common() for (int decompnum = 0; decompnum < ARRAY_LENGTH(m_compression); decompnum++) { m_decompressor[decompnum] = chd_codec_list::new_decompressor(m_compression[decompnum], *this); - if (m_decompressor[decompnum] == NULL && m_compression[decompnum] != 0) + if (m_decompressor[decompnum] == nullptr && m_compression[decompnum] != 0) throw CHDERR_UNKNOWN_COMPRESSION; } @@ -2488,7 +2488,7 @@ void chd_file::create_open_common() void chd_file::verify_proper_compression_append(UINT32 hunknum) { // punt if no file - if (m_file == NULL) + if (m_file == nullptr) throw CHDERR_NOT_OPEN; // return an error if out of range @@ -2751,11 +2751,11 @@ chd_file_compressor::chd_file_compressor() : m_walking_parent(false), m_total_in(0), m_total_out(0), - m_read_queue(NULL), + m_read_queue(nullptr), m_read_queue_offset(0), m_read_done_offset(0), m_read_error(false), - m_work_queue(NULL), + m_work_queue(nullptr), m_write_hunk(0) { // zap arrays @@ -2781,8 +2781,8 @@ chd_file_compressor::~chd_file_compressor() osd_work_queue_free(m_work_queue); // delete allocated arrays - for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_codecs); codecnum++) - delete m_codecs[codecnum]; + for (auto & elem : m_codecs) + delete elem; } /** @@ -2796,7 +2796,7 @@ chd_file_compressor::~chd_file_compressor() void chd_file_compressor::compress_begin() { // reset state - m_walking_parent = (m_parent != NULL); + m_walking_parent = (m_parent != nullptr); m_total_in = 0; m_total_out = 0; m_compsha1.reset(); @@ -2824,10 +2824,10 @@ void chd_file_compressor::compress_begin() } // initialize codec instances - for (int instance = 0; instance < ARRAY_LENGTH(m_codecs); instance++) + for (auto & elem : m_codecs) { - delete m_codecs[instance]; - m_codecs[instance] = new chd_compressor_group(*this, m_compression); + delete elem; + elem = new chd_compressor_group(*this, m_compression); } // reset write state @@ -2886,9 +2886,9 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio work_item &item = m_work_item[m_write_hunk % WORK_BUFFER_HUNKS]; // free any OSD work item - if (item.m_osd != NULL) + if (item.m_osd != nullptr) osd_work_item_release(item.m_osd); - item.m_osd = NULL; + item.m_osd = nullptr; // for parent walking, just add to the hashmap if (m_walking_parent) @@ -2929,7 +2929,7 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio } // if not, see if it's in the parent map - if (m_parent != NULL) + if (m_parent != nullptr) { UINT64 parentunit = m_parent_map.find(item.m_hash[0].m_crc16, item.m_hash[0].m_sha1); if (parentunit != hashmap::NOT_FOUND) @@ -2958,8 +2958,8 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio m_walking_parent = false; m_read_queue_offset = m_read_done_offset = 0; m_write_hunk = 0; - for (int itemnum = 0; itemnum < WORK_BUFFER_HUNKS; itemnum++) - atomic_exchange32(&m_work_item[itemnum].m_status, WS_READY); + for (auto & elem : m_work_item) + atomic_exchange32(&elem.m_status, WS_READY); } // wait for all reads to finish and if we're compressed, write the final SHA1 and map @@ -2982,7 +2982,7 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio ratio = (m_total_in == 0) ? 1.0 : double(m_total_out) / double(m_total_in); // if we're waiting for work, wait - while (m_work_item[m_write_hunk % WORK_BUFFER_HUNKS].m_status != WS_COMPLETE && m_work_item[m_write_hunk % WORK_BUFFER_HUNKS].m_osd != NULL) + while (m_work_item[m_write_hunk % WORK_BUFFER_HUNKS].m_status != WS_COMPLETE && m_work_item[m_write_hunk % WORK_BUFFER_HUNKS].m_osd != nullptr) osd_work_item_wait(m_work_item[m_write_hunk % WORK_BUFFER_HUNKS].m_osd, osd_ticks_per_second()); return m_walking_parent ? CHDERR_WALKING_PARENT : CHDERR_COMPRESSING; @@ -3005,7 +3005,7 @@ void *chd_file_compressor::async_walk_parent_static(void *param, int threadid) { work_item *item = reinterpret_cast<work_item *>(param); item->m_compressor->async_walk_parent(*item); - return NULL; + return nullptr; } /** @@ -3047,7 +3047,7 @@ void *chd_file_compressor::async_compress_hunk_static(void *param, int threadid) { work_item *item = reinterpret_cast<work_item *>(param); item->m_compressor->async_compress_hunk(*item, threadid); - return NULL; + return nullptr; } /** @@ -3096,7 +3096,7 @@ void chd_file_compressor::async_compress_hunk(work_item &item, int threadid) void *chd_file_compressor::async_read_static(void *param, int threadid) { reinterpret_cast<chd_file_compressor *>(param)->async_read(); - return NULL; + return nullptr; } /** @@ -3189,7 +3189,7 @@ void chd_file_compressor::async_read() */ chd_file_compressor::hashmap::hashmap() - : m_block_list(new entry_block(NULL)) + : m_block_list(new entry_block(nullptr)) { // initialize the map to empty memset(m_map, 0, sizeof(m_map)); @@ -3220,7 +3220,7 @@ chd_file_compressor::hashmap::~hashmap() void chd_file_compressor::hashmap::reset() { // delete all the blocks - while (m_block_list->m_next != NULL) + while (m_block_list->m_next != nullptr) { entry_block *block = m_block_list; m_block_list = block->m_next; @@ -3248,7 +3248,7 @@ void chd_file_compressor::hashmap::reset() UINT64 chd_file_compressor::hashmap::find(crc16_t crc16, sha1_t sha1) { // look up the entry in the map - for (entry_t *entry = m_map[crc16]; entry != NULL; entry = entry->m_next) + for (entry_t *entry = m_map[crc16]; entry != nullptr; entry = entry->m_next) if (entry->m_sha1 == sha1) return entry->m_itemnum; return NOT_FOUND; diff --git a/src/lib/util/chd.h b/src/lib/util/chd.h index d767c0889e0..114a29a5b5e 100644 --- a/src/lib/util/chd.h +++ b/src/lib/util/chd.h @@ -307,7 +307,7 @@ public: operator core_file *() { return m_file; } // getters - bool opened() const { return (m_file != NULL); } + bool opened() const { return (m_file != nullptr); } UINT32 version() const { return m_version; } UINT64 logical_bytes() const { return m_logicalbytes; } UINT32 hunk_bytes() const { return m_hunkbytes; } @@ -333,8 +333,8 @@ public: chd_error create(core_file &file, UINT64 logicalbytes, UINT32 hunkbytes, chd_codec_type compression[4], chd_file &parent); // file open - chd_error open(const char *filename, bool writeable = false, chd_file *parent = NULL); - chd_error open(core_file &file, bool writeable = false, chd_file *parent = NULL); + chd_error open(const char *filename, bool writeable = false, chd_file *parent = nullptr); + chd_error open(core_file &file, bool writeable = false, chd_file *parent = nullptr); // file close void close(); @@ -519,14 +519,14 @@ private: struct work_item { work_item() - : m_osd(NULL) - , m_compressor(NULL) + : m_osd(nullptr) + , m_compressor(nullptr) , m_status(WS_READY) - , m_data(NULL) - , m_compressed(NULL) + , m_data(nullptr) + , m_compressed(nullptr) , m_complen(0) , m_compression(0) - , m_codecs(NULL) + , m_codecs(nullptr) { } osd_work_item * m_osd; // OSD work item running on this block diff --git a/src/lib/util/chdcd.cpp b/src/lib/util/chdcd.cpp index e267c613d1d..eeb196d242f 100644 --- a/src/lib/util/chdcd.cpp +++ b/src/lib/util/chdcd.cpp @@ -475,7 +475,7 @@ chd_error chdcd_parse_nero(const char *tocfname, cdrom_toc &outtoc, chdcd_track_ infile = fopen(tocfname, "rb"); path = get_file_path(path); - if (infile == (FILE *)NULL) + if (infile == (FILE *)nullptr) { return CHDERR_FILE_NOT_FOUND; } @@ -657,7 +657,7 @@ chd_error chdcd_parse_iso(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i infile = fopen(tocfname, "rb"); path = get_file_path(path); - if (infile == (FILE *)NULL) + if (infile == (FILE *)nullptr) { return CHDERR_FILE_NOT_FOUND; } @@ -736,7 +736,7 @@ static chd_error chdcd_parse_gdi(const char *tocfname, cdrom_toc &outtoc, chdcd_ infile = fopen(tocfname, "rt"); path = get_file_path(path); - if (infile == (FILE *)NULL) + if (infile == (FILE *)nullptr) { return CHDERR_FILE_NOT_FOUND; } @@ -771,13 +771,13 @@ static chd_error chdcd_parse_gdi(const char *tocfname, cdrom_toc &outtoc, chdcd_ outtoc.tracks[trknum].subsize = 0; outtoc.tracks[trknum].pgsub = CD_SUB_NONE; - tok=strtok(NULL," "); + tok=strtok(nullptr," "); outtoc.tracks[trknum].physframeofs=atoi(tok); - tok=strtok(NULL," "); + tok=strtok(nullptr," "); trktype=atoi(tok); - tok=strtok(NULL," "); + tok=strtok(nullptr," "); trksize=atoi(tok); if(trktype==4 && trksize==2352) @@ -799,16 +799,16 @@ static chd_error chdcd_parse_gdi(const char *tocfname, cdrom_toc &outtoc, chdcd_ std::string name; - tok=strtok(NULL," "); + tok=strtok(nullptr," "); name = tok; if (tok[0]=='"') { do { - tok=strtok(NULL," "); - if (tok!=NULL) { + tok=strtok(nullptr," "); + if (tok!=nullptr) { name += " "; name += tok; } - } while(tok!=NULL && (strrchr(tok,'"')-tok !=(strlen(tok)-1))); + } while(tok!=nullptr && (strrchr(tok,'"')-tok !=(strlen(tok)-1))); strdelchr(name,'"'); } outinfo.track[trknum].fname.assign(path).append(name); @@ -869,7 +869,7 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i infile = fopen(tocfname, "rt"); path = get_file_path(path); - if (infile == (FILE *)NULL) + if (infile == (FILE *)nullptr) { return CHDERR_FILE_NOT_FOUND; } @@ -931,7 +931,7 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i { /* get the track number */ TOKENIZE - trknum = strtoul(token, NULL, 10) - 1; + trknum = strtoul(token, nullptr, 10) - 1; /* next token on the line is the track type */ TOKENIZE @@ -978,7 +978,7 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i /* get index number */ TOKENIZE - idx = strtoul(token, NULL, 10); + idx = strtoul(token, nullptr, 10); /* get index */ TOKENIZE @@ -1191,7 +1191,7 @@ chd_error chdcd_parse_toc(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i infile = fopen(tocfname, "rt"); path = get_file_path(path); - if (infile == (FILE *)NULL) + if (infile == (FILE *)nullptr) { return CHDERR_FILE_NOT_FOUND; } @@ -1241,7 +1241,7 @@ chd_error chdcd_parse_toc(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i if (token[0] == '#') { /* it's a decimal offset, use it */ - f = strtoul(&token[1], NULL, 10); + f = strtoul(&token[1], nullptr, 10); } else if (isdigit((UINT8)token[0])) { diff --git a/src/lib/util/chdcd.h b/src/lib/util/chdcd.h index be585aad87e..6adcf29ce7b 100644 --- a/src/lib/util/chdcd.h +++ b/src/lib/util/chdcd.h @@ -27,7 +27,7 @@ struct chdcd_track_input_entry struct chdcd_track_input_info { - void reset() { for (int i = 0; i < CD_MAX_TRACKS; i++) track[i].reset(); } + void reset() { for (auto & elem : track) elem.reset(); } chdcd_track_input_entry track[CD_MAX_TRACKS]; }; diff --git a/src/lib/util/chdcodec.cpp b/src/lib/util/chdcodec.cpp index 9f013609133..be1d2022cd7 100644 --- a/src/lib/util/chdcodec.cpp +++ b/src/lib/util/chdcodec.cpp @@ -67,7 +67,7 @@ public: ~chd_zlib_compressor(); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest); + virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; private: // internal state @@ -87,7 +87,7 @@ public: ~chd_zlib_decompressor(); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen); + virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; private: // internal state @@ -127,7 +127,7 @@ public: ~chd_lzma_compressor(); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest); + virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; // helpers static void configure_properties(CLzmaEncProps &props, UINT32 hunkbytes); @@ -150,7 +150,7 @@ public: ~chd_lzma_decompressor(); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen); + virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; private: // internal state @@ -169,7 +169,7 @@ public: chd_huffman_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest); + virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; private: // internal state @@ -187,7 +187,7 @@ public: chd_huffman_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen); + virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; private: // internal state @@ -205,7 +205,7 @@ public: chd_flac_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest); + virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; // static helpers static UINT32 blocksize(UINT32 bytes); @@ -227,7 +227,7 @@ public: chd_flac_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen); + virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; private: // internal state @@ -247,7 +247,7 @@ public: ~chd_cd_flac_compressor(); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest); + virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; // static helpers static UINT32 blocksize(UINT32 bytes); @@ -273,7 +273,7 @@ public: ~chd_cd_flac_decompressor(); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen); + virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; private: // internal state @@ -304,7 +304,7 @@ public: } // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) + virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override { // determine header bytes UINT32 frames = srclen / CD_FRAME_SIZE; @@ -373,7 +373,7 @@ public: } // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) + virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override { // determine header bytes UINT32 frames = destlen / CD_FRAME_SIZE; @@ -424,7 +424,7 @@ public: chd_avhuff_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest); + virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; private: // internal helpers @@ -446,8 +446,8 @@ public: chd_avhuff_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen); - virtual void configure(int param, void *config); + virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; + virtual void configure(int param, void *config) override; private: // internal state @@ -560,7 +560,7 @@ chd_compressor *chd_codec_list::new_compressor(chd_codec_type type, chd_file &ch { // find in the list and construct the class const codec_entry *entry = find_in_list(type); - return (entry == NULL) ? NULL : (*entry->m_construct_compressor)(chd, chd.hunk_bytes(), entry->m_lossy); + return (entry == nullptr) ? nullptr : (*entry->m_construct_compressor)(chd, chd.hunk_bytes(), entry->m_lossy); } @@ -573,7 +573,7 @@ chd_decompressor *chd_codec_list::new_decompressor(chd_codec_type type, chd_file { // find in the list and construct the class const codec_entry *entry = find_in_list(type); - return (entry == NULL) ? NULL : (*entry->m_construct_decompressor)(chd, chd.hunk_bytes(), entry->m_lossy); + return (entry == nullptr) ? nullptr : (*entry->m_construct_decompressor)(chd, chd.hunk_bytes(), entry->m_lossy); } @@ -586,7 +586,7 @@ const char *chd_codec_list::codec_name(chd_codec_type type) { // find in the list and construct the class const codec_entry *entry = find_in_list(type); - return (entry == NULL) ? NULL : entry->m_name; + return (entry == nullptr) ? nullptr : entry->m_name; } @@ -598,10 +598,10 @@ const char *chd_codec_list::codec_name(chd_codec_type type) const chd_codec_list::codec_entry *chd_codec_list::find_in_list(chd_codec_type type) { // find in the list and construct the class - for (int listnum = 0; listnum < ARRAY_LENGTH(s_codec_list); listnum++) - if (s_codec_list[listnum].m_type == type) - return &s_codec_list[listnum]; - return NULL; + for (auto & elem : s_codec_list) + if (elem.m_type == type) + return &elem; + return nullptr; } @@ -624,11 +624,11 @@ chd_compressor_group::chd_compressor_group(chd_file &chd, UINT32 compressor_list // verify the compression types and initialize the codecs for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_compressor); codecnum++) { - m_compressor[codecnum] = NULL; + m_compressor[codecnum] = nullptr; if (compressor_list[codecnum] != CHD_CODEC_NONE) { m_compressor[codecnum] = chd_codec_list::new_compressor(compressor_list[codecnum], chd); - if (m_compressor[codecnum] == NULL) + if (m_compressor[codecnum] == nullptr) throw CHDERR_UNKNOWN_COMPRESSION; #if CHDCODEC_VERIFY_COMPRESSION m_decompressor[codecnum] = chd_codec_list::new_decompressor(compressor_list[codecnum], chd); @@ -647,8 +647,8 @@ chd_compressor_group::chd_compressor_group(chd_file &chd, UINT32 compressor_list chd_compressor_group::~chd_compressor_group() { // delete the codecs and the test buffer - for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_compressor); codecnum++) - delete m_compressor[codecnum]; + for (auto & elem : m_compressor) + delete elem; } @@ -664,7 +664,7 @@ INT8 chd_compressor_group::find_best_compressor(const UINT8 *src, UINT8 *compres complen = m_hunkbytes; INT8 compression = -1; for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_compressor); codecnum++) - if (m_compressor[codecnum] != NULL) + if (m_compressor[codecnum] != nullptr) { // attempt to compress, swallowing errors try @@ -735,8 +735,8 @@ chd_zlib_allocator::chd_zlib_allocator() chd_zlib_allocator::~chd_zlib_allocator() { // free our memory - for (int memindex = 0; memindex < ARRAY_LENGTH(m_allocptr); memindex++) - delete[] m_allocptr[memindex]; + for (auto & elem : m_allocptr) + delete[] elem; } @@ -769,7 +769,7 @@ voidpf chd_zlib_allocator::fast_alloc(voidpf opaque, uInt items, uInt size) for (int scan = 0; scan < MAX_ZLIB_ALLOCS; scan++) { UINT32 *ptr = codec->m_allocptr[scan]; - if (ptr != NULL && size == *ptr) + if (ptr != nullptr && size == *ptr) { // set the low bit of the size so we don't match next time *ptr |= 1; @@ -780,7 +780,7 @@ voidpf chd_zlib_allocator::fast_alloc(voidpf opaque, uInt items, uInt size) // alloc a new one and put it into the list UINT32 *ptr = reinterpret_cast<UINT32 *>(new UINT8[size + sizeof(UINT32)]); for (int scan = 0; scan < MAX_ZLIB_ALLOCS; scan++) - if (codec->m_allocptr[scan] == NULL) + if (codec->m_allocptr[scan] == nullptr) { codec->m_allocptr[scan] = ptr; break; @@ -968,8 +968,8 @@ chd_lzma_allocator::chd_lzma_allocator() chd_lzma_allocator::~chd_lzma_allocator() { // free our memory - for (int memindex = 0; memindex < ARRAY_LENGTH(m_allocptr); memindex++) - delete[] m_allocptr[memindex]; + for (auto & elem : m_allocptr) + delete[] elem; } @@ -989,7 +989,7 @@ void *chd_lzma_allocator::fast_alloc(void *p, size_t size) for (int scan = 0; scan < MAX_LZMA_ALLOCS; scan++) { UINT32 *ptr = codec->m_allocptr[scan]; - if (ptr != NULL && size == *ptr) + if (ptr != nullptr && size == *ptr) { // set the low bit of the size so we don't match next time *ptr |= 1; @@ -1000,7 +1000,7 @@ void *chd_lzma_allocator::fast_alloc(void *p, size_t size) // alloc a new one and put it into the list UINT32 *ptr = reinterpret_cast<UINT32 *>(new UINT8[size + sizeof(UINT32)]); for (int scan = 0; scan < MAX_LZMA_ALLOCS; scan++) - if (codec->m_allocptr[scan] == NULL) + if (codec->m_allocptr[scan] == nullptr) { codec->m_allocptr[scan] = ptr; break; @@ -1019,7 +1019,7 @@ void *chd_lzma_allocator::fast_alloc(void *p, size_t size) void chd_lzma_allocator::fast_free(void *p, void *address) { - if (address == NULL) + if (address == nullptr) return; chd_lzma_allocator *codec = reinterpret_cast<chd_lzma_allocator *>(p); @@ -1070,7 +1070,7 @@ UINT32 chd_lzma_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *des { // allocate the encoder CLzmaEncHandle encoder = LzmaEnc_Create(&m_allocator); - if (encoder == NULL) + if (encoder == nullptr) throw CHDERR_COMPRESSION_ERROR; try @@ -1082,7 +1082,7 @@ UINT32 chd_lzma_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *des // run it SizeT complen = srclen; - res = LzmaEnc_MemEncode(encoder, dest, &complen, src, srclen, 0, NULL, &m_allocator, &m_allocator); + res = LzmaEnc_MemEncode(encoder, dest, &complen, src, srclen, 0, nullptr, &m_allocator, &m_allocator); if (res != SZ_OK) throw CHDERR_COMPRESSION_ERROR; @@ -1645,7 +1645,7 @@ UINT32 chd_avhuff_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *d postinit(); // make sure short frames are padded with 0 - if (src != NULL) + if (src != nullptr) { int size = avhuff_encoder::raw_data_size(src); while (size < srclen) @@ -1745,7 +1745,7 @@ void chd_avhuff_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 throw CHDERR_DECOMPRESSION_ERROR; // pad short frames with 0 - if (dest != NULL) + if (dest != nullptr) { int size = avhuff_encoder::raw_data_size(dest); if (size < destlen) diff --git a/src/lib/util/chdcodec.h b/src/lib/util/chdcodec.h index 144fba8641f..f517cdedeeb 100644 --- a/src/lib/util/chdcodec.h +++ b/src/lib/util/chdcodec.h @@ -108,7 +108,7 @@ public: static chd_decompressor *new_decompressor(chd_codec_type type, chd_file &file); // utilities - static bool codec_exists(chd_codec_type type) { return (find_in_list(type) != NULL); } + static bool codec_exists(chd_codec_type type) { return (find_in_list(type) != nullptr); } static const char *codec_name(chd_codec_type type); private: diff --git a/src/lib/util/corealloc.cpp b/src/lib/util/corealloc.cpp index a635803e463..9ca7af380d3 100644 --- a/src/lib/util/corealloc.cpp +++ b/src/lib/util/corealloc.cpp @@ -90,11 +90,11 @@ const zeromem_t zeromem = { }; // globals for memory_entry UINT64 memory_entry::s_curid = 1; -osd_lock *memory_entry::s_lock = NULL; +osd_lock *memory_entry::s_lock = nullptr; bool memory_entry::s_lock_alloc = false; bool memory_entry::s_tracking = false; -memory_entry *memory_entry::s_hash[memory_entry::k_hash_prime] = { NULL }; -memory_entry *memory_entry::s_freehead = NULL; +memory_entry *memory_entry::s_hash[memory_entry::k_hash_prime] = { nullptr }; +memory_entry *memory_entry::s_freehead = nullptr; //************************************************************************** // OPERATOR REPLACEMENTS @@ -103,15 +103,15 @@ memory_entry *memory_entry::s_freehead = NULL; #ifndef NO_MEM_TRACKING // standard new/delete operators (try to avoid using) -void *operator new(std::size_t size) throw (std::bad_alloc) { return malloc_file_line(size, NULL, 0, false, true, false); } -void *operator new[](std::size_t size) throw (std::bad_alloc) { return malloc_file_line(size, NULL, 0, true, true, false); } -void operator delete(void *ptr) throw() { if (ptr != NULL) free_file_line(ptr, NULL, 0, false); } -void operator delete[](void *ptr) throw() { if (ptr != NULL) free_file_line(ptr, NULL, 0, true); } +void *operator new(std::size_t size) throw (std::bad_alloc) { return malloc_file_line(size, nullptr, 0, false, true, false); } +void *operator new[](std::size_t size) throw (std::bad_alloc) { return malloc_file_line(size, nullptr, 0, true, true, false); } +void operator delete(void *ptr) throw() { if (ptr != nullptr) free_file_line(ptr, nullptr, 0, false); } +void operator delete[](void *ptr) throw() { if (ptr != nullptr) free_file_line(ptr, nullptr, 0, true); } -void* operator new(std::size_t size,const std::nothrow_t&) throw() { return malloc_file_line(size, NULL, 0, false, false, false); } -void* operator new[](std::size_t size, const std::nothrow_t&) throw() { return malloc_file_line(size, NULL, 0, true, false, false); } -void operator delete(void* ptr, const std::nothrow_t&) throw() { if (ptr != NULL) free_file_line(ptr, NULL, 0, false); } -void operator delete[](void* ptr, const std::nothrow_t&) throw() { if (ptr != NULL) free_file_line(ptr, NULL, 0, true); } +void* operator new(std::size_t size,const std::nothrow_t&) throw() { return malloc_file_line(size, nullptr, 0, false, false, false); } +void* operator new[](std::size_t size, const std::nothrow_t&) throw() { return malloc_file_line(size, nullptr, 0, true, false, false); } +void operator delete(void* ptr, const std::nothrow_t&) throw() { if (ptr != nullptr) free_file_line(ptr, nullptr, 0, false); } +void operator delete[](void* ptr, const std::nothrow_t&) throw() { if (ptr != nullptr) free_file_line(ptr, nullptr, 0, true); } #endif @@ -122,14 +122,14 @@ void operator delete[](void* ptr, const std::nothrow_t&) throw() { if (ptr != NU // file/line new/delete operators void *operator new(std::size_t size, const char *file, int line) throw (std::bad_alloc) { return malloc_file_line(size, file, line, false, true, false); } void *operator new[](std::size_t size, const char *file, int line) throw (std::bad_alloc) { return malloc_file_line(size, file, line, true, true, false); } -void operator delete(void *ptr, const char *file, int line) { if (ptr != NULL) free_file_line(ptr, file, line, false); } -void operator delete[](void *ptr, const char *file, int line) { if (ptr != NULL) free_file_line(ptr, file, line, true); } +void operator delete(void *ptr, const char *file, int line) { if (ptr != nullptr) free_file_line(ptr, file, line, false); } +void operator delete[](void *ptr, const char *file, int line) { if (ptr != nullptr) free_file_line(ptr, file, line, true); } // file/line new/delete operators with zeroing void *operator new(std::size_t size, const char *file, int line, const zeromem_t &) throw (std::bad_alloc) { return malloc_file_line(size, file, line, false, true, true); } void *operator new[](std::size_t size, const char *file, int line, const zeromem_t &) throw (std::bad_alloc) { return malloc_file_line(size, file, line, true, true, true); } -void operator delete(void *ptr, const char *file, int line, const zeromem_t &) { if (ptr != NULL) free_file_line(ptr, file, line, false); } -void operator delete[](void *ptr, const char *file, int line, const zeromem_t &) { if (ptr != NULL) free_file_line(ptr, file, line, true); } +void operator delete(void *ptr, const char *file, int line, const zeromem_t &) { if (ptr != nullptr) free_file_line(ptr, file, line, false); } +void operator delete[](void *ptr, const char *file, int line, const zeromem_t &) { if (ptr != nullptr) free_file_line(ptr, file, line, true); } @@ -146,13 +146,13 @@ void *malloc_file_line(size_t size, const char *file, int line, bool array, bool { // allocate the memory and fail if we can't void *result = array ? osd_malloc_array(size) : osd_malloc(size); - if (result == NULL) + if (result == nullptr) { fprintf(stderr, "Failed to allocate %d bytes (%s:%d)\n", UINT32(size), file, line); osd_break_into_debugger("Failed to allocate RAM"); if (throw_on_fail) throw std::bad_alloc(); - return NULL; + return nullptr; } // zap the memory if requested @@ -183,7 +183,7 @@ void free_file_line(void *memory, const char *file, int line, bool array) memory_entry *entry = memory_entry::find(memory); // warn about untracked frees - if (entry == NULL) + if (entry == nullptr) { fprintf(stderr, "Error: attempt to free untracked memory %p in %s(%d)!\n", memory, file, line); osd_break_into_debugger("Error: attempt to free untracked memory"); @@ -267,7 +267,7 @@ void memory_entry::acquire_lock() { // allocate a lock on first usage // note that osd_lock_alloc() may re-enter this path, so protect against recursion! - if (s_lock == NULL) + if (s_lock == nullptr) { if (s_lock_alloc) return; @@ -298,14 +298,14 @@ memory_entry *memory_entry::allocate(size_t size, void *base, const char *file, acquire_lock(); // if we're out of free entries, allocate a new chunk - if (s_freehead == NULL) + if (s_freehead == nullptr) { // create a new chunk, and fail if we can't memory_entry *entry = reinterpret_cast<memory_entry *>(osd_malloc_array(memory_block_alloc_chunk * sizeof(memory_entry))); - if (entry == NULL) + if (entry == nullptr) { release_lock(); - return NULL; + return nullptr; } // add all the entries to the list @@ -323,7 +323,7 @@ memory_entry *memory_entry::allocate(size_t size, void *base, const char *file, // populate it entry->m_size = size; entry->m_base = base; - entry->m_file = s_tracking ? file : NULL; + entry->m_file = s_tracking ? file : nullptr; entry->m_line = s_tracking ? line : 0; entry->m_id = s_curid++; entry->m_array = array; @@ -333,9 +333,9 @@ memory_entry *memory_entry::allocate(size_t size, void *base, const char *file, // add it to the alloc list int hashval = reinterpret_cast<FPTR>(base) % k_hash_prime; entry->m_next = s_hash[hashval]; - if (entry->m_next != NULL) + if (entry->m_next != nullptr) entry->m_next->m_prev = entry; - entry->m_prev = NULL; + entry->m_prev = nullptr; s_hash[hashval] = entry; release_lock(); @@ -350,15 +350,15 @@ memory_entry *memory_entry::allocate(size_t size, void *base, const char *file, memory_entry *memory_entry::find(void *ptr) { // NULL maps to nothing - if (ptr == NULL) - return NULL; + if (ptr == nullptr) + return nullptr; // scan the list under the lock acquire_lock(); int hashval = reinterpret_cast<FPTR>(ptr) % k_hash_prime; memory_entry *entry; - for (entry = s_hash[hashval]; entry != NULL; entry = entry->m_next) + for (entry = s_hash[hashval]; entry != nullptr; entry = entry->m_next) if (entry->m_base == ptr) break; @@ -380,11 +380,11 @@ void memory_entry::release(memory_entry *entry, const char *file, int line) // remove ourselves from the alloc list int hashval = reinterpret_cast<FPTR>(entry->m_base) % k_hash_prime; - if (entry->m_prev != NULL) + if (entry->m_prev != nullptr) entry->m_prev->m_next = entry->m_next; else s_hash[hashval] = entry->m_next; - if (entry->m_next != NULL) + if (entry->m_next != nullptr) entry->m_next->m_prev = entry->m_prev; // add ourself to the free list @@ -411,9 +411,9 @@ void memory_entry::report_unfreed(UINT64 start) // check for leaked memory UINT32 total = 0; - for (int hashnum = 0; hashnum < k_hash_prime; hashnum++) - for (memory_entry *entry = s_hash[hashnum]; entry != NULL; entry = entry->m_next) - if (entry->m_file != NULL && entry->m_id >= start) + for (auto entry : s_hash) + for (; entry != nullptr; entry = entry->m_next) + if (entry->m_file != nullptr && entry->m_id >= start) { if (total == 0) fprintf(stderr, "--- memory leak warning ---\n"); diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp index 797805ac768..b7e389a35f7 100644 --- a/src/lib/util/corefile.cpp +++ b/src/lib/util/corefile.cpp @@ -126,7 +126,7 @@ file_error core_fopen(const char *filename, UINT32 openflags, core_file **file) /* allocate the file itself */ *file = (core_file *)malloc(sizeof(**file)); - if (*file == NULL) + if (*file == nullptr) return FILERR_OUT_OF_MEMORY; memset(*file, 0, sizeof(**file)); @@ -138,7 +138,7 @@ file_error core_fopen(const char *filename, UINT32 openflags, core_file **file) if (filerr != FILERR_NONE) { core_fclose(*file); - *file = NULL; + *file = nullptr; } return filerr; } @@ -160,7 +160,7 @@ static file_error core_fopen_ram_internal(const void *data, size_t length, int c /* allocate the file itself */ *file = (core_file *)malloc(sizeof(**file) + (copy_buffer ? length : 0)); - if (*file == NULL) + if (*file == nullptr) return FILERR_OUT_OF_MEMORY; memset(*file, 0, sizeof(**file)); @@ -210,11 +210,11 @@ file_error core_fopen_ram_copy(const void *data, size_t length, UINT32 openflags void core_fclose(core_file *file) { /* close files and free memory */ - if (file->zdata != NULL) + if (file->zdata != nullptr) core_fcompress(file, FCOMPRESS_NONE); - if (file->file != NULL) + if (file->file != nullptr) osd_close(file->file); - if (file->data != NULL && file->data_allocated) + if (file->data != nullptr && file->data_allocated) free(file->data); free(file); } @@ -235,7 +235,7 @@ file_error core_fcompress(core_file *file, int level) return FILERR_INVALID_ACCESS; /* if we have been compressing, flush and free the data */ - if (file->zdata != NULL && level == FCOMPRESS_NONE) + if (file->zdata != nullptr && level == FCOMPRESS_NONE) { int zerr = Z_OK; @@ -273,17 +273,17 @@ file_error core_fcompress(core_file *file, int level) /* free memory */ free(file->zdata); - file->zdata = NULL; + file->zdata = nullptr; } /* if we are just starting to compress, allocate a new buffer */ - if (file->zdata == NULL && level > FCOMPRESS_NONE) + if (file->zdata == nullptr && level > FCOMPRESS_NONE) { int zerr; /* allocate memory */ file->zdata = (zlib_data *)malloc(sizeof(*file->zdata)); - if (file->zdata == NULL) + if (file->zdata == nullptr) return FILERR_OUT_OF_MEMORY; memset(file->zdata, 0, sizeof(*file->zdata)); @@ -301,7 +301,7 @@ file_error core_fcompress(core_file *file, int level) if (zerr != Z_OK) { free(file->zdata); - file->zdata = NULL; + file->zdata = nullptr; return FILERR_OUT_OF_MEMORY; } @@ -331,7 +331,7 @@ int core_fseek(core_file *file, INT64 offset, int whence) int err = 0; /* error if compressing */ - if (file->zdata != NULL) + if (file->zdata != nullptr) return 1; /* flush any buffered char */ @@ -412,7 +412,7 @@ UINT32 core_fread(core_file *file, void *buffer, UINT32 length) file->back_char_tail = 0; /* handle real files */ - if (file->file && file->data == NULL) + if (file->file && file->data == nullptr) { /* if we're within the buffer, consume that first */ if (file->offset >= file->bufferbase && file->offset < file->bufferbase + file->bufferbytes) @@ -638,7 +638,7 @@ char *core_fgets(char *s, int n, core_file *file) /* if we put nothing in, return NULL */ if (cur == s) - return NULL; + return nullptr; /* otherwise, terminate */ if (n > 0) @@ -659,13 +659,13 @@ const void *core_fbuffer(core_file *file) UINT32 read_length; /* if we already have data, just return it */ - if (file->data != NULL || !file->length) + if (file->data != nullptr || !file->length) return file->data; /* allocate some memory */ file->data = (UINT8 *)malloc(file->length); - if (file->data == NULL) - return NULL; + if (file->data == nullptr) + return nullptr; file->data_allocated = TRUE; /* read the file */ @@ -673,13 +673,13 @@ const void *core_fbuffer(core_file *file) if (filerr != FILERR_NONE || read_length != file->length) { free(file->data); - file->data = NULL; - return NULL; + file->data = nullptr; + return nullptr; } /* close the file because we don't need it anymore */ osd_close(file->file); - file->file = NULL; + file->file = nullptr; return file->data; } @@ -692,7 +692,7 @@ const void *core_fbuffer(core_file *file) file_error core_fload(const char *filename, void **data, UINT32 *length) { - core_file *file = NULL; + core_file *file = nullptr; file_error err; UINT64 size; @@ -711,7 +711,7 @@ file_error core_fload(const char *filename, void **data, UINT32 *length) /* allocate memory */ *data = osd_malloc(size); - if (length != NULL) + if (length != nullptr) *length = (UINT32)size; /* read the data */ @@ -729,7 +729,7 @@ file_error core_fload(const char *filename, void **data, UINT32 *length) file_error core_fload(const char *filename, dynamic_buffer &data) { - core_file *file = NULL; + core_file *file = nullptr; file_error err; UINT64 size; @@ -777,7 +777,7 @@ UINT32 core_fwrite(core_file *file, const void *buffer, UINT32 length) UINT32 bytes_written = 0; /* can't write to RAM-based stuff */ - if (file->data != NULL) + if (file->data != nullptr) return 0; /* flush any buffered char */ @@ -978,7 +978,7 @@ static UINT32 safe_buffer_copy(const void *source, UINT32 sourceoffs, UINT32 sou static file_error osd_or_zlib_read(core_file *file, void *buffer, UINT64 offset, UINT32 length, UINT32 *actual) { /* if no compression, just pass through */ - if (file->zdata == NULL) + if (file->zdata == nullptr) return osd_read(file->file, buffer, offset, length, actual); /* if the offset doesn't match the next offset, fail */ @@ -1045,7 +1045,7 @@ static file_error osd_or_zlib_read(core_file *file, void *buffer, UINT64 offset, static file_error osd_or_zlib_write(core_file *file, const void *buffer, UINT64 offset, UINT32 length, UINT32 *actual) { /* if no compression, just pass through */ - if (file->zdata == NULL) + if (file->zdata == nullptr) return osd_write(file->file, buffer, offset, length, actual); /* if the offset doesn't match the next offset, fail */ diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp index b4a75a3bc48..336d788cabb 100644 --- a/src/lib/util/corestr.cpp +++ b/src/lib/util/corestr.cpp @@ -114,11 +114,11 @@ int core_strwildcmp(const char *sp1, const char *sp2) char *core_strdup(const char *str) { - char *cpy = NULL; - if (str != NULL) + char *cpy = nullptr; + if (str != nullptr) { cpy = (char *)osd_malloc_array(strlen(str) + 1); - if (cpy != NULL) + if (cpy != nullptr) strcpy(cpy, str); } return cpy; @@ -261,18 +261,18 @@ void strdelchr(std::string& str, char chr) void strreplacechr(std::string& str, char ch, char newch) { - for (size_t i = 0; i < str.length(); i++) + for (auto & elem : str) { - if (str[i] == ch) str[i] = newch; + if (elem == ch) elem = newch; } } std::string strtrimspace(std::string& str) { int start = 0; - for (size_t i = 0; i < str.length(); i++) + for (auto & elem : str) { - if (!isspace(UINT8(str[i]))) break; + if (!isspace(UINT8(elem))) break; start++; } int end = str.length(); diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h index 703eba077da..afbd3dcf9a1 100644 --- a/src/lib/util/coretmpl.h +++ b/src/lib/util/coretmpl.h @@ -42,8 +42,8 @@ class simple_list public: // construction/destruction simple_list() - : m_head(NULL), - m_tail(NULL), + : m_head(nullptr), + m_tail(nullptr), m_count(0) { } virtual ~simple_list() { reset(); } @@ -56,7 +56,7 @@ public: // remove (free) all objects in the list, leaving an empty list void reset() { - while (m_head != NULL) + while (m_head != nullptr) remove(*m_head); } @@ -65,7 +65,7 @@ public: { object.m_next = m_head; m_head = &object; - if (m_tail == NULL) + if (m_tail == nullptr) m_tail = m_head; m_count++; return object; @@ -81,7 +81,7 @@ public: _ElementType *head = list.detach_all(); tail->m_next = m_head; m_head = head; - if (m_tail == NULL) + if (m_tail == nullptr) m_tail = tail; m_count += count; } @@ -89,8 +89,8 @@ public: // add the given object to the tail of the list _ElementType &append(_ElementType &object) { - object.m_next = NULL; - if (m_tail != NULL) + object.m_next = nullptr; + if (m_tail != nullptr) m_tail = m_tail->m_next = &object; else m_tail = m_head = &object; @@ -106,7 +106,7 @@ public: return; _ElementType *tail = list.last(); _ElementType *head = list.detach_all(); - if (m_tail != NULL) + if (m_tail != nullptr) m_tail->m_next = head; else m_head = head; @@ -117,7 +117,7 @@ public: // insert the given object after a particular object (NULL means prepend) _ElementType &insert_after(_ElementType &object, _ElementType *insert_after) { - if (insert_after == NULL) + if (insert_after == nullptr) return prepend(object); object.m_next = insert_after->m_next; insert_after->m_next = &object; @@ -130,9 +130,9 @@ public: // insert the given object before a particular object (NULL means append) _ElementType &insert_before(_ElementType &object, _ElementType *insert_before) { - if (insert_before == NULL) + if (insert_before == nullptr) return append(object); - for (_ElementType **curptr = &m_head; *curptr != NULL; curptr = &(*curptr)->m_next) + for (_ElementType **curptr = &m_head; *curptr != nullptr; curptr = &(*curptr)->m_next) if (*curptr == insert_before) { object.m_next = insert_before; @@ -148,11 +148,11 @@ public: // replace an item in the list at the same location, and remove it _ElementType &replace_and_remove(_ElementType &object, _ElementType &toreplace) { - _ElementType *prev = NULL; - for (_ElementType *cur = m_head; cur != NULL; prev = cur, cur = cur->m_next) + _ElementType *prev = nullptr; + for (_ElementType *cur = m_head; cur != nullptr; prev = cur, cur = cur->m_next) if (cur == &toreplace) { - if (prev != NULL) + if (prev != nullptr) prev->m_next = &object; else m_head = &object; @@ -169,12 +169,12 @@ public: _ElementType *detach_head() { _ElementType *result = m_head; - if (result != NULL) + if (result != nullptr) { m_head = result->m_next; m_count--; - if (m_head == NULL) - m_tail = NULL; + if (m_head == nullptr) + m_tail = nullptr; } return result; } @@ -182,11 +182,11 @@ public: // detach the given item from the list, but don't free its memory _ElementType &detach(_ElementType &object) { - _ElementType *prev = NULL; - for (_ElementType *cur = m_head; cur != NULL; prev = cur, cur = cur->m_next) + _ElementType *prev = nullptr; + for (_ElementType *cur = m_head; cur != nullptr; prev = cur, cur = cur->m_next) if (cur == &object) { - if (prev != NULL) + if (prev != nullptr) prev->m_next = object.m_next; else m_head = object.m_next; @@ -202,7 +202,7 @@ public: _ElementType *detach_all() { _ElementType *result = m_head; - m_head = m_tail = NULL; + m_head = m_tail = nullptr; m_count = 0; return result; } @@ -216,17 +216,17 @@ public: // find an object by index in the list _ElementType *find(int index) const { - for (_ElementType *cur = m_head; cur != NULL; cur = cur->m_next) + for (_ElementType *cur = m_head; cur != nullptr; cur = cur->m_next) if (index-- == 0) return cur; - return NULL; + return nullptr; } // return the index of the given object in the list int indexof(const _ElementType &object) const { int index = 0; - for (_ElementType *cur = m_head; cur != NULL; cur = cur->m_next) + for (_ElementType *cur = m_head; cur != nullptr; cur = cur->m_next) { if (cur == &object) return index; @@ -256,7 +256,7 @@ public: // construction/destruction simple_list_wrapper(_ObjectType *object) - : m_next(NULL), + : m_next(nullptr), m_object(object) { } // operators @@ -294,13 +294,13 @@ public: _ItemType *alloc() { _ItemType *result = m_freelist.detach_head(); - if (result == NULL) + if (result == nullptr) result = global_alloc(_ItemType); return result; } // reclaim an item by adding it to the free list - void reclaim(_ItemType *item) { if (item != NULL) m_freelist.append(*item); } + void reclaim(_ItemType *item) { if (item != nullptr) m_freelist.append(*item); } void reclaim(_ItemType &item) { m_freelist.append(item); } // reclaim all items from a list diff --git a/src/lib/util/cstrpool.cpp b/src/lib/util/cstrpool.cpp index dfb41e25232..242c33380de 100644 --- a/src/lib/util/cstrpool.cpp +++ b/src/lib/util/cstrpool.cpp @@ -37,16 +37,16 @@ const char *const_string_pool::add(const char *string) return string; // scan to find space - for (pool_chunk *chunk = m_chunklist.first(); chunk != NULL; chunk = chunk->next()) + for (pool_chunk *chunk = m_chunklist.first(); chunk != nullptr; chunk = chunk->next()) { const char *result = chunk->add(string); - if (result != NULL) + if (result != nullptr) return result; } // no space anywhere, create a new pool and prepend it (so it gets used first) const char *result = m_chunklist.prepend(*global_alloc(pool_chunk)).add(string); - assert(result != NULL); + assert(result != nullptr); return result; } @@ -63,7 +63,7 @@ bool const_string_pool::contains(const char *string) return true; // scan to find it - for (pool_chunk *chunk = m_chunklist.first(); chunk != NULL; chunk = chunk->next()) + for (pool_chunk *chunk = m_chunklist.first(); chunk != nullptr; chunk = chunk->next()) if (chunk->contains(string)) return true; @@ -79,7 +79,7 @@ bool const_string_pool::contains(const char *string) */ const_string_pool::pool_chunk::pool_chunk() - : m_next(NULL), + : m_next(nullptr), m_used(0) { } @@ -104,7 +104,7 @@ const char *const_string_pool::pool_chunk::add(const char *string) // if too big, return NULL if (m_used + bytes > POOL_SIZE) - return NULL; + return nullptr; // allocate, copy, and return the memory char *dest = &m_buffer[m_used]; diff --git a/src/lib/util/delegate.h b/src/lib/util/delegate.h index 85a1628409c..ec10a5c268d 100644 --- a/src/lib/util/delegate.h +++ b/src/lib/util/delegate.h @@ -631,16 +631,16 @@ public: typedef MEMBER_ABI generic_static_func generic_member_func; // generic constructor delegate_base() - : m_function(NULL), - m_object(NULL), - m_name(NULL), - m_latebinder(NULL), - m_raw_function(NULL) { } + : m_function(nullptr), + m_object(nullptr), + m_name(nullptr), + m_latebinder(nullptr), + m_raw_function(nullptr) { } // copy constructor delegate_base(const delegate_base &src) : m_function(src.m_function), - m_object(NULL), + m_object(nullptr), m_name(src.m_name), m_latebinder(src.m_latebinder), m_raw_function(src.m_raw_function), @@ -652,7 +652,7 @@ public: // copy constructor with late bind delegate_base(const delegate_base &src, delegate_late_bind &object) : m_function(src.m_function), - m_object(NULL), + m_object(nullptr), m_name(src.m_name), m_latebinder(src.m_latebinder), m_raw_function(src.m_raw_function), @@ -664,12 +664,12 @@ public: // construct from member function with object pointer template<class _FunctionClass> delegate_base(typename traits<_FunctionClass>::member_func_type funcptr, const char *name, _FunctionClass *object) - : m_function(NULL), - m_object(NULL), + : m_function(nullptr), + m_object(nullptr), m_name(name), m_latebinder(&late_bind_helper<_FunctionClass>), - m_raw_function(NULL), - m_raw_mfp(funcptr, object, (_ReturnType *)0, (generic_static_func)0) + m_raw_function(nullptr), + m_raw_mfp(funcptr, object, (_ReturnType *)nullptr, (generic_static_func)nullptr) { bind(reinterpret_cast<delegate_generic_class *>(object)); } @@ -678,7 +678,7 @@ public: template<class _FunctionClass> delegate_base(typename traits<_FunctionClass>::static_func_type funcptr, const char *name, _FunctionClass *object) : m_function(reinterpret_cast<generic_static_func>(funcptr)), - m_object(NULL), + m_object(nullptr), m_name(name), m_latebinder(&late_bind_helper<_FunctionClass>), m_raw_function(reinterpret_cast<generic_static_func>(funcptr)) @@ -690,7 +690,7 @@ public: template<class _FunctionClass> delegate_base(typename traits<_FunctionClass>::static_ref_func_type funcptr, const char *name, _FunctionClass *object) : m_function(reinterpret_cast<generic_static_func>(funcptr)), - m_object(NULL), + m_object(nullptr), m_name(name), m_latebinder(&late_bind_helper<_FunctionClass>), m_raw_function(reinterpret_cast<generic_static_func>(funcptr)) @@ -704,7 +704,7 @@ public: if (this != &src) { m_function = src.m_function; - m_object = NULL; + m_object = nullptr; m_name = src.m_name; m_latebinder = src.m_latebinder; m_raw_function = src.m_raw_function; @@ -744,11 +744,11 @@ public: _ReturnType operator()(_P1Type p1, _P2Type p2, _P3Type p3, _P4Type p4, _P5Type p5, _P6Type p6, _P7Type p7, _P8Type p8, _P9Type p9, _P10Type p10, _P11Type p11, _P12Type p12) const { DELEGATE_CALL((m_object, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)); } // getters - bool has_object() const { return (object() != NULL); } + bool has_object() const { return (object() != nullptr); } const char *name() const { return m_name; } // helpers - bool isnull() const { return (m_raw_function == NULL && m_raw_mfp.isnull()); } + bool isnull() const { return (m_raw_function == nullptr && m_raw_mfp.isnull()); } bool is_mfp() const { return !m_raw_mfp.isnull(); } // late binding @@ -766,7 +766,7 @@ protected: static delegate_generic_class *late_bind_helper(delegate_late_bind &object) { _FunctionClass *result = dynamic_cast<_FunctionClass *>(&object); - if (result == NULL) { + if (result == nullptr) { throw binding_type_exception(typeid(_FunctionClass), typeid(object)); } return reinterpret_cast<delegate_generic_class *>(result); @@ -778,7 +778,7 @@ protected: m_object = object; // if we're wrapping a member function pointer, handle special stuff - if (m_object != NULL && is_mfp()) + if (m_object != nullptr && is_mfp()) m_raw_mfp.update_after_bind(m_function, m_object); } diff --git a/src/lib/util/flac.cpp b/src/lib/util/flac.cpp index 49fc667a184..f70ae709978 100644 --- a/src/lib/util/flac.cpp +++ b/src/lib/util/flac.cpp @@ -78,7 +78,7 @@ bool flac_encoder::reset() FLAC__stream_encoder_set_blocksize(m_encoder, m_block_size); // re-start processing - return (FLAC__stream_encoder_init_stream(m_encoder, write_callback_static, NULL, NULL, NULL, this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK); + return (FLAC__stream_encoder_init_stream(m_encoder, write_callback_static, nullptr, nullptr, nullptr, this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK); } @@ -91,7 +91,7 @@ bool flac_encoder::reset(void *buffer, UINT32 buflength) // configure the output m_compressed_start = reinterpret_cast<FLAC__byte *>(buffer); m_compressed_length = buflength; - m_file = NULL; + m_file = nullptr; return reset(); } @@ -103,7 +103,7 @@ bool flac_encoder::reset(void *buffer, UINT32 buflength) bool flac_encoder::reset(core_file &file) { // configure the output - m_compressed_start = NULL; + m_compressed_start = nullptr; m_compressed_length = 0; m_file = &file; return reset(); @@ -185,7 +185,7 @@ UINT32 flac_encoder::finish() { // process the data and return the amount written FLAC__stream_encoder_finish(m_encoder); - return (m_file != NULL) ? core_ftell(m_file) : m_compressed_offset; + return (m_file != nullptr) ? core_ftell(m_file) : m_compressed_offset; } @@ -197,13 +197,13 @@ void flac_encoder::init_common() { // allocate the encoder m_encoder = FLAC__stream_encoder_new(); - if (m_encoder == NULL) + if (m_encoder == nullptr) throw std::bad_alloc(); // initialize default state - m_file = NULL; + m_file = nullptr; m_compressed_offset = 0; - m_compressed_start = NULL; + m_compressed_start = nullptr; m_compressed_length = 0; m_sample_rate = 44100; m_channels = 2; @@ -251,7 +251,7 @@ FLAC__StreamEncoderWriteStatus flac_encoder::write_callback(const FLAC__byte buf else { int count = bytes - offset; - if (m_file != NULL) + if (m_file != nullptr) core_fwrite(m_file, buffer, count); else { @@ -277,11 +277,11 @@ FLAC__StreamEncoderWriteStatus flac_encoder::write_callback(const FLAC__byte buf flac_decoder::flac_decoder() : m_decoder(FLAC__stream_decoder_new()), - m_file(NULL), + m_file(nullptr), m_compressed_offset(0), - m_compressed_start(NULL), + m_compressed_start(nullptr), m_compressed_length(0), - m_compressed2_start(NULL), + m_compressed2_start(nullptr), m_compressed2_length(0) { } @@ -293,7 +293,7 @@ flac_decoder::flac_decoder() flac_decoder::flac_decoder(const void *buffer, UINT32 length, const void *buffer2, UINT32 length2) : m_decoder(FLAC__stream_decoder_new()), - m_file(NULL), + m_file(nullptr), m_compressed_offset(0), m_compressed_start(reinterpret_cast<const FLAC__byte *>(buffer)), m_compressed_length(length), @@ -312,9 +312,9 @@ flac_decoder::flac_decoder(core_file &file) : m_decoder(FLAC__stream_decoder_new()), m_file(&file), m_compressed_offset(0), - m_compressed_start(NULL), + m_compressed_start(nullptr), m_compressed_length(0), - m_compressed2_start(NULL), + m_compressed2_start(nullptr), m_compressed2_length(0) { reset(); @@ -341,10 +341,10 @@ bool flac_decoder::reset() m_compressed_offset = 0; if (FLAC__stream_decoder_init_stream(m_decoder, &flac_decoder::read_callback_static, - NULL, + nullptr, &flac_decoder::tell_callback_static, - NULL, - NULL, + nullptr, + nullptr, &flac_decoder::write_callback_static, &flac_decoder::metadata_callback_static, &flac_decoder::error_callback_static, this) != FLAC__STREAM_DECODER_INIT_STATUS_OK) @@ -359,7 +359,7 @@ bool flac_decoder::reset() bool flac_decoder::reset(const void *buffer, UINT32 length, const void *buffer2, UINT32 length2) { - m_file = NULL; + m_file = nullptr; m_compressed_start = reinterpret_cast<const FLAC__byte *>(buffer); m_compressed_length = length; m_compressed2_start = reinterpret_cast<const FLAC__byte *>(buffer2); @@ -401,7 +401,7 @@ bool flac_decoder::reset(UINT32 sample_rate, UINT8 num_channels, UINT32 block_si m_custom_header[0x14] = (sample_rate << 4) | ((num_channels - 1) << 1); // configure the header ahead of the provided buffer - m_file = NULL; + m_file = nullptr; m_compressed_start = reinterpret_cast<const FLAC__byte *>(m_custom_header); m_compressed_length = sizeof(m_custom_header); m_compressed2_start = reinterpret_cast<const FLAC__byte *>(buffer); @@ -417,9 +417,9 @@ bool flac_decoder::reset(UINT32 sample_rate, UINT8 num_channels, UINT32 block_si bool flac_decoder::reset(core_file &file) { m_file = &file; - m_compressed_start = NULL; + m_compressed_start = nullptr; m_compressed_length = 0; - m_compressed2_start = NULL; + m_compressed2_start = nullptr; m_compressed2_length = 0; return reset(); } @@ -510,7 +510,7 @@ FLAC__StreamDecoderReadStatus flac_decoder::read_callback(FLAC__byte buffer[], s UINT32 expected = *bytes; // if a file, just read - if (m_file != NULL) + if (m_file != nullptr) *bytes = core_fread(m_file, buffer, expected); // otherwise, copy from memory @@ -589,7 +589,7 @@ FLAC__StreamDecoderWriteStatus flac_decoder::write_callback(const ::FLAC__Frame // interleaved case int shift = m_uncompressed_swap ? 8 : 0; int blocksize = frame->header.blocksize; - if (m_uncompressed_start[1] == NULL) + if (m_uncompressed_start[1] == nullptr) { INT16 *dest = m_uncompressed_start[0] + m_uncompressed_offset * frame->header.channels; for (int sampnum = 0; sampnum < blocksize && m_uncompressed_offset < m_uncompressed_length; sampnum++, m_uncompressed_offset++) @@ -602,7 +602,7 @@ FLAC__StreamDecoderWriteStatus flac_decoder::write_callback(const ::FLAC__Frame { for (int sampnum = 0; sampnum < blocksize && m_uncompressed_offset < m_uncompressed_length; sampnum++, m_uncompressed_offset++) for (int chan = 0; chan < frame->header.channels; chan++) - if (m_uncompressed_start[chan] != NULL) + if (m_uncompressed_start[chan] != nullptr) m_uncompressed_start[chan][m_uncompressed_offset] = INT16((UINT16(buffer[chan][sampnum]) << shift) | (UINT16(buffer[chan][sampnum]) >> shift)); } return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; diff --git a/src/lib/util/flac.h b/src/lib/util/flac.h index 24290b7649e..563c40974e0 100644 --- a/src/lib/util/flac.h +++ b/src/lib/util/flac.h @@ -92,7 +92,7 @@ class flac_decoder public: // construction/destruction flac_decoder(); - flac_decoder(const void *buffer, UINT32 length, const void *buffer2 = NULL, UINT32 length2 = 0); + flac_decoder(const void *buffer, UINT32 length, const void *buffer2 = nullptr, UINT32 length2 = 0); flac_decoder(core_file &file); ~flac_decoder(); @@ -106,7 +106,7 @@ public: // reset bool reset(); - bool reset(const void *buffer, UINT32 length, const void *buffer2 = NULL, UINT32 length2 = 0); + bool reset(const void *buffer, UINT32 length, const void *buffer2 = nullptr, UINT32 length2 = 0); bool reset(UINT32 sample_rate, UINT8 num_channels, UINT32 block_size, const void *buffer, UINT32 length); bool reset(core_file &file); diff --git a/src/lib/util/harddisk.cpp b/src/lib/util/harddisk.cpp index b1082f3234f..6bb121f36b2 100644 --- a/src/lib/util/harddisk.cpp +++ b/src/lib/util/harddisk.cpp @@ -44,22 +44,22 @@ hard_disk_file *hard_disk_open(chd_file *chd) chd_error err; /* punt if no CHD */ - if (chd == NULL) - return NULL; + if (chd == nullptr) + return nullptr; /* read the hard disk metadata */ err = chd->read_metadata(HARD_DISK_METADATA_TAG, 0, metadata); if (err != CHDERR_NONE) - return NULL; + return nullptr; /* parse the metadata */ if (sscanf(metadata.c_str(), HARD_DISK_METADATA_FORMAT, &cylinders, &heads, §ors, §orbytes) != 4) - return NULL; + return nullptr; /* allocate memory for the hard disk file */ file = (hard_disk_file *)malloc(sizeof(hard_disk_file)); - if (file == NULL) - return NULL; + if (file == nullptr) + return nullptr; /* fill in the data */ file->chd = chd; diff --git a/src/lib/util/hashing.cpp b/src/lib/util/hashing.cpp index e7f315ecc53..785127e01e8 100644 --- a/src/lib/util/hashing.cpp +++ b/src/lib/util/hashing.cpp @@ -63,13 +63,13 @@ bool sha1_t::from_string(const char *string, int length) return false; // iterate through our raw buffer - for (int bytenum = 0; bytenum < sizeof(m_raw); bytenum++) + for (auto & elem : m_raw) { int upper = char_to_hex(*string++); int lower = char_to_hex(*string++); if (upper == -1 || lower == -1) return false; - m_raw[bytenum] = (upper << 4) | lower; + elem = (upper << 4) | lower; } return true; } @@ -82,8 +82,8 @@ bool sha1_t::from_string(const char *string, int length) const char *sha1_t::as_string(std::string &buffer) const { buffer.clear(); - for (int i = 0; i < ARRAY_LENGTH(m_raw); i++) - strcatprintf(buffer, "%02x", m_raw[i]); + for (auto & elem : m_raw) + strcatprintf(buffer, "%02x", elem); return buffer.c_str(); } @@ -106,13 +106,13 @@ bool md5_t::from_string(const char *string, int length) return false; // iterate through our raw buffer - for (int bytenum = 0; bytenum < sizeof(m_raw); bytenum++) + for (auto & elem : m_raw) { int upper = char_to_hex(*string++); int lower = char_to_hex(*string++); if (upper == -1 || lower == -1) return false; - m_raw[bytenum] = (upper << 4) | lower; + elem = (upper << 4) | lower; } return true; } @@ -125,8 +125,8 @@ bool md5_t::from_string(const char *string, int length) const char *md5_t::as_string(std::string &buffer) const { buffer.clear(); - for (int i = 0; i < ARRAY_LENGTH(m_raw); i++) - strcatprintf(buffer, "%02x", m_raw[i]); + for (auto & elem : m_raw) + strcatprintf(buffer, "%02x", elem); return buffer.c_str(); } diff --git a/src/lib/util/huffman.cpp b/src/lib/util/huffman.cpp index 9205264f9eb..8aa32bd3b4d 100644 --- a/src/lib/util/huffman.cpp +++ b/src/lib/util/huffman.cpp @@ -563,7 +563,7 @@ int huffman_context_base::build_tree(UINT32 totaldata, UINT32 totalweight) // create new node node_t &newnode = m_huffnode[nextalloc++]; - newnode.m_parent = NULL; + newnode.m_parent = nullptr; node0.m_parent = node1.m_parent = &newnode; newnode.m_weight = node0.m_weight + node1.m_weight; @@ -591,7 +591,7 @@ int huffman_context_base::build_tree(UINT32 totaldata, UINT32 totalweight) if (node.m_weight > 0) { // determine the number of bits for this node - for (node_t *curnode = &node; curnode->m_parent != NULL; curnode = curnode->m_parent) + for (node_t *curnode = &node; curnode->m_parent != nullptr; curnode = curnode->m_parent) node.m_numbits++; if (node.m_numbits == 0) node.m_numbits = 1; diff --git a/src/lib/util/huffman.h b/src/lib/util/huffman.h index 76ee1b9c23b..a2bed42bbf9 100644 --- a/src/lib/util/huffman.h +++ b/src/lib/util/huffman.h @@ -98,7 +98,7 @@ class huffman_encoder : public huffman_context_base public: // pass through to the underlying constructor huffman_encoder() - : huffman_context_base(_NumCodes, _MaxBits, NULL, m_datahisto_array, m_huffnode_array) { histo_reset(); } + : huffman_context_base(_NumCodes, _MaxBits, nullptr, m_datahisto_array, m_huffnode_array) { histo_reset(); } // single item operations void histo_reset() { memset(m_datahisto_array, 0, sizeof(m_datahisto_array)); } @@ -126,7 +126,7 @@ class huffman_decoder : public huffman_context_base public: // pass through to the underlying constructor huffman_decoder() - : huffman_context_base(_NumCodes, _MaxBits, m_lookup_array, NULL, m_huffnode_array) { } + : huffman_context_base(_NumCodes, _MaxBits, m_lookup_array, nullptr, m_huffnode_array) { } // single item operations UINT32 decode_one(bitstream_in &bitbuf); diff --git a/src/lib/util/opresolv.cpp b/src/lib/util/opresolv.cpp index 91c6f1a9cbd..4764d6955e3 100644 --- a/src/lib/util/opresolv.cpp +++ b/src/lib/util/opresolv.cpp @@ -116,7 +116,7 @@ static optreserr_t resolve_single_param(const char *specification, int *param_va range++; flags &= ~FLAG_HALF_RANGE; if (--range_count == 0) - range = NULL; + range = nullptr; } } else if (*s == ';') @@ -179,14 +179,14 @@ static const char *lookup_in_specification(const char *specification, const opti { const char *s; s = strchr(specification, option->parameter); - return s ? s + 1 : NULL; + return s ? s + 1 : nullptr; } option_resolution *option_resolution_create(const option_guide *guide, const char *specification) { - option_resolution *resolution = NULL; + option_resolution *resolution = nullptr; const option_guide *guide_entry; int option_count; int opt = -1; @@ -198,7 +198,7 @@ option_resolution *option_resolution_create(const option_guide *guide, const cha option_count = option_resolution_countoptions(guide, specification); /* create a memory pool for this structure */ - pool = pool_alloc_lib(NULL); + pool = pool_alloc_lib(nullptr); if (!pool) goto outofmemory; @@ -244,7 +244,7 @@ unexpected: outofmemory: if (resolution) option_resolution_close(resolution); - return NULL; + return nullptr; } @@ -255,7 +255,7 @@ optreserr_t option_resolution_add_param(option_resolution *resolution, const cha int must_resolve; optreserr_t err; const char *option_specification; - struct option_resolution_entry *entry = NULL; + struct option_resolution_entry *entry = nullptr; for (i = 0; i < resolution->option_count; i++) { @@ -317,7 +317,7 @@ optreserr_t option_resolution_add_param(option_resolution *resolution, const cha if (must_resolve) { option_specification = lookup_in_specification(resolution->specification, entry->guide_entry); - err = resolve_single_param(option_specification, &entry->u.int_value, NULL, 0); + err = resolve_single_param(option_specification, &entry->u.int_value, nullptr, 0); if (err) goto done; @@ -363,7 +363,7 @@ optreserr_t option_resolution_finish(option_resolution *resolution) option_specification = lookup_in_specification(resolution->specification, entry->guide_entry); assert(option_specification); entry->u.int_value = -1; - err = resolve_single_param(option_specification, &entry->u.int_value, NULL, 0); + err = resolve_single_param(option_specification, &entry->u.int_value, nullptr, 0); if (err) return err; break; @@ -403,10 +403,10 @@ static const struct option_resolution_entry *option_resolution_lookup_entry(opti default: assert(FALSE); - return NULL; + return nullptr; } } - return NULL; + return nullptr; } @@ -424,7 +424,7 @@ const char *option_resolution_lookup_string(option_resolution *resolution, int o { const struct option_resolution_entry *entry; entry = option_resolution_lookup_entry(resolution, option_char); - return entry ? entry->u.str_value : NULL; + return entry ? entry->u.str_value : nullptr; } @@ -440,7 +440,7 @@ const option_guide *option_resolution_find_option(option_resolution *resolution, { const struct option_resolution_entry *entry; entry = option_resolution_lookup_entry(resolution, option_char); - return entry ? entry->guide_entry : NULL; + return entry ? entry->guide_entry : nullptr; } @@ -448,7 +448,7 @@ const option_guide *option_resolution_find_option(option_resolution *resolution, const option_guide *option_resolution_index_option(option_resolution *resolution, int indx) { if ((indx < 0) || (indx >= resolution->option_count)) - return NULL; + return nullptr; return resolution->entries[indx].guide_entry; } @@ -495,7 +495,7 @@ optreserr_t option_resolution_listranges(const char *specification, int option_c return OPTIONRESOLUTION_ERROR_SYNTAX; } - return resolve_single_param(specification + 1, NULL, range, range_count); + return resolve_single_param(specification + 1, nullptr, range, range_count); } @@ -513,7 +513,7 @@ optreserr_t option_resolution_getdefault(const char *specification, int option_c return OPTIONRESOLUTION_ERROR_SYNTAX; } - return resolve_single_param(specification + 1, val, NULL, 0); + return resolve_single_param(specification + 1, val, nullptr, 0); } @@ -549,7 +549,7 @@ optreserr_t option_resolution_isvalidvalue(const char *specification, int option int option_resolution_contains(const char *specification, int option_char) { - return strchr(specification, option_char) != NULL; + return strchr(specification, option_char) != nullptr; } /** @@ -578,6 +578,6 @@ const char *option_resolution_error_string(optreserr_t err) }; if ((err < 0) || (err >= ARRAY_LENGTH(errors))) - return NULL; + return nullptr; return errors[err]; } diff --git a/src/lib/util/options.cpp b/src/lib/util/options.cpp index 69e7189f50b..c644fef9657 100644 --- a/src/lib/util/options.cpp +++ b/src/lib/util/options.cpp @@ -53,7 +53,7 @@ const char *const core_options::s_option_unadorned[MAX_UNADORNED_OPTIONS] = //------------------------------------------------- core_options::entry::entry(const char *name, const char *description, UINT32 flags, const char *defvalue) - : m_next(NULL), + : m_next(nullptr), m_flags(flags), m_seqid(0), m_error_reported(false), @@ -61,7 +61,7 @@ core_options::entry::entry(const char *name, const char *description, UINT32 fla m_description(description) { // copy in the name(s) as appropriate - if (name != NULL) + if (name != nullptr) { // first extract any range std::string namestr(name); @@ -90,7 +90,7 @@ core_options::entry::entry(const char *name, const char *description, UINT32 fla } // set the default value - if (defvalue != NULL) + if (defvalue != nullptr) m_defdata = defvalue; m_data = m_defdata; } @@ -225,7 +225,7 @@ core_options &core_options::operator=(const core_options &rhs) bool core_options::operator==(const core_options &rhs) { // iterate over options in the first list - for (entry *curentry = m_entrylist.first(); curentry != NULL; curentry = curentry->next()) + for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next()) if (!curentry->is_header()) { // if the values differ, return false @@ -255,12 +255,12 @@ bool core_options::operator!=(const core_options &rhs) void core_options::add_entry(const char *name, const char *description, UINT32 flags, const char *defvalue, bool override_existing) { // allocate a new entry - entry *newentry = global_alloc(entry(name, description, flags, defvalue)); - if (newentry->name() != NULL) + auto newentry = global_alloc(entry(name, description, flags, defvalue)); + if (newentry->name() != nullptr) { // see if we match an existing entry entry *existing = m_entrymap.find(newentry->name()); - if (existing != NULL) + if (existing != nullptr) { // if we're overriding existing entries, then remove the old one if (override_existing) @@ -289,7 +289,7 @@ void core_options::add_entry(const char *name, const char *description, UINT32 f void core_options::add_entries(const options_entry *entrylist, bool override_existing) { // loop over entries until we hit a NULL name - for ( ; entrylist->name != NULL || (entrylist->flags & OPTION_HEADER) != 0; entrylist++) + for ( ; entrylist->name != nullptr || (entrylist->flags & OPTION_HEADER) != 0; entrylist++) add_entry(*entrylist, override_existing); } @@ -303,7 +303,7 @@ void core_options::set_default_value(const char *name, const char *defvalue) { // find the entry and bail if we can't entry *curentry = m_entrymap.find(name); - if (curentry == NULL) + if (curentry == nullptr) return; // update the data and default data @@ -320,7 +320,7 @@ void core_options::set_description(const char *name, const char *description) { // find the entry and bail if we can't entry *curentry = m_entrymap.find(name); - if (curentry == NULL) + if (curentry == nullptr) return; // update the data and default data @@ -351,7 +351,7 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, std:: // find our entry; if not found, indicate invalid option entry *curentry = m_entrymap.find(optionname); - if (curentry == NULL) + if (curentry == nullptr) { strcatprintf(error_string, "Error: unknown option: %s\n", curarg); retval = false; @@ -402,7 +402,7 @@ bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_p { // loop over lines in the file char buffer[4096]; - while (core_fgets(buffer, ARRAY_LENGTH(buffer), &inifile) != NULL) + while (core_fgets(buffer, ARRAY_LENGTH(buffer), &inifile) != nullptr) { // find the extent of the name char *optionname; @@ -444,7 +444,7 @@ bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_p // find our entry entry *curentry = m_entrymap.find(optionname); - if (curentry == NULL) + if (curentry == nullptr) { if (priority >= ignore_priority) strcatprintf(error_string, "Warning: unknown option in INI: %s\n", optionname); @@ -466,7 +466,7 @@ bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_p void core_options::revert(int priority) { // iterate over options and revert to defaults if below the given priority - for (entry *curentry = m_entrylist.first(); curentry != NULL; curentry = curentry->next()) + for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next()) curentry->revert(priority); } @@ -484,10 +484,10 @@ const char *core_options::output_ini(std::string &buffer, const core_options *di int num_valid_headers = 0; int unadorned_index = 0; - const char *last_header = NULL; + const char *last_header = nullptr; // loop over all items - for (entry *curentry = m_entrylist.first(); curentry != NULL; curentry = curentry->next()) + for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next()) { const char *name = curentry->name(); const char *value = curentry->value(); @@ -510,21 +510,21 @@ const char *core_options::output_ini(std::string &buffer, const core_options *di if ( !curentry->is_internal() ) { // look up counterpart in diff, if diff is specified - if (diff == NULL || strcmp(value, diff->value(name)) != 0) + if (diff == nullptr || strcmp(value, diff->value(name)) != 0) { // output header, if we have one - if (last_header != NULL) + if (last_header != nullptr) { if (num_valid_headers++) strcatprintf(buffer,"\n"); strcatprintf(buffer, "#\n# %s\n#\n", last_header); - last_header = NULL; + last_header = nullptr; } // and finally output the data, skip if unadorned if (!is_unadorned) { - if (strchr(value, ' ') != NULL) + if (strchr(value, ' ') != nullptr) strcatprintf(buffer,"%-25s \"%s\"\n", name, value); else strcatprintf(buffer,"%-25s %s\n", name, value); @@ -547,14 +547,14 @@ const char *core_options::output_help(std::string &buffer) buffer.clear(); // loop over all items - for (entry *curentry = m_entrylist.first(); curentry != NULL; curentry = curentry->next()) + for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next()) { // header: just print if (curentry->is_header()) strcatprintf(buffer,"\n#\n# %s\n#\n", curentry->description()); // otherwise, output entries for all non-deprecated items - else if (curentry->description() != NULL) + else if (curentry->description() != nullptr) strcatprintf(buffer,"-%-20s%s\n", curentry->name(), curentry->description()); } return buffer.c_str(); @@ -568,7 +568,7 @@ const char *core_options::output_help(std::string &buffer) const char *core_options::value(const char *name) const { entry *curentry = m_entrymap.find(name); - return (curentry != NULL) ? curentry->value() : ""; + return (curentry != nullptr) ? curentry->value() : ""; } @@ -579,7 +579,7 @@ const char *core_options::value(const char *name) const const char *core_options::description(const char *name) const { entry *curentry = m_entrymap.find(name); - return (curentry != NULL) ? curentry->description() : ""; + return (curentry != nullptr) ? curentry->description() : ""; } @@ -590,7 +590,7 @@ const char *core_options::description(const char *name) const int core_options::priority(const char *name) const { entry *curentry = m_entrymap.find(name); - return (curentry != NULL) ? curentry->priority() : 0; + return (curentry != nullptr) ? curentry->priority() : 0; } @@ -601,7 +601,7 @@ int core_options::priority(const char *name) const UINT32 core_options::seqid(const char *name) const { entry *curentry = m_entrymap.find(name); - return (curentry != NULL) ? curentry->seqid() : 0; + return (curentry != nullptr) ? curentry->seqid() : 0; } //------------------------------------------------- @@ -611,7 +611,7 @@ UINT32 core_options::seqid(const char *name) const bool core_options::exists(const char *name) const { entry *curentry = m_entrymap.find(name); - return (curentry != NULL); + return (curentry != nullptr); } //------------------------------------------------- @@ -622,7 +622,7 @@ bool core_options::set_value(const char *name, const char *value, int priority, { // find the entry first entry *curentry = m_entrymap.find(name); - if (curentry == NULL) + if (curentry == nullptr) { strcatprintf(error_string, "Attempted to set unknown option %s\n", name); return false; @@ -651,7 +651,7 @@ void core_options::set_flag(const char *name, UINT32 mask, UINT32 flag) { // find the entry first entry *curentry = m_entrymap.find(name); - if ( curentry == NULL ) + if ( curentry == nullptr ) { return; } @@ -682,7 +682,7 @@ void core_options::append_entry(core_options::entry &newentry) // if we have names, add them to the map for (int name = 0; name < ARRAY_LENGTH(newentry.m_name); name++) - if (newentry.name(name) != NULL) + if (newentry.name(name) != nullptr) { m_entrymap.add(newentry.name(name), &newentry); @@ -725,7 +725,7 @@ void core_options::copyfrom(const core_options &src) reset(); // iterate through the src options and make our own - for (entry *curentry = src.m_entrylist.first(); curentry != NULL; curentry = curentry->next()) + for (entry *curentry = src.m_entrylist.first(); curentry != nullptr; curentry = curentry->next()) append_entry(*global_alloc(entry(curentry->name(), curentry->description(), curentry->flags(), curentry->default_value()))); } diff --git a/src/lib/util/options.h b/src/lib/util/options.h index 1ef4636e1e6..a03e8217abf 100644 --- a/src/lib/util/options.h +++ b/src/lib/util/options.h @@ -70,12 +70,12 @@ public: friend class simple_list<entry>; // construction/destruction - entry(const char *name, const char *description, UINT32 flags = 0, const char *defvalue = NULL); + entry(const char *name, const char *description, UINT32 flags = 0, const char *defvalue = nullptr); public: // getters entry *next() const { return m_next; } - const char *name(int index = 0) const { return (index < ARRAY_LENGTH(m_name) && !m_name[index].empty()) ? m_name[index].c_str() : NULL; } + const char *name(int index = 0) const { return (index < ARRAY_LENGTH(m_name) && !m_name[index].empty()) ? m_name[index].c_str() : nullptr; } const char *description() const { return m_description; } const char *value() const { return m_data.c_str(); } const char *default_value() const { return m_defdata.c_str(); } @@ -130,7 +130,7 @@ public: const char *command() const { return m_command.c_str(); } // configuration - void add_entry(const char *name, const char *description, UINT32 flags = 0, const char *defvalue = NULL, bool override_existing = false); + void add_entry(const char *name, const char *description, UINT32 flags = 0, const char *defvalue = nullptr, bool override_existing = false); void add_entry(const options_entry &data, bool override_existing = false) { add_entry(data.name, data.description, data.flags, data.defvalue, override_existing); } void add_entries(const options_entry *entrylist, bool override_existing = false); void set_default_value(const char *name, const char *defvalue); @@ -145,7 +145,7 @@ public: void revert(int priority = OPTION_PRIORITY_MAXIMUM); // output - const char *output_ini(std::string &buffer, const core_options *diff = NULL); + const char *output_ini(std::string &buffer, const core_options *diff = nullptr); const char *output_help(std::string &buffer); // reading diff --git a/src/lib/util/palette.cpp b/src/lib/util/palette.cpp index cafdce24ebd..bd3c2d45ede 100644 --- a/src/lib/util/palette.cpp +++ b/src/lib/util/palette.cpp @@ -66,7 +66,7 @@ const UINT32 *palette_client::dirty_state::dirty_list(UINT32 &mindirty, UINT32 & maxdirty = m_maxdirty; // if nothing to report, report nothing - return (m_mindirty > m_maxdirty) ? NULL : &m_dirty[0]; + return (m_mindirty > m_maxdirty) ? nullptr : &m_dirty[0]; } @@ -128,7 +128,7 @@ void palette_client::dirty_state::reset() palette_client::palette_client(palette_t &palette) : m_palette(palette), - m_next(NULL), + m_next(nullptr), m_live(&m_dirty[0]), m_previous(&m_dirty[1]) { @@ -153,7 +153,7 @@ palette_client::palette_client(palette_t &palette) palette_client::~palette_client() { // first locate and remove ourself from our palette's list - for (palette_client **curptr = &m_palette.m_client_list; *curptr != NULL; curptr = &(*curptr)->m_next) + for (palette_client **curptr = &m_palette.m_client_list; *curptr != nullptr; curptr = &(*curptr)->m_next) if (*curptr == this) { *curptr = m_next; @@ -174,8 +174,8 @@ const UINT32 *palette_client::dirty_list(UINT32 &mindirty, UINT32 &maxdirty) { // if nothing to report, report nothing and don't swap const UINT32 *result = m_live->dirty_list(mindirty, maxdirty); - if (result == NULL) - return NULL; + if (result == nullptr) + return nullptr; // swap the live and previous lists dirty_state *temp = m_live; @@ -220,7 +220,7 @@ palette_t::palette_t(UINT32 numcolors, UINT32 numgroups) m_adjusted_rgb15(numcolors * numgroups + 2), m_group_bright(numgroups), m_group_contrast(numgroups), - m_client_list(NULL) + m_client_list(nullptr) { // initialize gamma map for (UINT32 index = 0; index < 256; index++) @@ -556,6 +556,6 @@ void palette_t::update_adjusted_color(UINT32 group, UINT32 index) m_adjusted_rgb15[finalindex] = adjusted.as_rgb15(); // mark dirty in all clients - for (palette_client *client = m_client_list; client != NULL; client = client->next()) + for (palette_client *client = m_client_list; client != nullptr; client = client->next()) client->mark_dirty(finalindex); } diff --git a/src/lib/util/png.cpp b/src/lib/util/png.cpp index 706dfb5e50f..6e57d949f47 100644 --- a/src/lib/util/png.cpp +++ b/src/lib/util/png.cpp @@ -115,26 +115,26 @@ INLINE int compute_rowbytes(const png_info *pnginfo) void png_free(png_info *pnginfo) { - while (pnginfo->textlist != NULL) + while (pnginfo->textlist != nullptr) { png_text *temp = pnginfo->textlist; pnginfo->textlist = temp->next; - if (temp->keyword != NULL) + if (temp->keyword != nullptr) free((void *)temp->keyword); free(temp); } - if (pnginfo->palette != NULL) + if (pnginfo->palette != nullptr) free(pnginfo->palette); - pnginfo->palette = NULL; + pnginfo->palette = nullptr; - if (pnginfo->trans != NULL) + if (pnginfo->trans != nullptr) free(pnginfo->trans); - pnginfo->trans = NULL; + pnginfo->trans = nullptr; - if (pnginfo->image != NULL) + if (pnginfo->image != nullptr) free(pnginfo->image); - pnginfo->image = NULL; + pnginfo->image = nullptr; } @@ -191,19 +191,19 @@ static png_error read_chunk(core_file *fp, UINT8 **data, UINT32 *type, UINT32 *l crc = crc32(0, tempbuff, 4); /* read the chunk itself into an allocated memory buffer */ - *data = NULL; + *data = nullptr; if (*length != 0) { /* allocate memory for this chunk */ *data = (UINT8 *)malloc(*length); - if (*data == NULL) + if (*data == nullptr) return PNGERR_OUT_OF_MEMORY; /* read the data from the file */ if (core_fread(fp, *data, *length) != *length) { free(*data); - *data = NULL; + *data = nullptr; return PNGERR_FILE_TRUNCATED; } @@ -215,7 +215,7 @@ static png_error read_chunk(core_file *fp, UINT8 **data, UINT32 *type, UINT32 *l if (core_fread(fp, tempbuff, 4) != 4) { free(*data); - *data = NULL; + *data = nullptr; return PNGERR_FILE_TRUNCATED; } chunk_crc = fetch_32bit(tempbuff); @@ -224,7 +224,7 @@ static png_error read_chunk(core_file *fp, UINT8 **data, UINT32 *type, UINT32 *l if (crc != chunk_crc) { free(*data); - *data = NULL; + *data = nullptr; return PNGERR_FILE_CORRUPT; } return PNGERR_NONE; @@ -273,11 +273,11 @@ static png_error process_chunk(png_private *png, UINT8 *data, UINT32 type, UINT3 /* allocate a new image data descriptor */ *png->idata_next = (image_data_chunk *)malloc(sizeof(**png->idata_next)); - if (*png->idata_next == NULL) + if (*png->idata_next == nullptr) return PNGERR_OUT_OF_MEMORY; /* add it to the tail of the list */ - (*png->idata_next)->next = NULL; + (*png->idata_next)->next = nullptr; (*png->idata_next)->length = length; (*png->idata_next)->data = data; png->idata_next = &(*png->idata_next)->next; @@ -303,17 +303,17 @@ static png_error process_chunk(png_private *png, UINT8 *data, UINT32 type, UINT3 /* allocate a new text item */ text = (png_text *)malloc(sizeof(*text)); - if (text == NULL) + if (text == nullptr) return PNGERR_OUT_OF_MEMORY; /* set the elements */ text->keyword = (char *)data; text->text = text->keyword + strlen(text->keyword) + 1; - text->next = NULL; + text->next = nullptr; /* add to the end of the list */ - for (pt = NULL, ct = png->pnginfo->textlist; ct != NULL; pt = ct, ct = ct->next) ; - if (pt == NULL) + for (pt = nullptr, ct = png->pnginfo->textlist; ct != nullptr; pt = ct, ct = ct->next) ; + if (pt == nullptr) png->pnginfo->textlist = text; else pt->next = text; @@ -359,7 +359,7 @@ static png_error unfilter_row(int type, UINT8 *src, UINT8 *dst, UINT8 *dstprev, /* UP = pixel above */ case PNG_PF_Up: - if (dstprev == NULL) + if (dstprev == nullptr) return unfilter_row(PNG_PF_None, src, dst, dstprev, bpp, rowbytes); for (x = 0; x < rowbytes; x++, dst++) *dst = *src++ + *dstprev++; @@ -367,7 +367,7 @@ static png_error unfilter_row(int type, UINT8 *src, UINT8 *dst, UINT8 *dstprev, /* AVERAGE = average of pixel above and previous pixel */ case PNG_PF_Average: - if (dstprev == NULL) + if (dstprev == nullptr) { for (x = 0; x < bpp; x++) *dst++ = *src++; @@ -388,8 +388,8 @@ static png_error unfilter_row(int type, UINT8 *src, UINT8 *dst, UINT8 *dstprev, for (x = 0; x < rowbytes; x++) { INT32 pa = (x < bpp) ? 0 : dst[-bpp]; - INT32 pc = (x < bpp || dstprev == NULL) ? 0 : dstprev[-bpp]; - INT32 pb = (dstprev == NULL) ? 0 : *dstprev++; + INT32 pc = (x < bpp || dstprev == nullptr) ? 0 : dstprev[-bpp]; + INT32 pb = (dstprev == nullptr) ? 0 : *dstprev++; INT32 prediction = pa + pb - pc; INT32 da = abs(prediction - pa); INT32 db = abs(prediction - pb); @@ -432,7 +432,7 @@ static png_error process_image(png_private *png) /* allocate memory for the filtered image */ png->pnginfo->image = (UINT8 *)malloc(imagesize); - if (png->pnginfo->image == NULL) + if (png->pnginfo->image == nullptr) return PNGERR_OUT_OF_MEMORY; /* initialize the stream */ @@ -447,7 +447,7 @@ static png_error process_image(png_private *png) } /* loop over IDAT and decompress each as part of a larger stream */ - for (idat = png->idata; idat != NULL; idat = idat->next) + for (idat = png->idata; idat != nullptr; idat = idat->next) { /* decompress this chunk */ stream.next_in = idat->data; @@ -482,7 +482,7 @@ static png_error process_image(png_private *png) { /* first byte of each row is the filter type */ int filter = *src++; - error = unfilter_row(filter, src, dst, (y == 0) ? NULL : &dst[-rowbytes], bpp, rowbytes); + error = unfilter_row(filter, src, dst, (y == 0) ? nullptr : &dst[-rowbytes], bpp, rowbytes); src += rowbytes; dst += rowbytes; } @@ -492,7 +492,7 @@ handle_error: if (error != PNGERR_NONE) { free(png->pnginfo->image); - png->pnginfo->image = NULL; + png->pnginfo->image = nullptr; } return error; } @@ -504,7 +504,7 @@ handle_error: png_error png_read_file(core_file *fp, png_info *pnginfo) { - UINT8 *chunk_data = NULL; + UINT8 *chunk_data = nullptr; png_private png; png_error error; @@ -542,7 +542,7 @@ png_error png_read_file(core_file *fp, png_info *pnginfo) /* free memory if we didn't want to keep it */ if (!keepmem) free(chunk_data); - chunk_data = NULL; + chunk_data = nullptr; } /* finish processing the image */ @@ -553,15 +553,15 @@ png_error png_read_file(core_file *fp, png_info *pnginfo) handle_error: /* free all intermediate data */ - while (png.idata != NULL) + while (png.idata != nullptr) { image_data_chunk *next = png.idata->next; - if (png.idata->data != NULL) + if (png.idata->data != nullptr) free(png.idata->data); free(png.idata); png.idata = next; } - if (chunk_data != NULL) + if (chunk_data != nullptr) free(chunk_data); /* if we have an error, free all the other data as well */ @@ -665,7 +665,7 @@ png_error png_expand_buffer_8bit(png_info *pnginfo) /* allocate a new buffer at 8-bit */ outbuf = (UINT8 *)malloc(pnginfo->width * pnginfo->height); - if (outbuf == NULL) + if (outbuf == nullptr) return PNGERR_OUT_OF_MEMORY; inp = pnginfo->image; @@ -710,13 +710,13 @@ png_error png_add_text(png_info *pnginfo, const char *keyword, const char *text) /* allocate a new text element */ newtext = (png_text *)malloc(sizeof(*newtext)); - if (newtext == NULL) + if (newtext == nullptr) return PNGERR_OUT_OF_MEMORY; /* allocate a string long enough to hold both */ keylen = (int)strlen(keyword); textdata = (char *)malloc(keylen + 1 + strlen(text) + 1); - if (textdata == NULL) + if (textdata == nullptr) { free(newtext); return PNGERR_OUT_OF_MEMORY; @@ -729,11 +729,11 @@ png_error png_add_text(png_info *pnginfo, const char *keyword, const char *text) /* text follows a trailing NULL */ newtext->keyword = textdata; newtext->text = textdata + keylen + 1; - newtext->next = NULL; + newtext->next = nullptr; /* add us to the end of the linked list */ - for (pt = NULL, ct = pnginfo->textlist; ct != NULL; pt = ct, ct = ct->next) ; - if (pt == NULL) + for (pt = nullptr, ct = pnginfo->textlist; ct != nullptr; pt = ct, ct = ct->next) ; + if (pt == nullptr) pnginfo->textlist = newtext; else pt->next = newtext; @@ -884,7 +884,7 @@ static png_error convert_bitmap_to_image_palette(png_info *pnginfo, const bitmap /* allocate memory for the palette */ pnginfo->palette = (UINT8 *)malloc(3 * 256); - if (pnginfo->palette == NULL) + if (pnginfo->palette == nullptr) return PNGERR_OUT_OF_MEMORY; /* build the palette */ @@ -899,7 +899,7 @@ static png_error convert_bitmap_to_image_palette(png_info *pnginfo, const bitmap /* allocate memory for the image */ pnginfo->image = (UINT8 *)malloc(pnginfo->height * (rowbytes + 1)); - if (pnginfo->image == NULL) + if (pnginfo->image == nullptr) { free(pnginfo->palette); return PNGERR_OUT_OF_MEMORY; @@ -941,7 +941,7 @@ static png_error convert_bitmap_to_image_rgb(png_info *pnginfo, const bitmap_t & /* allocate memory for the image */ pnginfo->image = (UINT8 *)malloc(pnginfo->height * (rowbytes + 1)); - if (pnginfo->image == NULL) + if (pnginfo->image == nullptr) return PNGERR_OUT_OF_MEMORY; /* copy in the pixels, specifying a NULL filter */ @@ -1046,7 +1046,7 @@ static png_error write_png_stream(core_file *fp, png_info *pnginfo, const bitmap goto handle_error; /* write TEXT chunks */ - for (text = pnginfo->textlist; text != NULL; text = text->next) + for (text = pnginfo->textlist; text != nullptr; text = text->next) { error = write_chunk(fp, (UINT8 *)text->keyword, PNG_CN_tEXt, (UINT32)strlen(text->keyword) + 1 + (UINT32)strlen(text->text)); if (error != PNGERR_NONE) @@ -1054,7 +1054,7 @@ static png_error write_png_stream(core_file *fp, png_info *pnginfo, const bitmap } /* write an IEND chunk */ - error = write_chunk(fp, NULL, PNG_CN_IEND, 0); + error = write_chunk(fp, nullptr, PNG_CN_IEND, 0); handle_error: return error; @@ -1067,7 +1067,7 @@ png_error png_write_bitmap(core_file *fp, png_info *info, bitmap_t &bitmap, int png_error error; /* use a dummy pnginfo if none passed to us */ - if (info == NULL) + if (info == nullptr) { info = &pnginfo; memset(&pnginfo, 0, sizeof(pnginfo)); @@ -1161,5 +1161,5 @@ png_error mng_capture_frame(core_file *fp, png_info *info, bitmap_t &bitmap, int png_error mng_capture_stop(core_file *fp) { - return write_chunk(fp, NULL, MNG_CN_MEND, 0); + return write_chunk(fp, nullptr, MNG_CN_MEND, 0); } diff --git a/src/lib/util/pool.cpp b/src/lib/util/pool.cpp index ab62f47c6aa..e004f236b76 100644 --- a/src/lib/util/pool.cpp +++ b/src/lib/util/pool.cpp @@ -115,11 +115,11 @@ INLINE objtype_entry *get_object_type(object_pool *pool, object_type type) { objtype_entry *entry; - for (entry = pool->typelist; entry != NULL; entry = entry->next) + for (entry = pool->typelist; entry != nullptr; entry = entry->next) if (entry->type == type) return entry; - return NULL; + return nullptr; } @@ -138,8 +138,8 @@ object_pool *pool_alloc_lib(void (*fail)(const char *message)) /* allocate memory for the pool itself */ pool = (object_pool *)malloc(sizeof(*pool)); - if (pool == NULL) - return NULL; + if (pool == nullptr) + return nullptr; memset(pool, 0, sizeof(*pool)); /* set the failure handler */ @@ -162,11 +162,11 @@ void pool_type_register(object_pool *pool, object_type type, const char *friendl objtype_entry *newtype = get_object_type(pool, type); /* if the type doesn't already exist... */ - if (newtype == NULL) + if (newtype == nullptr) { /* allocate a new entry */ newtype = (objtype_entry *)malloc(sizeof(*newtype)); - if (newtype == NULL) + if (newtype == nullptr) { report_failure(pool, "Error adding new type %s\n", friendly); return; @@ -195,7 +195,7 @@ void pool_clear(object_pool *pool) object_entry *entry, *next; /* iterate over all entries in the global list and free them */ - for (entry = pool->globallist; entry != NULL; entry = next) + for (entry = pool->globallist; entry != nullptr; entry = next) { /* remember the next entry */ next = entry->globalnext; @@ -205,7 +205,7 @@ void pool_clear(object_pool *pool) /* add ourself to the free list */ entry->next = pool->freelist; - entry->globalnext = entry->globalprev = NULL; + entry->globalnext = entry->globalprev = nullptr; pool->freelist = entry; } @@ -228,14 +228,14 @@ void pool_free_lib(object_pool *pool) pool_clear(pool); /* free all entry blocks */ - for (block = pool->blocklist; block != NULL; block = nextblock) + for (block = pool->blocklist; block != nullptr; block = nextblock) { nextblock = block->next; free(block); } /* free all types */ - for (type = pool->typelist; type != NULL; type = nexttype) + for (type = pool->typelist; type != nullptr; type = nexttype) { nexttype = type->next; free(type); @@ -263,29 +263,29 @@ void *pool_object_add_file_line(object_pool *pool, object_type _type, void *obje object_entry *entry; /* if we have an invalid type, fail */ - if (type == NULL) + if (type == nullptr) { report_failure(pool, "pool_object_add (via %s:%d): Attempted to add object of unknown type with size %d", file, line, (int)size); return object; } /* if we get a NULL object, fail */ - if (object == NULL) + if (object == nullptr) { report_failure(pool, "pool_object_add (via %s:%d): Attempted to add a NULL object of size %d", file, line, (int)size); return object; } /* allocate a new entry */ - if (pool->freelist == NULL) + if (pool->freelist == nullptr) { object_entry_block *block; int entrynum; /* if we need a new block, allocate that now */ block = (object_entry_block *)malloc(sizeof(*block)); - if (block == NULL) - return NULL; + if (block == nullptr) + return nullptr; memset(block, 0, sizeof(*block)); /* hook us into the blocklist */ @@ -312,9 +312,9 @@ void *pool_object_add_file_line(object_pool *pool, object_type _type, void *obje entry->line = line; /* hook us into the global list */ - if (pool->globallist != NULL) + if (pool->globallist != nullptr) pool->globallist->globalprev = entry; - entry->globalprev = NULL; + entry->globalprev = nullptr; entry->globalnext = pool->globallist; pool->globallist = entry; @@ -336,7 +336,7 @@ void *pool_object_remove(object_pool *pool, void *object, int destruct) object_entry **entryptr; /* find the object in question and remove it */ - for (entryptr = &pool->hashtable[hashnum]; *entryptr != NULL; entryptr = &(*entryptr)->next) + for (entryptr = &pool->hashtable[hashnum]; *entryptr != nullptr; entryptr = &(*entryptr)->next) if ((*entryptr)->object == object) { object_entry *entry = *entryptr; @@ -346,9 +346,9 @@ void *pool_object_remove(object_pool *pool, void *object, int destruct) (*entry->type->destructor)(entry->object, entry->size); /* remove us from the global list */ - if (entry->globalprev != NULL) + if (entry->globalprev != nullptr) entry->globalprev->globalnext = entry->globalnext; - if (entry->globalnext != NULL) + if (entry->globalnext != nullptr) entry->globalnext->globalprev = entry->globalprev; if (pool->globallist == entry) pool->globallist = entry->globalnext; @@ -362,7 +362,7 @@ void *pool_object_remove(object_pool *pool, void *object, int destruct) break; } - return NULL; + return nullptr; } @@ -377,7 +377,7 @@ int pool_object_exists(object_pool *pool, object_type type, void *object) object_entry *entry; /* find the object in question */ - for (entry = pool->hashtable[hashnum]; entry != NULL; entry = entry->next) + for (entry = pool->hashtable[hashnum]; entry != nullptr; entry = entry->next) if (entry->object == object && (type == OBJTYPE_WILDCARD || entry->type->type == type)) return TRUE; @@ -401,14 +401,14 @@ object_pool_iterator *pool_iterate_begin(object_pool *pool, object_type type) /* allocate the iterator */ iter = (object_pool_iterator *)malloc(sizeof(*iter)); - if (iter == NULL) - return NULL; + if (iter == nullptr) + return nullptr; memset(iter, 0, sizeof(*iter)); /* fill it in */ iter->pool = pool; iter->type = type; - iter->last = NULL; + iter->last = nullptr; return iter; } @@ -421,19 +421,19 @@ object_pool_iterator *pool_iterate_begin(object_pool *pool, object_type type) int pool_iterate_next(object_pool_iterator *iter, void **objectptr, size_t *sizeptr, object_type *typeptr) { /* if no previous entry, find the first */ - if (iter->last == NULL) + if (iter->last == nullptr) iter->last = iter->pool->globallist; else iter->last = iter->last->globalnext; /* stop when we get one */ - if (iter->last != NULL) + if (iter->last != nullptr) { - if (objectptr != NULL) + if (objectptr != nullptr) *objectptr = iter->last; - if (sizeptr != NULL) + if (sizeptr != nullptr) *sizeptr = iter->last->size; - if (typeptr != NULL) + if (typeptr != nullptr) *typeptr = iter->last->type->type; return TRUE; } @@ -478,7 +478,7 @@ void *pool_malloc_file_line(object_pool *pool, size_t size, const char *file, in void *pool_realloc_file_line(object_pool *pool, void *ptr, size_t size, const char *file, int line) { - if (ptr != NULL) + if (ptr != nullptr) pool_object_remove(pool, ptr, FALSE); ptr = realloc(ptr, size); if (size != 0) @@ -495,7 +495,7 @@ void *pool_realloc_file_line(object_pool *pool, void *ptr, size_t size, const ch char *pool_strdup_file_line(object_pool *pool, const char *str, const char *file, int line) { char *ptr = (char *)pool_malloc_file_line(pool, strlen(str) + 1, file, line); - if (ptr != NULL) + if (ptr != nullptr) strcpy(ptr, str); return ptr; } @@ -530,7 +530,7 @@ static void memory_destruct(void *object, size_t size) static void report_failure(object_pool *pool, const char *format, ...) { /* only do the work if we have a callback */ - if (pool->fail != NULL) + if (pool->fail != nullptr) { char message[1024]; va_list argptr; diff --git a/src/lib/util/tagmap.h b/src/lib/util/tagmap.h index 50550f3e6c3..600cc230985 100644 --- a/src/lib/util/tagmap.h +++ b/src/lib/util/tagmap.h @@ -16,6 +16,7 @@ #include "osdcore.h" #include "coretmpl.h" #include <string> +#include <utility> #ifdef MAME_DEBUG #include "eminline.h" #endif @@ -61,10 +62,10 @@ public: public: // construction/destruction entry_t(const char *tag, UINT32 fullhash, _ElementType object) - : m_next(NULL), + : m_next(nullptr), m_fullhash(fullhash), m_tag(tag), - m_object(object) { } + m_object(std::move(object)) { } // accessors const std::string &tag() const { return m_tag; } @@ -101,9 +102,9 @@ public: // empty the list void reset() { - for (UINT32 hashindex = 0; hashindex < ARRAY_LENGTH(m_table); hashindex++) - while (m_table[hashindex] != NULL) - remove_common(&m_table[hashindex]); + for (auto & elem : m_table) + while (elem != nullptr) + remove_common(&elem); } // add/remove @@ -114,7 +115,7 @@ public: void remove(const char *tag) { UINT32 fullhash = hash(tag); - for (entry_t **entryptr = &m_table[fullhash % ARRAY_LENGTH(m_table)]; *entryptr != NULL; entryptr = &(*entryptr)->m_next) + for (entry_t **entryptr = &m_table[fullhash % ARRAY_LENGTH(m_table)]; *entryptr != nullptr; entryptr = &(*entryptr)->m_next) if ((*entryptr)->fullhash() == fullhash && (*entryptr)->tag() == tag) return remove_common(entryptr); } @@ -122,8 +123,8 @@ public: // remove by object void remove(_ElementType object) { - for (UINT32 hashindex = 0; hashindex < ARRAY_LENGTH(m_table); hashindex++) - for (entry_t **entryptr = &m_table[hashindex]; *entryptr != NULL; entryptr = &(*entryptr)->m_next) + for (auto & elem : m_table) + for (entry_t **entryptr = &elem; *entryptr != nullptr; entryptr = &(*entryptr)->m_next) if ((*entryptr)->object() == object) return remove_common(entryptr); } @@ -138,10 +139,10 @@ public: if (g_tagmap_counter_enabled) atomic_increment32(&g_tagmap_finds); #endif - for (entry_t *entry = m_table[fullhash % ARRAY_LENGTH(m_table)]; entry != NULL; entry = entry->next()) + for (entry_t *entry = m_table[fullhash % ARRAY_LENGTH(m_table)]; entry != nullptr; entry = entry->next()) if (entry->fullhash() == fullhash && entry->tag() == tag) return entry->object(); - return _ElementType(NULL); + return _ElementType(nullptr); } // find by tag without checking anything but the hash @@ -152,10 +153,10 @@ public: atomic_increment32(&g_tagmap_finds); #endif UINT32 fullhash = hash(tag); - for (entry_t *entry = m_table[fullhash % ARRAY_LENGTH(m_table)]; entry != NULL; entry = entry->next()) + for (entry_t *entry = m_table[fullhash % ARRAY_LENGTH(m_table)]; entry != nullptr; entry = entry->next()) if (entry->fullhash() == fullhash) return entry->object(); - return NULL; + return nullptr; } // return first object in the table @@ -288,7 +289,7 @@ public: // operations by tag _ElementType &replace_and_remove(const char *tag, _ElementType &object) { _ElementType *existing = find(tag); return (existing == NULL) ? append(tag, object) : replace_and_remove(tag, object, *existing); } - void remove(const char *tag) { _ElementType *object = find(tag); if (object != NULL) remove(*object); } + void remove(const char *tag) { _ElementType *object = find(tag); if (object != nullptr) remove(*object); } _ElementType *find(const char *tag) const { return m_map.find_hash_only(tag); } int indexof(const char *tag) const { _ElementType *object = find(tag); return (object != NULL) ? m_list.indexof(*object) : NULL; } @@ -316,7 +317,7 @@ tagmap_error tagmap_t<_ElementType, _HashSize>::add_common(const char *tag, _Ele UINT32 hashindex = fullhash % ARRAY_LENGTH(m_table); // first make sure we don't have a duplicate - for (entry_t *entry = m_table[hashindex]; entry != NULL; entry = entry->next()) + for (entry_t *entry = m_table[hashindex]; entry != nullptr; entry = entry->next()) if (entry->fullhash() == fullhash) if (unique_hash || entry->tag() == tag) { @@ -326,7 +327,7 @@ tagmap_error tagmap_t<_ElementType, _HashSize>::add_common(const char *tag, _Ele } // now allocate a new entry and add to the head of the list - entry_t *entry = global_alloc(entry_t(tag, fullhash, object)); + auto entry = global_alloc(entry_t(tag, fullhash, object)); entry->m_next = m_table[hashindex]; m_table[hashindex] = entry; return TMERR_NONE; diff --git a/src/lib/util/un7z.cpp b/src/lib/util/un7z.cpp index bbae440e0ff..b9cfa13eafe 100644 --- a/src/lib/util/un7z.cpp +++ b/src/lib/util/un7z.cpp @@ -24,7 +24,7 @@ void *SZipAlloc(void *p, size_t size) { if (size == 0) - return 0; + return nullptr; return malloc(size); } @@ -38,7 +38,7 @@ void SZipFree(void *p, void *address) void File_Construct(CSzFile *p) { - p->_7z_osdfile = NULL; + p->_7z_osdfile = nullptr; } static WRes File_Open(CSzFile *p, const char *name, int writeMode) @@ -186,7 +186,7 @@ static void free__7z_file(_7z_file *_7z); int _7z_search_crc_match(_7z_file *new_7z, UINT32 search_crc, const char* search_filename, int search_filename_length, bool matchcrc, bool matchname) { - UInt16 *temp = NULL; + UInt16 *temp = nullptr; size_t tempSize = 0; for (int i = 0; i < new_7z->db.db.NumFiles; i++) @@ -194,7 +194,7 @@ int _7z_search_crc_match(_7z_file *new_7z, UINT32 search_crc, const char* search const CSzFileItem *f = new_7z->db.db.Files + i; size_t len; - len = SzArEx_GetFileNameUtf16(&new_7z->db, i, NULL); + len = SzArEx_GetFileNameUtf16(&new_7z->db, i, nullptr); // if it's a directory entry we don't care about it.. if (f->IsDir) @@ -202,10 +202,10 @@ int _7z_search_crc_match(_7z_file *new_7z, UINT32 search_crc, const char* search if (len > tempSize) { - SZipFree(NULL, temp); + SZipFree(nullptr, temp); tempSize = len; - temp = (UInt16 *)SZipAlloc(NULL, tempSize * sizeof(temp[0])); - if (temp == 0) + temp = (UInt16 *)SZipAlloc(nullptr, tempSize * sizeof(temp[0])); + if (temp == nullptr) { return -1; // memory error } @@ -265,12 +265,12 @@ int _7z_search_crc_match(_7z_file *new_7z, UINT32 search_crc, const char* search new_7z->uncompressed_length = size; new_7z->crc = crc; - SZipFree(NULL, temp); + SZipFree(nullptr, temp); return i; } } - SZipFree(NULL, temp); + SZipFree(nullptr, temp); return -1; } @@ -288,7 +288,7 @@ _7z_error _7z_file_open(const char *filename, _7z_file **_7z) SRes res; /* ensure we start with a NULL result */ - *_7z = NULL; + *_7z = nullptr; /* see if we are in the cache, and reopen if so */ for (cachenum = 0; cachenum < ARRAY_LENGTH(_7z_cache); cachenum++) @@ -296,17 +296,17 @@ _7z_error _7z_file_open(const char *filename, _7z_file **_7z) _7z_file *cached = _7z_cache[cachenum]; /* if we have a valid entry and it matches our filename, use it and remove from the cache */ - if (cached != NULL && cached->filename != NULL && strcmp(filename, cached->filename) == 0) + if (cached != nullptr && cached->filename != nullptr && strcmp(filename, cached->filename) == 0) { *_7z = cached; - _7z_cache[cachenum] = NULL; + _7z_cache[cachenum] = nullptr; return _7ZERR_NONE; } } /* allocate memory for the _7z_file structure */ new_7z = (_7z_file *)malloc(sizeof(*new_7z)); - if (new_7z == NULL) + if (new_7z == nullptr) return _7ZERR_OUT_OF_MEMORY; memset(new_7z, 0, sizeof(*new_7z)); @@ -350,12 +350,12 @@ _7z_error _7z_file_open(const char *filename, _7z_file **_7z) } new_7z->blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */ - new_7z->outBuffer = 0; /* it must be 0 before first call for each new archive. */ + new_7z->outBuffer = nullptr; /* it must be 0 before first call for each new archive. */ new_7z->outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */ /* make a copy of the filename for caching purposes */ string = (char *)malloc(strlen(filename) + 1); - if (string == NULL) + if (string == nullptr) { _7zerr = _7ZERR_OUT_OF_MEMORY; goto error; @@ -381,13 +381,13 @@ void _7z_file_close(_7z_file *_7z) int cachenum; /* close the open files */ - if (_7z->archiveStream.file._7z_osdfile != NULL) + if (_7z->archiveStream.file._7z_osdfile != nullptr) osd_close(_7z->archiveStream.file._7z_osdfile); - _7z->archiveStream.file._7z_osdfile = NULL; + _7z->archiveStream.file._7z_osdfile = nullptr; /* find the first NULL entry in the cache */ for (cachenum = 0; cachenum < ARRAY_LENGTH(_7z_cache); cachenum++) - if (_7z_cache[cachenum] == NULL) + if (_7z_cache[cachenum] == nullptr) break; /* if no room left in the cache, free the bottommost entry */ @@ -412,10 +412,10 @@ void _7z_file_cache_clear(void) /* clear call cache entries */ for (cachenum = 0; cachenum < ARRAY_LENGTH(_7z_cache); cachenum++) - if (_7z_cache[cachenum] != NULL) + if (_7z_cache[cachenum] != nullptr) { free__7z_file(_7z_cache[cachenum]); - _7z_cache[cachenum] = NULL; + _7z_cache[cachenum] = nullptr; } } @@ -432,7 +432,7 @@ _7z_error _7z_file_decompress(_7z_file *new_7z, void *buffer, UINT32 length) int index = new_7z->curr_file_idx; /* make sure the file is open.. */ - if (new_7z->archiveStream.file._7z_osdfile==NULL) + if (new_7z->archiveStream.file._7z_osdfile==nullptr) { new_7z->archiveStream.file._7z_currfpos = 0; err = osd_open(new_7z->filename, OPEN_FLAG_READ, &new_7z->archiveStream.file._7z_osdfile, &new_7z->archiveStream.file._7z_length); @@ -477,11 +477,11 @@ _7z_error _7z_file_decompress(_7z_file *new_7z, void *buffer, UINT32 length) static void free__7z_file(_7z_file *_7z) { - if (_7z != NULL) + if (_7z != nullptr) { - if (_7z->archiveStream.file._7z_osdfile != NULL) + if (_7z->archiveStream.file._7z_osdfile != nullptr) osd_close(_7z->archiveStream.file._7z_osdfile); - if (_7z->filename != NULL) + if (_7z->filename != nullptr) free((void *)_7z->filename); diff --git a/src/lib/util/unicode.cpp b/src/lib/util/unicode.cpp index 5f375337b34..e2c3956cedb 100644 --- a/src/lib/util/unicode.cpp +++ b/src/lib/util/unicode.cpp @@ -34,7 +34,7 @@ int uchar_from_utf8(unicode_char *uchar, const char *utf8char, size_t count) char auxchar; /* validate parameters */ - if (utf8char == NULL || count == 0) + if (utf8char == nullptr || count == 0) return 0; /* start with the first byte */ @@ -127,7 +127,7 @@ int uchar_from_utf16(unicode_char *uchar, const utf16_char *utf16char, size_t co int rc = -1; /* validate parameters */ - if (utf16char == NULL || count == 0) + if (utf16char == nullptr || count == 0) return 0; /* handle the two-byte case */ diff --git a/src/lib/util/unzip.cpp b/src/lib/util/unzip.cpp index 21e137b9f24..a8f3ca434e2 100644 --- a/src/lib/util/unzip.cpp +++ b/src/lib/util/unzip.cpp @@ -185,7 +185,7 @@ zip_error zip_file_open(const char *filename, zip_file **zip) int cachenum; /* ensure we start with a NULL result */ - *zip = NULL; + *zip = nullptr; /* see if we are in the cache, and reopen if so */ for (cachenum = 0; cachenum < ARRAY_LENGTH(zip_cache); cachenum++) @@ -193,17 +193,17 @@ zip_error zip_file_open(const char *filename, zip_file **zip) zip_file *cached = zip_cache[cachenum]; /* if we have a valid entry and it matches our filename, use it and remove from the cache */ - if (cached != NULL && cached->filename != NULL && strcmp(filename, cached->filename) == 0) + if (cached != nullptr && cached->filename != nullptr && strcmp(filename, cached->filename) == 0) { *zip = cached; - zip_cache[cachenum] = NULL; + zip_cache[cachenum] = nullptr; return ZIPERR_NONE; } } /* allocate memory for the zip_file structure */ newzip = (zip_file *)malloc(sizeof(*newzip)); - if (newzip == NULL) + if (newzip == nullptr) return ZIPERR_OUT_OF_MEMORY; memset(newzip, 0, sizeof(*newzip)); @@ -229,7 +229,7 @@ zip_error zip_file_open(const char *filename, zip_file **zip) /* allocate memory for the central directory */ newzip->cd = (UINT8 *)malloc(newzip->ecd.cd_size + 1); - if (newzip->cd == NULL) + if (newzip->cd == nullptr) { ziperr = ZIPERR_OUT_OF_MEMORY; goto error; @@ -245,7 +245,7 @@ zip_error zip_file_open(const char *filename, zip_file **zip) /* make a copy of the filename for caching purposes */ string = (char *)malloc(strlen(filename) + 1); - if (string == NULL) + if (string == nullptr) { ziperr = ZIPERR_OUT_OF_MEMORY; goto error; @@ -279,13 +279,13 @@ void zip_file_close(zip_file *zip) int cachenum; /* close the open files */ - if (zip->file != NULL) + if (zip->file != nullptr) osd_close(zip->file); - zip->file = NULL; + zip->file = nullptr; /* find the first NULL entry in the cache */ for (cachenum = 0; cachenum < ARRAY_LENGTH(zip_cache); cachenum++) - if (zip_cache[cachenum] == NULL) + if (zip_cache[cachenum] == nullptr) break; /* if no room left in the cache, free the bottommost entry */ @@ -316,10 +316,10 @@ void zip_file_cache_clear(void) /* clear call cache entries */ for (cachenum = 0; cachenum < ARRAY_LENGTH(zip_cache); cachenum++) - if (zip_cache[cachenum] != NULL) + if (zip_cache[cachenum] != nullptr) { free_zip_file(zip_cache[cachenum]); - zip_cache[cachenum] = NULL; + zip_cache[cachenum] = nullptr; } } @@ -370,15 +370,15 @@ const zip_file_header *zip_file_first_file(zip_file *zip) const zip_file_header *zip_file_next_file(zip_file *zip) { /* fix up any modified data */ - if (zip->header.raw != NULL) + if (zip->header.raw != nullptr) { zip->header.raw[ZIPCFN + zip->header.filename_length] = zip->header.saved; - zip->header.raw = NULL; + zip->header.raw = nullptr; } /* if we're at or past the end, we're done */ if (zip->cd_pos >= zip->ecd.cd_size) - return NULL; + return nullptr; /* extract file header info */ zip->header.raw = zip->cd + zip->cd_pos; @@ -407,7 +407,7 @@ const zip_file_header *zip_file_next_file(zip_file *zip) zip->header.rawlength += zip->header.extra_field_length; zip->header.rawlength += zip->header.file_comment_length; if (zip->cd_pos + zip->header.rawlength > zip->ecd.cd_size) - return NULL; + return nullptr; /* NULL terminate the filename */ zip->header.saved = zip->header.raw[ZIPCFN + zip->header.filename_length]; @@ -493,15 +493,15 @@ zip_error zip_file_decompress(zip_file *zip, void *buffer, UINT32 length) static void free_zip_file(zip_file *zip) { - if (zip != NULL) + if (zip != nullptr) { - if (zip->file != NULL) + if (zip->file != nullptr) osd_close(zip->file); - if (zip->filename != NULL) + if (zip->filename != nullptr) free((void *)zip->filename); - if (zip->ecd.raw != NULL) + if (zip->ecd.raw != nullptr) free(zip->ecd.raw); - if (zip->cd != NULL) + if (zip->cd != nullptr) free(zip->cd); free(zip); } @@ -545,7 +545,7 @@ static zip_error read_ecd(zip_file *zip) /* allocate buffer */ buffer = (UINT8 *)malloc(buflen + 1); - if (buffer == NULL) + if (buffer == nullptr) return ZIPERR_OUT_OF_MEMORY; /* read in one buffers' worth of data */ @@ -618,7 +618,7 @@ static zip_error get_compressed_data_offset(zip_file *zip, UINT64 *offset) UINT32 read_length; /* make sure the file handle is open */ - if (zip->file == NULL) + if (zip->file == nullptr) { int filerr = osd_open(zip->filename, OPEN_FLAG_READ, &zip->file, &zip->length); if (filerr != FILERR_NONE) diff --git a/src/lib/util/vbiparse.cpp b/src/lib/util/vbiparse.cpp index 9c6c39fc4ea..ff523ee4265 100644 --- a/src/lib/util/vbiparse.cpp +++ b/src/lib/util/vbiparse.cpp @@ -398,7 +398,7 @@ void vbi_metadata_pack(UINT8 *dest, UINT32 framenum, const vbi_metadata *vbi) void vbi_metadata_unpack(vbi_metadata *vbi, UINT32 *framenum, const UINT8 *source) { - if (framenum != NULL) + if (framenum != nullptr) *framenum = (source[0] << 16) | (source[1] << 8) | source[2]; vbi->white = source[3]; vbi->line16 = (source[4] << 16) | (source[5] << 8) | source[6]; diff --git a/src/lib/util/xmlfile.cpp b/src/lib/util/xmlfile.cpp index cb674abfa2b..620f12a66b3 100644 --- a/src/lib/util/xmlfile.cpp +++ b/src/lib/util/xmlfile.cpp @@ -71,12 +71,12 @@ static const char *copystring(const char *input) char *newstr; /* NULL just passes through */ - if (input == NULL) - return NULL; + if (input == nullptr) + return nullptr; /* make a lower-case copy if the allocation worked */ newstr = (char *)malloc(strlen(input) + 1); - if (newstr != NULL) + if (newstr != nullptr) strcpy(newstr, input); return newstr; @@ -95,12 +95,12 @@ static const char *copystring_lower(const char *input) int i; /* NULL just passes through */ - if (input == NULL) - return NULL; + if (input == nullptr) + return nullptr; /* make a lower-case copy if the allocation worked */ newstr = (char *)malloc(strlen(input) + 1); - if (newstr != NULL) + if (newstr != nullptr) { for (i = 0; input[i] != 0; i++) newstr[i] = tolower((UINT8)input[i]); @@ -127,8 +127,8 @@ xml_data_node *xml_file_create(void) /* create a root node */ rootnode = (xml_data_node *)malloc(sizeof(*rootnode)); - if (rootnode == NULL) - return NULL; + if (rootnode == nullptr) + return nullptr; memset(rootnode, 0, sizeof(*rootnode)); return rootnode; } @@ -146,7 +146,7 @@ xml_data_node *xml_file_read(core_file *file, xml_parse_options *opts) /* set up the parser */ if (!expat_setup_parser(&parse_info, opts)) - return NULL; + return nullptr; /* loop through the file and parse it */ do @@ -160,7 +160,7 @@ xml_data_node *xml_file_read(core_file *file, xml_parse_options *opts) /* parse the data */ if (XML_Parse(parse_info.parser, tempbuf, bytes, done) == XML_STATUS_ERROR) { - if (opts != NULL && opts->error != NULL) + if (opts != nullptr && opts->error != nullptr) { opts->error->error_message = XML_ErrorString(XML_GetErrorCode(parse_info.parser)); opts->error->error_line = XML_GetCurrentLineNumber(parse_info.parser); @@ -169,7 +169,7 @@ xml_data_node *xml_file_read(core_file *file, xml_parse_options *opts) xml_file_free(parse_info.rootnode); XML_ParserFree(parse_info.parser); - return NULL; + return nullptr; } } while (!done); @@ -194,12 +194,12 @@ xml_data_node *xml_string_read(const char *string, xml_parse_options *opts) /* set up the parser */ if (!expat_setup_parser(&parse_info, opts)) - return NULL; + return nullptr; /* parse the data */ if (XML_Parse(parse_info.parser, string, length, TRUE) == XML_STATUS_ERROR) { - if (opts != NULL && opts->error != NULL) + if (opts != nullptr && opts->error != nullptr) { opts->error->error_message = XML_ErrorString(XML_GetErrorCode(parse_info.parser)); opts->error->error_line = XML_GetCurrentLineNumber(parse_info.parser); @@ -208,7 +208,7 @@ xml_data_node *xml_string_read(const char *string, xml_parse_options *opts) xml_file_free(parse_info.rootnode); XML_ParserFree(parse_info.parser); - return NULL; + return nullptr; } /* free the parser */ @@ -226,7 +226,7 @@ xml_data_node *xml_string_read(const char *string, xml_parse_options *opts) void xml_file_write(xml_data_node *node, core_file *file) { /* ensure this is a root node */ - if (node->name != NULL) + if (node->name != nullptr) return; /* output a simple header */ @@ -246,7 +246,7 @@ void xml_file_write(xml_data_node *node, core_file *file) void xml_file_free(xml_data_node *node) { /* ensure this is a root node */ - if (node->name != NULL) + if (node->name != nullptr) return; free_node_recursive(node); @@ -285,7 +285,7 @@ xml_data_node *xml_get_sibling(xml_data_node *node, const char *name) for ( ; node; node = node->next) if (strcmp(node->name, name) == 0) return node; - return NULL; + return nullptr; } @@ -301,15 +301,15 @@ xml_data_node *xml_find_matching_sibling(xml_data_node *node, const char *name, for ( ; node; node = node->next) { /* can pass NULL as a wildcard for the node name */ - if (name == NULL || strcmp(name, node->name) == 0) + if (name == nullptr || strcmp(name, node->name) == 0) { /* find a matching attribute */ xml_attribute_node *attr = xml_get_attribute(node, attribute); - if (attr != NULL && strcmp(attr->value, matchval) == 0) + if (attr != nullptr && strcmp(attr->value, matchval) == 0) return node; } } - return NULL; + return nullptr; } @@ -336,7 +336,7 @@ xml_data_node *xml_get_or_add_child(xml_data_node *node, const char *name, const /* find the child first */ child = xml_get_sibling(node->child, name); - if (child != NULL) + if (child != nullptr) return child; /* if not found, do a standard add child */ @@ -384,7 +384,7 @@ xml_attribute_node *xml_get_attribute(xml_data_node *node, const char *attribute for (anode = node->attribute; anode; anode = anode->next) if (strcmp(anode->name, attribute) == 0) return anode; - return NULL; + return nullptr; } @@ -409,11 +409,11 @@ const char *xml_get_attribute_string(xml_data_node *node, const char *attribute, int xml_get_attribute_int(xml_data_node *node, const char *attribute, int defvalue) { - const char *string = xml_get_attribute_string(node, attribute, NULL); + const char *string = xml_get_attribute_string(node, attribute, nullptr); int value; unsigned int uvalue; - if (string == NULL) + if (string == nullptr) return defvalue; if (string[0] == '$') return (sscanf(&string[1], "%X", &uvalue) == 1) ? uvalue : defvalue; @@ -432,9 +432,9 @@ int xml_get_attribute_int(xml_data_node *node, const char *attribute, int defval int xml_get_attribute_int_format(xml_data_node *node, const char *attribute) { - const char *string = xml_get_attribute_string(node, attribute, NULL); + const char *string = xml_get_attribute_string(node, attribute, nullptr); - if (string == NULL) + if (string == nullptr) return XML_INT_FORMAT_DECIMAL; if (string[0] == '$') return XML_INT_FORMAT_HEX_DOLLAR; @@ -466,10 +466,10 @@ int xml_get_attribute_int_format(xml_data_node *node, const char *attribute) float xml_get_attribute_float(xml_data_node *node, const char *attribute, float defvalue) { - const char *string = xml_get_attribute_string(node, attribute, NULL); + const char *string = xml_get_attribute_string(node, attribute, nullptr); float value; - if (string == NULL || sscanf(string, "%f", &value) != 1) + if (string == nullptr || sscanf(string, "%f", &value) != 1) return defvalue; return value; } @@ -500,9 +500,9 @@ xml_attribute_node *xml_set_attribute(xml_data_node *node, const char *name, con anode = xml_get_attribute(node, name); /* if we found it, free the old value and replace it */ - if (anode != NULL) + if (anode != nullptr) { - if (anode->value != NULL) + if (anode->value != nullptr) free((void *)anode->value); anode->value = copystring(value); } @@ -590,7 +590,7 @@ const char *xml_normalize_string(const char *string) static char buffer[1024]; char *d = &buffer[0]; - if (string != NULL) + if (string != nullptr) { while (*string) { @@ -650,7 +650,7 @@ static void *expat_malloc(size_t size) static void expat_free(void *ptr) { - if (ptr != NULL) + if (ptr != nullptr) free(&((UINT32 *)ptr)[-4]); } @@ -668,9 +668,9 @@ static void expat_free(void *ptr) static void *expat_realloc(void *ptr, size_t size) { void *newptr = expat_malloc(size); - if (newptr == NULL) - return NULL; - if (ptr != NULL) + if (newptr == nullptr) + return nullptr; + if (ptr != nullptr) { UINT32 oldsize = ((UINT32 *)ptr)[-4]; memcpy(newptr, ptr, oldsize); @@ -701,12 +701,12 @@ static int expat_setup_parser(xml_parse_info *parse_info, xml_parse_options *opt /* setup parse_info structure */ memset(parse_info, 0, sizeof(*parse_info)); - if (opts != NULL) + if (opts != nullptr) { parse_info->flags = opts->flags; - if (opts->error != NULL) + if (opts->error != nullptr) { - opts->error->error_message = NULL; + opts->error->error_message = nullptr; opts->error->error_line = 0; opts->error->error_column = 0; } @@ -714,7 +714,7 @@ static int expat_setup_parser(xml_parse_info *parse_info, xml_parse_options *opt /* create a root node */ parse_info->rootnode = xml_file_create(); - if (parse_info->rootnode == NULL) + if (parse_info->rootnode == nullptr) return FALSE; parse_info->curnode = parse_info->rootnode; @@ -722,8 +722,8 @@ static int expat_setup_parser(xml_parse_info *parse_info, xml_parse_options *opt memcallbacks.malloc_fcn = expat_malloc; memcallbacks.realloc_fcn = expat_realloc; memcallbacks.free_fcn = expat_free; - parse_info->parser = XML_ParserCreate_MM(NULL, &memcallbacks, NULL); - if (parse_info->parser == NULL) + parse_info->parser = XML_ParserCreate_MM(nullptr, &memcallbacks, nullptr); + if (parse_info->parser == nullptr) { free(parse_info->rootnode); return FALSE; @@ -735,7 +735,7 @@ static int expat_setup_parser(xml_parse_info *parse_info, xml_parse_options *opt XML_SetUserData(parse_info->parser, parse_info); /* optional parser initialization step */ - if (opts != NULL && opts->init_parser != NULL) + if (opts != nullptr && opts->init_parser != nullptr) (*opts->init_parser)(parse_info->parser); return TRUE; } @@ -764,8 +764,8 @@ static void expat_element_start(void *data, const XML_Char *name, const XML_Char int attr; /* add a new child node to the current node */ - newnode = add_child(*curnode, name, NULL); - if (newnode == NULL) + newnode = add_child(*curnode, name, nullptr); + if (newnode == nullptr) return; /* remember the line number */ @@ -807,14 +807,14 @@ static void expat_data(void *data, const XML_Char *s, int len) return; /* determine how much data we currently have */ - if ((*curnode)->value != NULL) + if ((*curnode)->value != nullptr) oldlen = (int)strlen((*curnode)->value); /* realloc */ newdata = (char *)malloc(oldlen + len + 1); - if (newdata == NULL) + if (newdata == nullptr) return; - if ((*curnode)->value != NULL) + if ((*curnode)->value != nullptr) { memcpy(newdata, (*curnode)->value, oldlen); free((void *)(*curnode)->value); @@ -850,7 +850,7 @@ static void expat_element_end(void *data, const XML_Char *name) /* strip leading/trailing spaces from the value data */ orig = (char *)(*curnode)->value; - if (orig != NULL && !(parse_info->flags & XML_PARSE_FLAG_WHITESPACE_SIGNIFICANT)) + if (orig != nullptr && !(parse_info->flags & XML_PARSE_FLAG_WHITESPACE_SIGNIFICANT)) { char *start = orig; char *end = start + strlen(start); @@ -867,7 +867,7 @@ static void expat_element_end(void *data, const XML_Char *name) if (start == end) { free(orig); - (*curnode)->value = NULL; + (*curnode)->value = nullptr; } /* otherwise, memmove the data */ @@ -911,27 +911,27 @@ static xml_data_node *add_child(xml_data_node *parent, const char *name, const c /* new element: create a new node */ node = (xml_data_node *)malloc(sizeof(*node)); - if (node == NULL) - return NULL; + if (node == nullptr) + return nullptr; /* initialize the members */ - node->next = NULL; + node->next = nullptr; node->parent = parent; - node->child = NULL; + node->child = nullptr; node->name = copystring_lower(name); - if (node->name == NULL) + if (node->name == nullptr) { free(node); - return NULL; + return nullptr; } node->value = copystring(value); - if (node->value == NULL && value != NULL) + if (node->value == nullptr && value != nullptr) { free((void *)node->name); free(node); - return NULL; + return nullptr; } - node->attribute = NULL; + node->attribute = nullptr; /* add us to the end of the list of siblings */ for (pnode = &parent->child; *pnode; pnode = &(*pnode)->next) ; @@ -964,23 +964,23 @@ static xml_attribute_node *add_attribute(xml_data_node *node, const char *name, /* allocate a new attribute node */ anode = (xml_attribute_node *)malloc(sizeof(*anode)); - if (anode == NULL) - return NULL; + if (anode == nullptr) + return nullptr; /* fill it in */ - anode->next = NULL; + anode->next = nullptr; anode->name = copystring_lower(name); - if (anode->name == NULL) + if (anode->name == nullptr) { free(anode); - return NULL; + return nullptr; } anode->value = copystring(value); - if (anode->value == NULL) + if (anode->value == nullptr) { free((void *)anode->name); free(anode); - return NULL; + return nullptr; } /* add us to the end of the list of attributes */ @@ -1024,7 +1024,7 @@ static void write_node_recursive(xml_data_node *node, int indent, core_file *fil core_fprintf(file, " %s=\"%s\"", anode->name, anode->value); /* if there are no children and no value, end the tag here */ - if (node->child == NULL && node->value == NULL) + if (node->child == nullptr && node->value == nullptr) core_fprintf(file, " />\n"); /* otherwise, close this tag and output more stuff */ @@ -1033,11 +1033,11 @@ static void write_node_recursive(xml_data_node *node, int indent, core_file *fil core_fprintf(file, ">\n"); /* if there is a value, output that here */ - if (node->value != NULL) + if (node->value != nullptr) core_fprintf(file, "%*s%s\n", indent + 4, "", node->value); /* loop over children and output them as well */ - if (node->child != NULL) + if (node->child != nullptr) { for (child = node->child; child; child = child->next) write_node_recursive(child, indent + 4, file); @@ -1068,18 +1068,18 @@ static void free_node_recursive(xml_data_node *node) xml_data_node *child, *nchild; /* free name/value */ - if (node->name != NULL) + if (node->name != nullptr) free((void *)node->name); - if (node->value != NULL) + if (node->value != nullptr) free((void *)node->value); /* free attributes */ for (anode = node->attribute; anode; anode = nanode) { /* free name/value */ - if (anode->name != NULL) + if (anode->name != nullptr) free((void *)anode->name); - if (anode->value != NULL) + if (anode->value != nullptr) free((void *)anode->value); /* note the next node and free this node */ diff --git a/src/lib/util/zippath.cpp b/src/lib/util/zippath.cpp index 36c9470ed92..84674eb1fe2 100644 --- a/src/lib/util/zippath.cpp +++ b/src/lib/util/zippath.cpp @@ -47,10 +47,10 @@ class zippath_directory public: zippath_directory() : returned_parent(false), - directory(NULL), + directory(nullptr), called_zip_first(false), - zipfile(NULL), - returned_dirlist(NULL) { } + zipfile(nullptr), + returned_dirlist(nullptr) { } /* common */ /** @brief true to returned parent. */ @@ -130,7 +130,7 @@ static void parse_parent_path(const char *path, int *beginpos, int *endpos) pos--; /* return endpos */ - if (endpos != NULL) + if (endpos != nullptr) *endpos = pos; /* now skip until we find a path separator */ @@ -138,7 +138,7 @@ static void parse_parent_path(const char *path, int *beginpos, int *endpos) pos--; /* return beginpos */ - if (beginpos != NULL) + if (beginpos != nullptr) *beginpos = pos; } @@ -162,7 +162,7 @@ static void parse_parent_path(const char *path, int *beginpos, int *endpos) std::string &zippath_parent(std::string &dst, const char *path) { int pos; - parse_parent_path(path, &pos, NULL); + parse_parent_path(path, &pos, nullptr); /* return the result */ if (pos >= 0) { @@ -316,7 +316,7 @@ static file_error create_core_file_from_zip(zip_file *zip, const zip_file_header void *ptr; ptr = malloc(header->uncompressed_length); - if (ptr == NULL) + if (ptr == nullptr) { filerr = FILERR_OUT_OF_MEMORY; goto done; @@ -334,7 +334,7 @@ static file_error create_core_file_from_zip(zip_file *zip, const zip_file_header goto done; done: - if (ptr != NULL) + if (ptr != nullptr) free(ptr); return filerr; } @@ -361,19 +361,19 @@ file_error zippath_fopen(const char *filename, UINT32 openflags, core_file *&fil { file_error filerr = FILERR_NOT_FOUND; zip_error ziperr; - zip_file *zip = NULL; + zip_file *zip = nullptr; const zip_file_header *header; osd_dir_entry_type entry_type; - char *alloc_fullpath = NULL; + char *alloc_fullpath = nullptr; int len; /* first, set up the two types of paths */ std::string mainpath(filename); std::string subpath; - file = NULL; + file = nullptr; /* loop through */ - while((file == NULL) && (mainpath.length() > 0) + while((file == nullptr) && (mainpath.length() > 0) && ((openflags == OPEN_FLAG_READ) || (subpath.length() == 0))) { /* is the mainpath a ZIP path? */ @@ -395,7 +395,7 @@ file_error zippath_fopen(const char *filename, UINT32 openflags, core_file *&fil else header = zip_file_first_file(zip); - if (header == NULL) + if (header == nullptr) { filerr = FILERR_NOT_FOUND; goto done; @@ -470,9 +470,9 @@ done: } } - if (zip != NULL) + if (zip != nullptr) zip_file_close(zip); - if (alloc_fullpath != NULL) + if (alloc_fullpath != nullptr) osd_free(alloc_fullpath); return filerr; } @@ -531,7 +531,7 @@ static int is_root(const char *path) static int is_7z_file(const char *path) { const char *s = strrchr(path, '.'); - return (s != NULL) && !core_stricmp(s, ".7z"); + return (s != nullptr) && !core_stricmp(s, ".7z"); } @@ -553,7 +553,7 @@ static int is_7z_file(const char *path) static int is_zip_file(const char *path) { const char *s = strrchr(path, '.'); - return (s != NULL) && !core_stricmp(s, ".zip"); + return (s != nullptr) && !core_stricmp(s, ".zip"); } @@ -678,12 +678,12 @@ static const zip_file_header *zippath_find_sub_path(zip_file *zipfile, const cha char c1, c2, last_char; const zip_file_header *header; - for (header = zip_file_first_file(zipfile); header != NULL; header = zip_file_next_file(zipfile)) + for (header = zip_file_first_file(zipfile); header != nullptr; header = zip_file_next_file(zipfile)) { /* special case */ - if (subpath == NULL) + if (subpath == nullptr) { - if (type != NULL) + if (type != nullptr) *type = ENTTYPE_FILE; return header; } @@ -700,22 +700,22 @@ static const zip_file_header *zippath_find_sub_path(zip_file *zipfile, const cha { if (c1 == '\0') { - if (type != NULL) + if (type != nullptr) *type = ENTTYPE_FILE; return header; } else if ((last_char == '/') || (c1 == '/')) { - if (type != NULL) + if (type != nullptr) *type = ENTTYPE_DIR; return header; } } } - if (type != NULL) + if (type != nullptr) *type = ENTTYPE_NONE; - return NULL; + return nullptr; } @@ -741,7 +741,7 @@ static const zip_file_header *zippath_find_sub_path(zip_file *zipfile, const cha static file_error zippath_resolve(const char *path, osd_dir_entry_type &entry_type, zip_file *&zipfile, std::string &newpath) { file_error err; - osd_directory_entry *current_entry = NULL; + osd_directory_entry *current_entry = nullptr; osd_dir_entry_type current_entry_type; int went_up = FALSE; int i; @@ -750,7 +750,7 @@ static file_error zippath_resolve(const char *path, osd_dir_entry_type &entry_ty /* be conservative */ entry_type = ENTTYPE_NONE; - zipfile = NULL; + zipfile = nullptr; std::string apath(path); std::string apath_trimmed; @@ -767,12 +767,12 @@ static file_error zippath_resolve(const char *path, osd_dir_entry_type &entry_ty current_entry = osd_stat(apath_trimmed.c_str()); /* did we find anything? */ - if (current_entry != NULL) + if (current_entry != nullptr) { /* get the entry type and free the stat entry */ current_entry_type = current_entry->type; osd_free(current_entry); - current_entry = NULL; + current_entry = nullptr; } else { @@ -849,7 +849,7 @@ file_error zippath_opendir(const char *path, zippath_directory **directory) file_error err; /* allocate a directory */ - zippath_directory *result = NULL; + zippath_directory *result = nullptr; try { result = new zippath_directory; @@ -873,11 +873,11 @@ file_error zippath_opendir(const char *path, zippath_directory **directory) } /* was the result a ZIP? */ - if (result->zipfile == NULL) + if (result->zipfile == nullptr) { /* a conventional directory */ result->directory = osd_opendir(path); - if (result->directory == NULL) + if (result->directory == nullptr) { err = FILERR_FAILURE; goto done; @@ -889,12 +889,12 @@ file_error zippath_opendir(const char *path, zippath_directory **directory) } done: - if ((directory == NULL || err != FILERR_NONE) && result != NULL) + if ((directory == nullptr || err != FILERR_NONE) && result != nullptr) { zippath_closedir(result); - result = NULL; + result = nullptr; } - if (directory != NULL) + if (directory != nullptr) *directory = result; return err; } @@ -914,13 +914,13 @@ done: void zippath_closedir(zippath_directory *directory) { - if (directory->directory != NULL) + if (directory->directory != nullptr) osd_closedir(directory->directory); - if (directory->zipfile != NULL) + if (directory->zipfile != nullptr) zip_file_close(directory->zipfile); - while (directory->returned_dirlist != NULL) + while (directory->returned_dirlist != nullptr) { zippath_returned_directory *dirlist = directory->returned_dirlist; directory->returned_dirlist = directory->returned_dirlist->next; @@ -950,7 +950,7 @@ void zippath_closedir(zippath_directory *directory) static const char *get_relative_path(zippath_directory *directory, const zip_file_header *header) { - const char *result = NULL; + const char *result = nullptr; int len = directory->zipprefix.length(); if ((len <= strlen(header->filename)) @@ -981,7 +981,7 @@ static const char *get_relative_path(zippath_directory *directory, const zip_fil const osd_directory_entry *zippath_readdir(zippath_directory *directory) { - const osd_directory_entry *result = NULL; + const osd_directory_entry *result = nullptr; const zip_file_header *header; const char *relpath; const char *separator; @@ -997,17 +997,17 @@ const osd_directory_entry *zippath_readdir(zippath_directory *directory) directory->returned_entry.type = ENTTYPE_DIR; result = &directory->returned_entry; } - else if (directory->directory != NULL) + else if (directory->directory != nullptr) { /* a normal directory read */ do { result = osd_readdir(directory->directory); } - while((result != NULL) && (!strcmp(result->name, ".") || !strcmp(result->name, ".."))); + while((result != nullptr) && (!strcmp(result->name, ".") || !strcmp(result->name, ".."))); /* special case - is this entry a ZIP file? if so we need to return it as a "directory" */ - if ((result != NULL) && is_zip_file(result->name)) + if ((result != nullptr) && is_zip_file(result->name)) { /* copy; but change the entry type */ directory->returned_entry = *result; @@ -1015,7 +1015,7 @@ const osd_directory_entry *zippath_readdir(zippath_directory *directory) result = &directory->returned_entry; } } - else if (directory->zipfile != NULL) + else if (directory->zipfile != nullptr) { do { @@ -1027,27 +1027,27 @@ const osd_directory_entry *zippath_readdir(zippath_directory *directory) else header = zip_file_next_file(directory->zipfile); directory->called_zip_first = true; - relpath = NULL; + relpath = nullptr; } - while((header != NULL) && ((relpath = get_relative_path(directory, header)) == NULL)); + while((header != nullptr) && ((relpath = get_relative_path(directory, header)) == nullptr)); - if (relpath != NULL) + if (relpath != nullptr) { /* we've found a ZIP entry; but this may be an entry deep within the target directory */ for (s = relpath; *s && !is_zip_file_separator(*s); s++) ; - separator = *s ? s : NULL; + separator = *s ? s : nullptr; - if (separator != NULL) + if (separator != nullptr) { /* a nested entry; loop through returned_dirlist to see if we've returned the parent directory */ - for (rdent = directory->returned_dirlist; rdent != NULL; rdent = rdent->next) + for (rdent = directory->returned_dirlist; rdent != nullptr; rdent = rdent->next) { if (!core_strnicmp(rdent->name.c_str(), relpath, separator - relpath)) break; } - if (rdent == NULL) + if (rdent == nullptr) { /* we've found a new directory; add this to returned_dirlist */ rdent = new zippath_returned_directory; @@ -1073,7 +1073,7 @@ const osd_directory_entry *zippath_readdir(zippath_directory *directory) } } } - while((relpath != NULL) && (result == NULL)); + while((relpath != nullptr) && (result == nullptr)); } return result; } @@ -1097,5 +1097,5 @@ const osd_directory_entry *zippath_readdir(zippath_directory *directory) int zippath_is_zip(zippath_directory *directory) { - return directory->zipfile != NULL; + return directory->zipfile != nullptr; } |