From bfd9350bedaa5147eafaea45477d0481dcfb7a52 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 24 Feb 2013 15:49:06 +0000 Subject: [PATCH] Changed some types from int to size_t where appropriate. Fixed a CoreMidi build problem in 64-bit mode. --- .../Source/Utility/jucer_FileHelpers.cpp | 6 ++-- .../Source/demos/InterprocessCommsDemo.cpp | 2 +- .../effects/juce_LagrangeInterpolator.cpp | 6 ++-- .../juce_audio_basics/midi/juce_MidiFile.cpp | 4 +-- .../midi/juce_MidiMessage.cpp | 2 +- .../juce_audio_basics/midi/juce_MidiMessage.h | 2 +- .../native/juce_mac_CoreMidi.cpp | 30 +++++++++---------- .../native/juce_win32_AudioCDReader.cpp | 2 +- .../codecs/juce_AiffAudioFormat.cpp | 6 ++-- .../codecs/juce_FlacAudioFormat.cpp | 2 +- .../codecs/juce_WavAudioFormat.cpp | 8 ++--- .../RTAS/juce_RTAS_Wrapper.cpp | 4 +-- .../VST/juce_VST_Wrapper.cpp | 4 +-- .../format_types/juce_VSTPluginFormat.cpp | 2 +- .../processors/juce_AudioProcessor.cpp | 12 ++++---- modules/juce_core/containers/juce_Variant.cpp | 6 ++-- modules/juce_core/files/juce_File.cpp | 12 ++++---- modules/juce_core/files/juce_File.h | 4 +-- .../juce_core/files/juce_FileOutputStream.cpp | 20 ++++++------- .../juce_core/files/juce_FileOutputStream.h | 10 +++---- modules/juce_core/json/juce_JSON.cpp | 2 +- .../juce_core/native/juce_posix_SharedCode.h | 6 ++-- modules/juce_core/native/juce_win32_Files.cpp | 8 ++--- modules/juce_core/network/juce_URL.cpp | 4 +-- .../streams/juce_MemoryOutputStream.cpp | 21 ++++++------- .../streams/juce_MemoryOutputStream.h | 6 ++-- .../juce_core/streams/juce_OutputStream.cpp | 12 ++++---- modules/juce_core/streams/juce_OutputStream.h | 6 ++-- .../juce_core/text/juce_CharPointer_ASCII.h | 2 +- .../juce_core/text/juce_CharPointer_UTF16.h | 2 +- .../juce_core/text/juce_CharPointer_UTF32.h | 2 +- .../juce_core/text/juce_CharPointer_UTF8.h | 2 +- .../juce_core/text/juce_CharacterFunctions.h | 8 +++-- modules/juce_core/text/juce_String.cpp | 18 +++++------ modules/juce_core/text/juce_String.h | 8 ++--- .../juce_core/threads/juce_ChildProcess.cpp | 2 +- .../zip/juce_GZIPCompressorOutputStream.cpp | 20 ++++++------- .../zip/juce_GZIPCompressorOutputStream.h | 2 +- modules/juce_core/zip/juce_ZipFile.cpp | 2 +- .../image_formats/juce_JPEGLoader.cpp | 4 +-- .../image_formats/juce_PNGLoader.cpp | 2 +- .../native/juce_linux_Clipboard.cpp | 5 ++-- .../native/juce_win32_DragAndDrop.cpp | 4 +-- .../native/juce_win32_FileChooser.cpp | 10 +++---- .../native/juce_win32_Windowing.cpp | 2 +- .../code_editor/juce_CodeDocument.cpp | 2 +- 46 files changed, 155 insertions(+), 151 deletions(-) diff --git a/extras/Introjucer/Source/Utility/jucer_FileHelpers.cpp b/extras/Introjucer/Source/Utility/jucer_FileHelpers.cpp index af99bd087a..1e224c920d 100644 --- a/extras/Introjucer/Source/Utility/jucer_FileHelpers.cpp +++ b/extras/Introjucer/Source/Utility/jucer_FileHelpers.cpp @@ -30,11 +30,11 @@ //============================================================================== namespace FileHelpers { - static int64 calculateMemoryHashCode (const void* data, const int numBytes) + static int64 calculateMemoryHashCode (const void* data, const size_t numBytes) { int64 t = 0; - for (int i = 0; i < numBytes; ++i) + for (size_t i = 0; i < numBytes; ++i) t = t * 65599 + static_cast (data)[i]; return t; @@ -68,7 +68,7 @@ namespace FileHelpers return stream != nullptr ? calculateStreamHashCode (*stream) : 0; } - bool overwriteFileWithNewDataIfDifferent (const File& file, const void* data, int numBytes) + bool overwriteFileWithNewDataIfDifferent (const File& file, const void* data, size_t numBytes) { if (file.getSize() == numBytes && calculateMemoryHashCode (data, numBytes) == calculateFileHashCode (file)) diff --git a/extras/JuceDemo/Source/demos/InterprocessCommsDemo.cpp b/extras/JuceDemo/Source/demos/InterprocessCommsDemo.cpp index a21ac61c4c..8d4ab3a6ed 100644 --- a/extras/JuceDemo/Source/demos/InterprocessCommsDemo.cpp +++ b/extras/JuceDemo/Source/demos/InterprocessCommsDemo.cpp @@ -112,7 +112,7 @@ public: // The send button has been pressed, so write out the contents of the // text box to the socket or pipe, depending on which is active. const String text (sendText.getText()); - MemoryBlock messageData (text.toUTF8(), (size_t) text.getNumBytesAsUTF8()); + MemoryBlock messageData (text.toUTF8(), text.getNumBytesAsUTF8()); for (int i = activeConnections.size(); --i >= 0;) { diff --git a/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.cpp b/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.cpp index 991f4739c3..63e8c5217a 100644 --- a/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.cpp +++ b/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.cpp @@ -80,7 +80,7 @@ void LagrangeInterpolator::reset() noexcept } int LagrangeInterpolator::process (const double actualRatio, const float* in, - float* out, const int numOut) noexcept + float* out, const int numOut) noexcept { if (actualRatio == 1.0) { @@ -132,7 +132,7 @@ int LagrangeInterpolator::process (const double actualRatio, const float* in, } subSamplePos = pos; - return in - originalIn; + return (int) (in - originalIn); } int LagrangeInterpolator::processAdding (const double actualRatio, const float* in, @@ -197,5 +197,5 @@ int LagrangeInterpolator::processAdding (const double actualRatio, const float* } subSamplePos = pos; - return in - originalIn; + return (int) (in - originalIn); } diff --git a/modules/juce_audio_basics/midi/juce_MidiFile.cpp b/modules/juce_audio_basics/midi/juce_MidiFile.cpp index e7909b7e15..2e6768c1cc 100644 --- a/modules/juce_audio_basics/midi/juce_MidiFile.cpp +++ b/modules/juce_audio_basics/midi/juce_MidiFile.cpp @@ -408,7 +408,7 @@ void MidiFile::writeTrack (OutputStream& mainOut, const int trackNum) MidiFileHelpers::writeVariableLengthInt (out, (uint32) dataSize); } - out.write (data, dataSize); + out.write (data, (size_t) dataSize); lastStatusByte = statusByte; } } @@ -416,7 +416,7 @@ void MidiFile::writeTrack (OutputStream& mainOut, const int trackNum) { out.writeByte (0); // (tick delta) const MidiMessage m (MidiMessage::endOfTrack()); - out.write (m.getRawData(), m.getRawDataSize()); + out.write (m.getRawData(), (size_t) m.getRawDataSize()); } mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk")); diff --git a/modules/juce_audio_basics/midi/juce_MidiMessage.cpp b/modules/juce_audio_basics/midi/juce_MidiMessage.cpp index 035276c14a..f97bcf5373 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessage.cpp +++ b/modules/juce_audio_basics/midi/juce_MidiMessage.cpp @@ -620,7 +620,7 @@ bool MidiMessage::isSysEx() const noexcept return *data == 0xf0; } -MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData, const int dataSize) +MidiMessage MidiMessage::createSysExMessage (const void* sysexData, const int dataSize) { HeapBlock m ((size_t) dataSize + 2); diff --git a/modules/juce_audio_basics/midi/juce_MidiMessage.h b/modules/juce_audio_basics/midi/juce_MidiMessage.h index f39138bbbb..75c6c7c473 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessage.h +++ b/modules/juce_audio_basics/midi/juce_MidiMessage.h @@ -846,7 +846,7 @@ public: The data passed in is wrapped with header and tail bytes of 0xf0 and 0xf7. */ - static MidiMessage createSysExMessage (const uint8* sysexData, + static MidiMessage createSysExMessage (const void* sysexData, int dataSize); diff --git a/modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp b/modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp index 8d966ce003..2a8b80b903 100644 --- a/modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp +++ b/modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp @@ -65,20 +65,20 @@ namespace CoreMidiHelpers { String result (getMidiObjectName (endpoint)); - MIDIEntityRef entity = nullptr; + MIDIEntityRef entity = 0; // NB: don't attempt to use nullptr for refs - it fails in some types of build. MIDIEndpointGetEntity (endpoint, &entity); - if (entity == nullptr) + if (entity == 0) return result; // probably virtual if (result.isEmpty()) result = getMidiObjectName (entity); // endpoint name is empty - try the entity // now consider the device's name - MIDIDeviceRef device = nullptr; + MIDIDeviceRef device = 0; MIDIEntityGetDevice (entity, &device); - if (device != nullptr) + if (device != 0) { const String deviceName (getMidiObjectName (device)); @@ -174,7 +174,7 @@ namespace CoreMidiHelpers : MIDIGetDestination (i); String name; - if (dest != nullptr) + if (dest != 0) name = getConnectedEndpointName (dest); if (name.isEmpty()) @@ -201,9 +201,9 @@ namespace CoreMidiHelpers static MIDIClientRef getGlobalMidiClient() { - static MIDIClientRef globalMidiClient = nullptr; + static MIDIClientRef globalMidiClient = 0; - if (globalMidiClient == nullptr) + if (globalMidiClient == 0) { // Since OSX 10.6, the MIDIClientCreate function will only work // correctly when called from the message thread! @@ -228,16 +228,16 @@ namespace CoreMidiHelpers ~MidiPortAndEndpoint() { - if (port != nullptr) + if (port != 0) MIDIPortDispose (port); - if (port == nullptr && endPoint != nullptr) // if port == nullptr, it means we created the endpoint, so it's safe to delete it + if (port == 0 && endPoint != 0) // if port == nullptr, it means we created the endpoint, so it's safe to delete it MIDIEndpointDispose (endPoint); } void send (const MIDIPacketList* const packets) { - if (port != nullptr) + if (port != 0) MIDISend (port, endPoint, packets); else MIDIReceived (endPoint, packets); @@ -269,7 +269,7 @@ namespace CoreMidiHelpers activeCallbacks.removeFirstMatchingValue (this); } - if (portAndEndpoint != nullptr && portAndEndpoint->port != nullptr) + if (portAndEndpoint != 0 && portAndEndpoint->port != 0) CHECK_ERROR (MIDIPortDisconnectSource (portAndEndpoint->port, portAndEndpoint->endPoint)); } @@ -325,7 +325,7 @@ MidiOutput* MidiOutput::openDevice (int index) MIDIClientRef client = CoreMidiHelpers::getGlobalMidiClient(); MIDIPortRef port; - if (client != nullptr && CHECK_ERROR (MIDIOutputPortCreate (client, pname, &port))) + if (client != 0 && CHECK_ERROR (MIDIOutputPortCreate (client, pname, &port))) { mo = new MidiOutput(); mo->internal = new CoreMidiHelpers::MidiPortAndEndpoint (port, endPoint); @@ -346,10 +346,10 @@ MidiOutput* MidiOutput::createNewDevice (const String& deviceName) MIDIEndpointRef endPoint; CFStringRef name = deviceName.toCFString(); - if (client != nullptr && CHECK_ERROR (MIDISourceCreate (client, name, &endPoint))) + if (client != 0 && CHECK_ERROR (MIDISourceCreate (client, name, &endPoint))) { mo = new MidiOutput(); - mo->internal = new CoreMidiHelpers::MidiPortAndEndpoint (nullptr, endPoint); + mo->internal = new CoreMidiHelpers::MidiPortAndEndpoint (0, endPoint); } CFRelease (name); @@ -489,7 +489,7 @@ MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallba if (CHECK_ERROR (MIDIDestinationCreate (client, name, midiInputProc, mpc, &endPoint))) { - mpc->portAndEndpoint = new MidiPortAndEndpoint (nullptr, endPoint); + mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint); mi = new MidiInput (deviceName); mpc->input = mi; diff --git a/modules/juce_audio_devices/native/juce_win32_AudioCDReader.cpp b/modules/juce_audio_devices/native/juce_win32_AudioCDReader.cpp index 4f8a46af53..ff022e23cf 100644 --- a/modules/juce_audio_devices/native/juce_win32_AudioCDReader.cpp +++ b/modules/juce_audio_devices/native/juce_win32_AudioCDReader.cpp @@ -1069,7 +1069,7 @@ bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int sta } else { - const int framesInBuffer = buffer.getSize() / bytesPerFrame; + const int framesInBuffer = (int) (buffer.getSize() / bytesPerFrame); const int frameNeeded = (int) (startSampleInFile / samplesPerFrame); if (firstFrameInBuffer + framesInBuffer != frameNeeded) diff --git a/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp index 95eb147ccf..62b5e75149 100644 --- a/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp @@ -193,7 +193,7 @@ namespace AiffFileHelpers out.writeShortBigEndian ((short) identifier); out.writeIntBigEndian (offset); - const int labelLength = jmin (254, label.getNumBytesAsUTF8()); // seems to need null terminator even though it's a pstring + const size_t labelLength = jmin ((size_t) 254, label.getNumBytesAsUTF8()); // seems to need null terminator even though it's a pstring out.writeByte ((char) labelLength + 1); out.write (label.toUTF8(), labelLength); out.writeByte (0); @@ -226,7 +226,7 @@ namespace AiffFileHelpers const String comment (values.getValue (prefix + "Text", String::empty)); - const int commentLength = jmin (comment.getNumBytesAsUTF8(), 65534); + const size_t commentLength = jmin (comment.getNumBytesAsUTF8(), (size_t) 65534); out.writeShortBigEndian ((short) commentLength + 1); out.write (comment.toUTF8(), commentLength); out.writeByte (0); @@ -527,7 +527,7 @@ public: } if (bytesWritten + bytes >= (size_t) 0xfff00000 - || ! output->write (tempBlock.getData(), (int) bytes)) + || ! output->write (tempBlock.getData(), bytes)) { // failed to write to disk, so let's try writing the header. // If it's just run out of disk space, then if it does manage diff --git a/modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp index f60bc0cdd2..bcc6f36430 100644 --- a/modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp @@ -391,7 +391,7 @@ public: bool writeData (const void* const data, const int size) const { - return output->write (data, size); + return output->write (data, (size_t) size); } static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes) diff --git a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp index 45aa83da17..2e4cb88b85 100644 --- a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp @@ -98,7 +98,7 @@ namespace WavFileHelpers static MemoryBlock createFrom (const StringPairArray& values) { - const size_t sizeNeeded = sizeof (BWAVChunk) + (size_t) values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8(); + const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8(); MemoryBlock data ((sizeNeeded + 3) & ~3); data.fillWith (0); @@ -401,7 +401,7 @@ namespace WavFileHelpers const int chunkType, MemoryOutputStream& out) { const String label (values.getValue (prefix + "Text", prefix)); - const int labelLength = label.getNumBytesAsUTF8() + 1; + const int labelLength = (int) label.getNumBytesAsUTF8() + 1; const int chunkLength = 4 + labelLength + (labelLength & 1); out.writeInt (chunkType); @@ -417,7 +417,7 @@ namespace WavFileHelpers { const String text (values.getValue (prefix + "Text", prefix)); - const int textLength = text.getNumBytesAsUTF8() + 1; // include null terminator + const int textLength = (int) text.getNumBytesAsUTF8() + 1; // include null terminator int chunkLength = textLength + 20 + (textLength & 1); out.writeInt (chunkName ("ltxt")); @@ -832,7 +832,7 @@ public: default: jassertfalse; break; } - if (! output->write (tempBlock.getData(), (int) bytes)) + if (! output->write (tempBlock.getData(), bytes)) { // failed to write to disk, so let's try writing the header. // If it's just run out of disk space, then if it does manage diff --git a/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp b/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp index e23c179518..4199b8ea18 100644 --- a/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp @@ -848,7 +848,7 @@ private: // Pro-tools expects all your parameters to have valid names! jassert (juceFilter->getParameterName (index).isNotEmpty()); - juceFilter->getParameterName (index).copyToUTF8 (name, maxLength); + juceFilter->getParameterName (index).copyToUTF8 (name, (size_t) maxLength); } long GetPriority() const { return kFicCooperativeTaskPriority; } @@ -863,7 +863,7 @@ private: void GetValueString (char* valueString, int maxLength, long value) const { - juceFilter->getParameterText (index).copyToUTF8 (valueString, maxLength); + juceFilter->getParameterText (index).copyToUTF8 (valueString, (size_t) maxLength); } Cmn_Bool IsAutomatable() const diff --git a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp index 2905c7414f..0ac03b5a74 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -436,8 +436,8 @@ public: static void setPinProperties (VstPinProperties& properties, const String& name, VstSpeakerArrangementType type, const bool isPair) { - name.copyToUTF8 (properties.label, kVstMaxLabelLen - 1); - name.copyToUTF8 (properties.shortLabel, kVstMaxShortLabelLen - 1); + name.copyToUTF8 (properties.label, (size_t) (kVstMaxLabelLen - 1)); + name.copyToUTF8 (properties.shortLabel, (size_t) (kVstMaxShortLabelLen - 1)); if (type != kSpeakerArrEmpty) { diff --git a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp index 0db217e8ec..bc5e5b1e85 100644 --- a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp @@ -1393,7 +1393,7 @@ public: if (JUCEApplication* app = JUCEApplication::getInstance()) hostName = app->getApplicationName(); - hostName.copyToUTF8 ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1); + hostName.copyToUTF8 ((char*) ptr, (size_t) jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1); break; } diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessor.cpp b/modules/juce_audio_processors/processors/juce_AudioProcessor.cpp index 333bf1b3d9..bb7ac74be5 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessor.cpp +++ b/modules/juce_audio_processors/processors/juce_AudioProcessor.cpp @@ -236,15 +236,15 @@ const uint32 magicXmlNumber = 0x21324356; void AudioProcessor::copyXmlToBinary (const XmlElement& xml, juce::MemoryBlock& destData) { const String xmlString (xml.createDocument (String::empty, true, false)); - const int stringLength = xmlString.getNumBytesAsUTF8(); + const size_t stringLength = xmlString.getNumBytesAsUTF8(); - destData.setSize ((size_t) stringLength + 9); + destData.setSize (stringLength + 9); - char* const d = static_cast (destData.getData()); - *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber); - *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength); + uint32* const d = static_cast (destData.getData()); + d[0] = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber); + d[1] = ByteOrder::swapIfBigEndian ((const uint32) stringLength); - xmlString.copyToUTF8 (d + 8, stringLength + 1); + xmlString.copyToUTF8 ((CharPointer_UTF8::CharType*) (d + 2), stringLength + 1); } XmlElement* AudioProcessor::getXmlFromBinary (const void* data, const int sizeInBytes) diff --git a/modules/juce_core/containers/juce_Variant.cpp b/modules/juce_core/containers/juce_Variant.cpp index 6ecc85144a..23d016aef8 100644 --- a/modules/juce_core/containers/juce_Variant.cpp +++ b/modules/juce_core/containers/juce_Variant.cpp @@ -211,10 +211,10 @@ public: void writeToStream (const ValueUnion& data, OutputStream& output) const { const String* const s = getString (data); - const int len = s->getNumBytesAsUTF8() + 1; - HeapBlock temp ((size_t) len); + const size_t len = s->getNumBytesAsUTF8() + 1; + HeapBlock temp (len); s->copyToUTF8 (temp, len); - output.writeCompressedInt (len + 1); + output.writeCompressedInt ((int) (len + 1)); output.writeByte (varMarker_String); output.write (temp, len); } diff --git a/modules/juce_core/files/juce_File.cpp b/modules/juce_core/files/juce_File.cpp index b97d99f94a..567810efb1 100644 --- a/modules/juce_core/files/juce_File.cpp +++ b/modules/juce_core/files/juce_File.cpp @@ -672,9 +672,11 @@ FileOutputStream* File::createOutputStream (const int bufferSize) const //============================================================================== bool File::appendData (const void* const dataToAppend, - const int numberOfBytes) const + const size_t numberOfBytes) const { - if (numberOfBytes <= 0) + jassert (((ssize_t) numberOfBytes) >= 0); + + if (numberOfBytes == 0) return true; FileOutputStream out (*this, 8192); @@ -682,11 +684,9 @@ bool File::appendData (const void* const dataToAppend, } bool File::replaceWithData (const void* const dataToWrite, - const int numberOfBytes) const + const size_t numberOfBytes) const { - jassert (numberOfBytes >= 0); // a negative number of bytes?? - - if (numberOfBytes <= 0) + if (numberOfBytes == 0) return deleteFile(); TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile); diff --git a/modules/juce_core/files/juce_File.h b/modules/juce_core/files/juce_File.h index 879d1c22ab..25bd0f1013 100644 --- a/modules/juce_core/files/juce_File.h +++ b/modules/juce_core/files/juce_File.h @@ -623,7 +623,7 @@ public: @returns false if it can't write to the file for some reason */ bool appendData (const void* dataToAppend, - int numberOfBytes) const; + size_t numberOfBytes) const; /** Replaces this file's contents with a given block of data. @@ -640,7 +640,7 @@ public: @see appendText */ bool replaceWithData (const void* dataToWrite, - int numberOfBytes) const; + size_t numberOfBytes) const; /** Appends a string to the end of the file. diff --git a/modules/juce_core/files/juce_FileOutputStream.cpp b/modules/juce_core/files/juce_FileOutputStream.cpp index 5409b1dc3f..b8f1be5e4f 100644 --- a/modules/juce_core/files/juce_FileOutputStream.cpp +++ b/modules/juce_core/files/juce_FileOutputStream.cpp @@ -67,7 +67,7 @@ bool FileOutputStream::flushBuffer() if (bytesInBuffer > 0) { - ok = (writeInternal (buffer, bytesInBuffer) == bytesInBuffer); + ok = (writeInternal (buffer, bytesInBuffer) == (ssize_t) bytesInBuffer); bytesInBuffer = 0; } @@ -80,13 +80,13 @@ void FileOutputStream::flush() flushInternal(); } -bool FileOutputStream::write (const void* const src, const int numBytes) +bool FileOutputStream::write (const void* const src, const size_t numBytes) { - jassert (src != nullptr && numBytes >= 0); + jassert (src != nullptr && ((ssize_t) numBytes) >= 0); if (bytesInBuffer + numBytes < bufferSize) { - memcpy (buffer + bytesInBuffer, src, (size_t) numBytes); + memcpy (buffer + bytesInBuffer, src, numBytes); bytesInBuffer += numBytes; currentPosition += numBytes; } @@ -97,32 +97,32 @@ bool FileOutputStream::write (const void* const src, const int numBytes) if (numBytes < bufferSize) { - memcpy (buffer + bytesInBuffer, src, (size_t) numBytes); + memcpy (buffer + bytesInBuffer, src, numBytes); bytesInBuffer += numBytes; currentPosition += numBytes; } else { - const int bytesWritten = writeInternal (src, numBytes); + const ssize_t bytesWritten = writeInternal (src, numBytes); if (bytesWritten < 0) return false; currentPosition += bytesWritten; - return bytesWritten == numBytes; + return bytesWritten == (ssize_t) numBytes; } } return true; } -void FileOutputStream::writeRepeatedByte (uint8 byte, int numBytes) +void FileOutputStream::writeRepeatedByte (uint8 byte, size_t numBytes) { - jassert (numBytes >= 0); + jassert (((ssize_t) numBytes) >= 0); if (bytesInBuffer + numBytes < bufferSize) { - memset (buffer + bytesInBuffer, byte, (size_t) numBytes); + memset (buffer + bytesInBuffer, byte, numBytes); bytesInBuffer += numBytes; currentPosition += numBytes; } diff --git a/modules/juce_core/files/juce_FileOutputStream.h b/modules/juce_core/files/juce_FileOutputStream.h index c1fea7f6a6..d6188c7979 100644 --- a/modules/juce_core/files/juce_FileOutputStream.h +++ b/modules/juce_core/files/juce_FileOutputStream.h @@ -90,8 +90,8 @@ public: void flush(); int64 getPosition(); bool setPosition (int64 pos); - bool write (const void* data, int numBytes); - void writeRepeatedByte (uint8 byte, int numTimesToRepeat); + bool write (const void* data, size_t numBytes); + void writeRepeatedByte (uint8 byte, size_t numTimesToRepeat); private: @@ -100,15 +100,15 @@ private: void* fileHandle; Result status; int64 currentPosition; - int bufferSize, bytesInBuffer; + size_t bufferSize, bytesInBuffer; HeapBlock buffer; void openHandle(); void closeHandle(); void flushInternal(); bool flushBuffer(); - int64 setPositionInternal (int64 newPosition); - int writeInternal (const void* data, int numBytes); + int64 setPositionInternal (int64); + ssize_t writeInternal (const void*, size_t); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileOutputStream) }; diff --git a/modules/juce_core/json/juce_JSON.cpp b/modules/juce_core/json/juce_JSON.cpp index e805c3abc2..80bf40e1f5 100644 --- a/modules/juce_core/json/juce_JSON.cpp +++ b/modules/juce_core/json/juce_JSON.cpp @@ -400,7 +400,7 @@ private: static void writeSpaces (OutputStream& out, int numSpaces) { - out.writeRepeatedByte (' ', numSpaces); + out.writeRepeatedByte (' ', (size_t) numSpaces); } static void writeArray (OutputStream& out, const Array& array, diff --git a/modules/juce_core/native/juce_posix_SharedCode.h b/modules/juce_core/native/juce_posix_SharedCode.h index 62e129f0a8..afe2b7c453 100644 --- a/modules/juce_core/native/juce_posix_SharedCode.h +++ b/modules/juce_core/native/juce_posix_SharedCode.h @@ -494,19 +494,19 @@ void FileOutputStream::closeHandle() } } -int FileOutputStream::writeInternal (const void* const data, const int numBytes) +ssize_t FileOutputStream::writeInternal (const void* const data, const size_t numBytes) { ssize_t result = 0; if (fileHandle != 0) { - result = ::write (getFD (fileHandle), data, (size_t) numBytes); + result = ::write (getFD (fileHandle), data, numBytes); if (result == -1) status = getResultForErrno(); } - return (int) result; + return result; } void FileOutputStream::flushInternal() diff --git a/modules/juce_core/native/juce_win32_Files.cpp b/modules/juce_core/native/juce_win32_Files.cpp index 509b9eaf17..996cfe554d 100644 --- a/modules/juce_core/native/juce_win32_Files.cpp +++ b/modules/juce_core/native/juce_win32_Files.cpp @@ -59,7 +59,7 @@ namespace WindowsFileHelpers const size_t numBytes = CharPointer_UTF16::getBytesRequiredFor (path.getCharPointer()) + 4; HeapBlock pathCopy; pathCopy.calloc (numBytes, 1); - path.copyToUTF16 (pathCopy, (int) numBytes); + path.copyToUTF16 (pathCopy, numBytes); if (PathStripToRoot (pathCopy)) path = static_cast (pathCopy); @@ -184,7 +184,7 @@ bool File::moveToTrash() const const size_t numBytes = CharPointer_UTF16::getBytesRequiredFor (fullPath.getCharPointer()) + 8; HeapBlock doubleNullTermPath; doubleNullTermPath.calloc (numBytes, 1); - fullPath.copyToUTF16 (doubleNullTermPath, (int) numBytes); + fullPath.copyToUTF16 (doubleNullTermPath, numBytes); SHFILEOPSTRUCT fos = { 0 }; fos.wFunc = FO_DELETE; @@ -278,7 +278,7 @@ void FileOutputStream::closeHandle() CloseHandle ((HANDLE) fileHandle); } -int FileOutputStream::writeInternal (const void* buffer, int numBytes) +ssize_t FileOutputStream::writeInternal (const void* buffer, size_t numBytes) { if (fileHandle != nullptr) { @@ -286,7 +286,7 @@ int FileOutputStream::writeInternal (const void* buffer, int numBytes) if (! WriteFile ((HANDLE) fileHandle, buffer, (DWORD) numBytes, &actualNum, 0)) status = WindowsFileHelpers::getResultForLastError(); - return (int) actualNum; + return (ssize_t) actualNum; } return 0; diff --git a/modules/juce_core/network/juce_URL.cpp b/modules/juce_core/network/juce_URL.cpp index afc5fc44a1..1efeefac6b 100644 --- a/modules/juce_core/network/juce_URL.cpp +++ b/modules/juce_core/network/juce_URL.cpp @@ -415,7 +415,7 @@ String URL::removeEscapeChars (const String& s) // We need to operate on the string as raw UTF8 chars, and then recombine them into unicode // after all the replacements have been made, so that multi-byte chars are handled. - Array utf8 (result.toUTF8().getAddress(), result.getNumBytesAsUTF8()); + Array utf8 (result.toUTF8().getAddress(), (int) result.getNumBytesAsUTF8()); for (int i = 0; i < utf8.size(); ++i) { @@ -440,7 +440,7 @@ String URL::addEscapeChars (const String& s, const bool isParameter) const CharPointer_UTF8 legalChars (isParameter ? "_-.*!'()" : ",$_-.*!'()"); - Array utf8 (s.toUTF8().getAddress(), s.getNumBytesAsUTF8()); + Array utf8 (s.toUTF8().getAddress(), (int) s.getNumBytesAsUTF8()); for (int i = 0; i < utf8.size(); ++i) { diff --git a/modules/juce_core/streams/juce_MemoryOutputStream.cpp b/modules/juce_core/streams/juce_MemoryOutputStream.cpp index 713ba64aec..9017c8b0c9 100644 --- a/modules/juce_core/streams/juce_MemoryOutputStream.cpp +++ b/modules/juce_core/streams/juce_MemoryOutputStream.cpp @@ -68,37 +68,37 @@ void MemoryOutputStream::reset() noexcept size = 0; } -void MemoryOutputStream::prepareToWrite (int numBytes) +void MemoryOutputStream::prepareToWrite (size_t numBytes) { jassert (numBytes >= 0); - size_t storageNeeded = position + (size_t) numBytes; + size_t storageNeeded = position + numBytes; if (storageNeeded >= data.getSize()) data.ensureSize ((storageNeeded + jmin (storageNeeded / 2, (size_t) (1024 * 1024)) + 32) & ~31u); } -bool MemoryOutputStream::write (const void* const buffer, int howMany) +bool MemoryOutputStream::write (const void* const buffer, size_t howMany) { - jassert (buffer != nullptr && howMany >= 0); + jassert (buffer != nullptr && ((ssize_t) howMany) >= 0); if (howMany > 0) { prepareToWrite (howMany); - memcpy (static_cast (data.getData()) + position, buffer, (size_t) howMany); - position += (size_t) howMany; + memcpy (static_cast (data.getData()) + position, buffer, howMany); + position += howMany; size = jmax (size, position); } return true; } -void MemoryOutputStream::writeRepeatedByte (uint8 byte, int howMany) +void MemoryOutputStream::writeRepeatedByte (uint8 byte, size_t howMany) { if (howMany > 0) { prepareToWrite (howMany); - memset (static_cast (data.getData()) + position, byte, (size_t) howMany); - position += (size_t) howMany; + memset (static_cast (data.getData()) + position, byte, howMany); + position += howMany; size = jmax (size, position); } } @@ -160,7 +160,8 @@ String MemoryOutputStream::toString() const OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryOutputStream& streamToRead) { - const int dataSize = (int) streamToRead.getDataSize(); + const size_t dataSize = streamToRead.getDataSize(); + if (dataSize > 0) stream.write (streamToRead.getData(), dataSize); diff --git a/modules/juce_core/streams/juce_MemoryOutputStream.h b/modules/juce_core/streams/juce_MemoryOutputStream.h index ee190beff5..da8422a7f2 100644 --- a/modules/juce_core/streams/juce_MemoryOutputStream.h +++ b/modules/juce_core/streams/juce_MemoryOutputStream.h @@ -107,11 +107,11 @@ public: */ void flush(); - bool write (const void* buffer, int howMany); + bool write (const void* buffer, size_t howMany); int64 getPosition() { return position; } bool setPosition (int64 newPosition); int writeFromInputStream (InputStream& source, int64 maxNumBytesToWrite); - void writeRepeatedByte (uint8 byte, int numTimesToRepeat); + void writeRepeatedByte (uint8 byte, size_t numTimesToRepeat); private: //============================================================================== @@ -120,7 +120,7 @@ private: size_t position, size; void trimExternalBlockSize(); - void prepareToWrite (int numBytes); + void prepareToWrite (size_t); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryOutputStream) }; diff --git a/modules/juce_core/streams/juce_OutputStream.cpp b/modules/juce_core/streams/juce_OutputStream.cpp index 1471c984f6..5b9444b153 100644 --- a/modules/juce_core/streams/juce_OutputStream.cpp +++ b/modules/juce_core/streams/juce_OutputStream.cpp @@ -74,9 +74,9 @@ void OutputStream::writeByte (char byte) write (&byte, 1); } -void OutputStream::writeRepeatedByte (uint8 byte, int numTimesToRepeat) +void OutputStream::writeRepeatedByte (uint8 byte, size_t numTimesToRepeat) { - while (--numTimesToRepeat >= 0) + for (size_t i = 0; i < numTimesToRepeat; ++i) writeByte ((char) byte); } @@ -170,8 +170,8 @@ void OutputStream::writeString (const String& text) { // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind // if lots of large, persistent strings were to be written to streams). - const int numBytes = text.getNumBytesAsUTF8() + 1; - HeapBlock temp ((size_t) numBytes); + const size_t numBytes = text.getNumBytesAsUTF8() + 1; + HeapBlock temp (numBytes); text.copyToUTF8 (temp, numBytes); write (temp, numBytes); } @@ -288,14 +288,14 @@ JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const cha JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text) { - stream.write (text, (int) strlen (text)); + stream.write (text, strlen (text)); return stream; } JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryBlock& data) { if (data.getSize() > 0) - stream.write (data.getData(), (int) data.getSize()); + stream.write (data.getData(), data.getSize()); return stream; } diff --git a/modules/juce_core/streams/juce_OutputStream.h b/modules/juce_core/streams/juce_OutputStream.h index ef5ed388f5..009bd49740 100644 --- a/modules/juce_core/streams/juce_OutputStream.h +++ b/modules/juce_core/streams/juce_OutputStream.h @@ -84,11 +84,11 @@ public: types of data which use this to do the work. @param dataToWrite the target buffer to receive the data. This must not be null. - @param numberOfBytes the number of bytes to write. This must not be negative. + @param numberOfBytes the number of bytes to write. @returns false if the write operation fails for some reason */ virtual bool write (const void* dataToWrite, - int numberOfBytes) = 0; + size_t numberOfBytes) = 0; //============================================================================== /** Writes a single byte to the stream. @@ -160,7 +160,7 @@ public: virtual void writeDoubleBigEndian (double value); /** Writes a byte to the output stream a given number of times. */ - virtual void writeRepeatedByte (uint8 byte, int numTimesToRepeat); + virtual void writeRepeatedByte (uint8 byte, size_t numTimesToRepeat); /** Writes a condensed binary encoding of a 32-bit integer. diff --git a/modules/juce_core/text/juce_CharPointer_ASCII.h b/modules/juce_core/text/juce_CharPointer_ASCII.h index 66630add04..d029a0a77c 100644 --- a/modules/juce_core/text/juce_CharPointer_ASCII.h +++ b/modules/juce_core/text/juce_CharPointer_ASCII.h @@ -223,7 +223,7 @@ public: to the destination buffer before stopping. */ template - int writeWithDestByteLimit (const CharPointer& src, const int maxDestBytes) noexcept + size_t writeWithDestByteLimit (const CharPointer& src, const size_t maxDestBytes) noexcept { return CharacterFunctions::copyWithDestByteLimit (*this, src, maxDestBytes); } diff --git a/modules/juce_core/text/juce_CharPointer_UTF16.h b/modules/juce_core/text/juce_CharPointer_UTF16.h index c44fb8ea2c..89aadca6cb 100644 --- a/modules/juce_core/text/juce_CharPointer_UTF16.h +++ b/modules/juce_core/text/juce_CharPointer_UTF16.h @@ -303,7 +303,7 @@ public: to the destination buffer before stopping. */ template - int writeWithDestByteLimit (const CharPointer& src, const int maxDestBytes) noexcept + size_t writeWithDestByteLimit (const CharPointer& src, const size_t maxDestBytes) noexcept { return CharacterFunctions::copyWithDestByteLimit (*this, src, maxDestBytes); } diff --git a/modules/juce_core/text/juce_CharPointer_UTF32.h b/modules/juce_core/text/juce_CharPointer_UTF32.h index 7d707b9f17..f7aa6df79d 100644 --- a/modules/juce_core/text/juce_CharPointer_UTF32.h +++ b/modules/juce_core/text/juce_CharPointer_UTF32.h @@ -233,7 +233,7 @@ public: to the destination buffer before stopping. */ template - int writeWithDestByteLimit (const CharPointer& src, const int maxDestBytes) noexcept + size_t writeWithDestByteLimit (const CharPointer& src, const size_t maxDestBytes) noexcept { return CharacterFunctions::copyWithDestByteLimit (*this, src, maxDestBytes); } diff --git a/modules/juce_core/text/juce_CharPointer_UTF8.h b/modules/juce_core/text/juce_CharPointer_UTF8.h index 75351c133b..92f018d30e 100644 --- a/modules/juce_core/text/juce_CharPointer_UTF8.h +++ b/modules/juce_core/text/juce_CharPointer_UTF8.h @@ -385,7 +385,7 @@ public: to the destination buffer before stopping. */ template - int writeWithDestByteLimit (const CharPointer& src, const int maxDestBytes) noexcept + size_t writeWithDestByteLimit (const CharPointer& src, const size_t maxDestBytes) noexcept { return CharacterFunctions::copyWithDestByteLimit (*this, src, maxDestBytes); } diff --git a/modules/juce_core/text/juce_CharacterFunctions.h b/modules/juce_core/text/juce_CharacterFunctions.h index 74d574a2fb..5b7e0ddb05 100644 --- a/modules/juce_core/text/juce_CharacterFunctions.h +++ b/modules/juce_core/text/juce_CharacterFunctions.h @@ -324,15 +324,16 @@ public: /** Copies characters from one string to another, up to a null terminator or a given byte size limit. */ template - static int copyWithDestByteLimit (DestCharPointerType& dest, SrcCharPointerType src, int maxBytes) noexcept + static size_t copyWithDestByteLimit (DestCharPointerType& dest, SrcCharPointerType src, size_t maxBytesToWrite) noexcept { typename DestCharPointerType::CharType const* const startAddress = dest.getAddress(); + ssize_t maxBytes = (ssize_t) maxBytesToWrite; maxBytes -= sizeof (typename DestCharPointerType::CharType); // (allow for a terminating null) for (;;) { const juce_wchar c = src.getAndAdvance(); - const int bytesNeeded = (int) DestCharPointerType::getBytesRequiredFor (c); + const size_t bytesNeeded = DestCharPointerType::getBytesRequiredFor (c); maxBytes -= bytesNeeded; if (c == 0 || maxBytes < 0) @@ -343,7 +344,8 @@ public: dest.writeNull(); - return (int) ((size_t) getAddressDifference (dest.getAddress(), startAddress) + sizeof (typename DestCharPointerType::CharType)); + return (size_t) getAddressDifference (dest.getAddress(), startAddress) + + sizeof (typename DestCharPointerType::CharType); } /** Copies characters from one string to another, up to a null terminator diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index 07fd4449a5..146b89a89e 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -731,7 +731,7 @@ JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const double number) JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text) { - const int numBytes = text.getNumBytesAsUTF8(); + const size_t numBytes = text.getNumBytesAsUTF8(); #if (JUCE_STRING_UTF_TYPE == 8) stream.write (text.getCharPointer().getAddress(), numBytes); @@ -2020,36 +2020,36 @@ const wchar_t* String::toWideCharPointer() const template struct StringCopier { - static int copyToBuffer (const CharPointerType_Src& source, typename CharPointerType_Dest::CharType* const buffer, const int maxBufferSizeBytes) + static size_t copyToBuffer (const CharPointerType_Src& source, typename CharPointerType_Dest::CharType* const buffer, const size_t maxBufferSizeBytes) { - jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied! + jassert (((ssize_t) maxBufferSizeBytes) >= 0); // keep this value positive! if (buffer == nullptr) - return (int) (CharPointerType_Dest::getBytesRequiredFor (source) + sizeof (typename CharPointerType_Dest::CharType)); + return CharPointerType_Dest::getBytesRequiredFor (source) + sizeof (typename CharPointerType_Dest::CharType); return CharPointerType_Dest (buffer).writeWithDestByteLimit (source, maxBufferSizeBytes); } }; -int String::copyToUTF8 (CharPointer_UTF8::CharType* const buffer, const int maxBufferSizeBytes) const noexcept +size_t String::copyToUTF8 (CharPointer_UTF8::CharType* const buffer, size_t maxBufferSizeBytes) const noexcept { return StringCopier ::copyToBuffer (text, buffer, maxBufferSizeBytes); } -int String::copyToUTF16 (CharPointer_UTF16::CharType* const buffer, int maxBufferSizeBytes) const noexcept +size_t String::copyToUTF16 (CharPointer_UTF16::CharType* const buffer, size_t maxBufferSizeBytes) const noexcept { return StringCopier ::copyToBuffer (text, buffer, maxBufferSizeBytes); } -int String::copyToUTF32 (CharPointer_UTF32::CharType* const buffer, int maxBufferSizeBytes) const noexcept +size_t String::copyToUTF32 (CharPointer_UTF32::CharType* const buffer, size_t maxBufferSizeBytes) const noexcept { return StringCopier ::copyToBuffer (text, buffer, maxBufferSizeBytes); } //============================================================================== -int String::getNumBytesAsUTF8() const noexcept +size_t String::getNumBytesAsUTF8() const noexcept { - return (int) CharPointer_UTF8::getBytesRequiredFor (text); + return CharPointer_UTF8::getBytesRequiredFor (text); } String String::fromUTF8 (const char* const buffer, int bufferSizeBytes) diff --git a/modules/juce_core/text/juce_String.h b/modules/juce_core/text/juce_String.h index 85bc8c22f8..74fad7412e 100644 --- a/modules/juce_core/text/juce_String.h +++ b/modules/juce_core/text/juce_String.h @@ -1096,7 +1096,7 @@ public: The number returned does NOT include the trailing zero. @see toUTF8, copyToUTF8 */ - int getNumBytesAsUTF8() const noexcept; + size_t getNumBytesAsUTF8() const noexcept; //============================================================================== /** Copies the string to a buffer as UTF-8 characters. @@ -1114,7 +1114,7 @@ public: end, and will return the number of bytes that were actually used. @see CharPointer_UTF8::writeWithDestByteLimit */ - int copyToUTF8 (CharPointer_UTF8::CharType* destBuffer, int maxBufferSizeBytes) const noexcept; + size_t copyToUTF8 (CharPointer_UTF8::CharType* destBuffer, size_t maxBufferSizeBytes) const noexcept; /** Copies the string to a buffer as UTF-16 characters. @@ -1131,7 +1131,7 @@ public: end, and will return the number of bytes that were actually used. @see CharPointer_UTF16::writeWithDestByteLimit */ - int copyToUTF16 (CharPointer_UTF16::CharType* destBuffer, int maxBufferSizeBytes) const noexcept; + size_t copyToUTF16 (CharPointer_UTF16::CharType* destBuffer, size_t maxBufferSizeBytes) const noexcept; /** Copies the string to a buffer as UTF-32 characters. @@ -1148,7 +1148,7 @@ public: end, and will return the number of bytes that were actually used. @see CharPointer_UTF32::writeWithDestByteLimit */ - int copyToUTF32 (CharPointer_UTF32::CharType* destBuffer, int maxBufferSizeBytes) const noexcept; + size_t copyToUTF32 (CharPointer_UTF32::CharType* destBuffer, size_t maxBufferSizeBytes) const noexcept; //============================================================================== /** Increases the string's internally allocated storage. diff --git a/modules/juce_core/threads/juce_ChildProcess.cpp b/modules/juce_core/threads/juce_ChildProcess.cpp index da5e85edd6..2fb747269e 100644 --- a/modules/juce_core/threads/juce_ChildProcess.cpp +++ b/modules/juce_core/threads/juce_ChildProcess.cpp @@ -52,7 +52,7 @@ String ChildProcess::readAllProcessOutput() if (num <= 0) break; - result.write (buffer, num); + result.write (buffer, (size_t) num); } return result.toString(); diff --git a/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp b/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp index e233146f73..6b9df015da 100644 --- a/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp +++ b/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp @@ -46,7 +46,7 @@ public: zlibNamespace::deflateEnd (&stream); } - bool write (const uint8* data, unsigned int dataSize, OutputStream& out) + bool write (const uint8* data, size_t dataSize, OutputStream& out) { // When you call flush() on a gzip stream, the stream is closed, and you can // no longer continue to write data to it! @@ -62,7 +62,7 @@ public: void finish (OutputStream& out) { const uint8* data = nullptr; - unsigned int dataSize = 0; + size_t dataSize = 0; while (! finished) doNextBlock (data, dataSize, out, Z_FINISH); @@ -76,9 +76,10 @@ private: bool isFirstDeflate, streamIsValid, finished; zlibNamespace::Bytef buffer[32768]; - bool doNextBlock (const uint8*& data, unsigned int& dataSize, OutputStream& out, const int flushMode) + bool doNextBlock (const uint8*& data, size_t& dataSize, OutputStream& out, const int flushMode) { using namespace zlibNamespace; + if (streamIsValid) { stream.next_in = const_cast (data); @@ -99,8 +100,8 @@ private: { data += dataSize - stream.avail_in; dataSize = stream.avail_in; - const int bytesDone = ((int) sizeof (buffer)) - (int) stream.avail_out; - return bytesDone <= 0 || out.write (buffer, bytesDone); + const ssize_t bytesDone = sizeof (buffer) - (ssize_t) stream.avail_out; + return bytesDone <= 0 || out.write (buffer, (size_t) bytesDone); } default: @@ -136,12 +137,11 @@ void GZIPCompressorOutputStream::flush() destStream->flush(); } -bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany) +bool GZIPCompressorOutputStream::write (const void* destBuffer, size_t howMany) { jassert (destBuffer != nullptr && howMany >= 0); - return helper->write (static_cast (destBuffer), - (unsigned int) howMany, *destStream); + return helper->write (static_cast (destBuffer), howMany, *destStream); } int64 GZIPCompressorOutputStream::getPosition() @@ -182,8 +182,8 @@ public: for (int k = (int) data.getSize(); --k >= 0;) data[k] = (char) rng.nextInt (255); - original.write (data.getData(), (int) data.getSize()); - zipper .write (data.getData(), (int) data.getSize()); + original << data; + zipper << data; } } diff --git a/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h b/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h index 2428f434b0..d1f5d576d9 100644 --- a/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h +++ b/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h @@ -77,7 +77,7 @@ public: int64 getPosition(); bool setPosition (int64 newPosition); - bool write (const void* destBuffer, int howMany); + bool write (const void* destBuffer, size_t howMany); /** These are preset values that can be used for the constructor's windowBits paramter. For more info about this, see the zlib documentation for its windowBits parameter. diff --git a/modules/juce_core/zip/juce_ZipFile.cpp b/modules/juce_core/zip/juce_ZipFile.cpp index 7dc6e119cc..7c6392a421 100644 --- a/modules/juce_core/zip/juce_ZipFile.cpp +++ b/modules/juce_core/zip/juce_ZipFile.cpp @@ -520,7 +520,7 @@ private: return false; checksum = juce_crc32 (checksum, buffer, (unsigned int) bytesRead); - target.write (buffer, bytesRead); + target.write (buffer, (size_t) bytesRead); } return true; diff --git a/modules/juce_graphics/image_formats/juce_JPEGLoader.cpp b/modules/juce_graphics/image_formats/juce_JPEGLoader.cpp index 70b1979826..084791d0d2 100644 --- a/modules/juce_graphics/image_formats/juce_JPEGLoader.cpp +++ b/modules/juce_graphics/image_formats/juce_JPEGLoader.cpp @@ -192,7 +192,7 @@ namespace JPEGHelpers JuceJpegDest* const dest = static_cast (cinfo->dest); const size_t numToWrite = jpegBufferSize - dest->free_in_buffer; - dest->output->write (dest->buffer, (int) numToWrite); + dest->output->write (dest->buffer, numToWrite); } static boolean jpegWriteFlush (j_compress_ptr cinfo) @@ -204,7 +204,7 @@ namespace JPEGHelpers dest->next_output_byte = reinterpret_cast (dest->buffer); dest->free_in_buffer = jpegBufferSize; - return (boolean) dest->output->write (dest->buffer, numToWrite); + return (boolean) dest->output->write (dest->buffer, (size_t) numToWrite); } } diff --git a/modules/juce_graphics/image_formats/juce_PNGLoader.cpp b/modules/juce_graphics/image_formats/juce_PNGLoader.cpp index 02d1e69953..d36c70fb94 100644 --- a/modules/juce_graphics/image_formats/juce_PNGLoader.cpp +++ b/modules/juce_graphics/image_formats/juce_PNGLoader.cpp @@ -112,7 +112,7 @@ namespace PNGHelpers static void JUCE_CDECL writeDataCallback (png_structp png, png_bytep data, png_size_t length) { - static_cast (png_get_io_ptr (png))->write (data, (int) length); + static_cast (png_get_io_ptr (png))->write (data, length); } #if ! JUCE_USING_COREIMAGE_LOADER diff --git a/modules/juce_gui_basics/native/juce_linux_Clipboard.cpp b/modules/juce_gui_basics/native/juce_linux_Clipboard.cpp index 6988d17c38..846ef0a69f 100644 --- a/modules/juce_gui_basics/native/juce_linux_Clipboard.cpp +++ b/modules/juce_gui_basics/native/juce_linux_Clipboard.cpp @@ -135,7 +135,8 @@ namespace ClipboardHelpers reply.time = evt.time; HeapBlock data; - int propertyFormat = 0, numDataItems = 0; + int propertyFormat = 0; + size_t numDataItems = 0; if (evt.selection == XA_PRIMARY || evt.selection == ClipboardHelpers::atom_CLIPBOARD) { @@ -167,7 +168,7 @@ namespace ClipboardHelpers if (data != nullptr) { - const int maxReasonableSelectionSize = 1000000; + const size_t maxReasonableSelectionSize = 1000000; // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss if (evt.property != None && numDataItems < maxReasonableSelectionSize) diff --git a/modules/juce_gui_basics/native/juce_win32_DragAndDrop.cpp b/modules/juce_gui_basics/native/juce_win32_DragAndDrop.cpp index 658a5b7562..b66be5d8ab 100644 --- a/modules/juce_gui_basics/native/juce_win32_DragAndDrop.cpp +++ b/modules/juce_gui_basics/native/juce_win32_DragAndDrop.cpp @@ -236,7 +236,7 @@ namespace DragAndDropHelpers for (int i = 0; i < fileNames.size(); ++i) { - const int bytesWritten = fileNames[i].copyToUTF16 (fname, 2048); + const size_t bytesWritten = fileNames[i].copyToUTF16 (fname, 2048); fname = reinterpret_cast (addBytesToPointer (fname, bytesWritten)); } @@ -285,7 +285,7 @@ bool DragAndDropContainer::performExternalDragDropOfText (const String& text) medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, numBytes + 2); WCHAR* const data = static_cast (GlobalLock (medium.hGlobal)); - text.copyToUTF16 (data, (int) numBytes); + text.copyToUTF16 (data, numBytes); format.cfFormat = CF_UNICODETEXT; GlobalUnlock (medium.hGlobal); diff --git a/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp b/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp index 3d85079798..300f56feb9 100644 --- a/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp +++ b/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp @@ -135,7 +135,7 @@ void FileChooser::showPlatformDialog (Array& results, const String& title_ const String title (title_); HeapBlock files; - const int charsAvailableForResult = 32768; + const size_t charsAvailableForResult = 32768; files.calloc (charsAvailableForResult + 1); int filenameOffset = 0; @@ -215,12 +215,12 @@ void FileChooser::showPlatformDialog (Array& results, const String& title_ info.customComponent->enterModalState(); } - const int filterSpaceNumChars = 2048; + const size_t filterSpaceNumChars = 2048; HeapBlock filters; filters.calloc (filterSpaceNumChars); - const int bytesWritten = filter.copyToUTF16 (filters.getData(), filterSpaceNumChars * sizeof (WCHAR)); + const size_t bytesWritten = filter.copyToUTF16 (filters.getData(), filterSpaceNumChars * sizeof (WCHAR)); filter.copyToUTF16 (filters + (bytesWritten / sizeof (WCHAR)), - (int) ((filterSpaceNumChars - 1) * sizeof (WCHAR) - bytesWritten)); + ((filterSpaceNumChars - 1) * sizeof (WCHAR) - bytesWritten)); OPENFILENAMEW of = { 0 }; String localPath (info.initialPath); @@ -234,7 +234,7 @@ void FileChooser::showPlatformDialog (Array& results, const String& title_ of.lpstrFilter = filters.getData(); of.nFilterIndex = 1; of.lpstrFile = files; - of.nMaxFile = charsAvailableForResult; + of.nMaxFile = (DWORD) charsAvailableForResult; of.lpstrInitialDir = localPath.toWideCharPointer(); of.lpstrTitle = title.toWideCharPointer(); of.Flags = flags; diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 709ceffaa0..0e82924866 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -3025,7 +3025,7 @@ void SystemClipboard::copyTextToClipboard (const String& text) { if (WCHAR* const data = static_cast (GlobalLock (bufH))) { - text.copyToUTF16 (data, (int) bytesNeeded); + text.copyToUTF16 (data, bytesNeeded); GlobalUnlock (bufH); SetClipboardData (CF_UNICODETEXT, bufH); diff --git a/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp b/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp index b6de2d6b02..7b71d0d4da 100644 --- a/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp +++ b/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp @@ -611,7 +611,7 @@ bool CodeDocument::writeToStream (OutputStream& stream) String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string. const char* utf8 = temp.toUTF8(); - if (! stream.write (utf8, (int) strlen (utf8))) + if (! stream.write (utf8, strlen (utf8))) return false; }