mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Data::getSize now uses size_t instead of int
This commit is contained in:
@@ -20,9 +20,9 @@
|
||||
|
||||
#include "FileData.h"
|
||||
|
||||
// STD
|
||||
// C++
|
||||
#include <iostream>
|
||||
#include <climits>
|
||||
#include <limits>
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -31,7 +31,7 @@ namespace filesystem
|
||||
|
||||
FileData::FileData(uint64 size, const std::string &filename)
|
||||
: data(new char[(size_t) size])
|
||||
, size(size)
|
||||
, size((size_t) size)
|
||||
, filename(filename)
|
||||
{
|
||||
if (filename.rfind('.') != std::string::npos)
|
||||
@@ -48,15 +48,10 @@ void *FileData::getData() const
|
||||
return (void *)data;
|
||||
}
|
||||
|
||||
// TODO: Enable this
|
||||
/*uint64 FileData::getSize() const
|
||||
size_t FileData::getSize() const
|
||||
{
|
||||
return size;
|
||||
}*/
|
||||
|
||||
int FileData::getSize() const
|
||||
{
|
||||
return size > INT_MAX ? INT_MAX : (int) size;
|
||||
size_t sizemax = std::numeric_limits<size_t>::max();
|
||||
return size > sizemax ? sizemax : (size_t) size;
|
||||
}
|
||||
|
||||
const std::string &FileData::getFilename() const
|
||||
|
||||
@@ -49,9 +49,7 @@ public:
|
||||
|
||||
// Implements Data.
|
||||
void *getData() const;
|
||||
//TODO: Enable this
|
||||
//uint64 getSize() const;
|
||||
int getSize() const;
|
||||
size_t getSize() const;
|
||||
|
||||
const std::string &getFilename() const;
|
||||
const std::string &getExtension() const;
|
||||
|
||||
@@ -64,16 +64,16 @@ void *GlyphData::getData() const
|
||||
return (void *) data;
|
||||
}
|
||||
|
||||
int GlyphData::getSize() const
|
||||
size_t GlyphData::getSize() const
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case GlyphData::FORMAT_LUMINANCE_ALPHA:
|
||||
return getWidth() * getHeight() * 2;
|
||||
return size_t(getWidth() * getHeight() * 2);
|
||||
break;
|
||||
case GlyphData::FORMAT_RGBA:
|
||||
default:
|
||||
return getWidth() * getHeight() * 4;
|
||||
return size_t(getWidth() * getHeight() * 4);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
|
||||
// Implements Data.
|
||||
void *getData() const;
|
||||
int getSize() const;
|
||||
size_t getSize() const;
|
||||
|
||||
/**
|
||||
* Gets the height of the glyph.
|
||||
|
||||
@@ -36,9 +36,9 @@ CompressedData::~CompressedData()
|
||||
{
|
||||
}
|
||||
|
||||
int CompressedData::getSize() const
|
||||
size_t CompressedData::getSize() const
|
||||
{
|
||||
return int(dataSize);
|
||||
return dataSize;
|
||||
}
|
||||
|
||||
void *CompressedData::getData() const
|
||||
@@ -51,11 +51,11 @@ int CompressedData::getMipmapCount() const
|
||||
return dataImages.size();
|
||||
}
|
||||
|
||||
int CompressedData::getSize(int miplevel) const
|
||||
size_t CompressedData::getSize(int miplevel) const
|
||||
{
|
||||
checkMipmapLevelExists(miplevel);
|
||||
|
||||
return int(dataImages[miplevel].size);
|
||||
return dataImages[miplevel].size;
|
||||
}
|
||||
|
||||
void *CompressedData::getData(int miplevel) const
|
||||
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
|
||||
// Implements Data.
|
||||
virtual void *getData() const;
|
||||
virtual int getSize() const;
|
||||
virtual size_t getSize() const;
|
||||
|
||||
/**
|
||||
* Gets the number of mipmaps in this Compressed Image Data.
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
/**
|
||||
* Gets the size in bytes of a sub-image at the specified mipmap level.
|
||||
**/
|
||||
int getSize(int miplevel) const;
|
||||
size_t getSize(int miplevel) const;
|
||||
|
||||
/**
|
||||
* Gets the byte data of a sub-image at the specified mipmap level.
|
||||
|
||||
@@ -38,9 +38,9 @@ ImageData::~ImageData()
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
int ImageData::getSize() const
|
||||
size_t ImageData::getSize() const
|
||||
{
|
||||
return getWidth()*getHeight()*sizeof(pixel);
|
||||
return size_t(getWidth()*getHeight())*sizeof(pixel);
|
||||
}
|
||||
|
||||
void *ImageData::getData() const
|
||||
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
|
||||
// Implements Data.
|
||||
virtual void *getData() const;
|
||||
virtual int getSize() const;
|
||||
virtual size_t getSize() const;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
#include "SoundData.h"
|
||||
|
||||
// C
|
||||
#include <climits>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
// STL
|
||||
// C++
|
||||
#include <limits>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
@@ -48,9 +48,9 @@ SoundData::SoundData(Decoder *decoder)
|
||||
{
|
||||
// Expand or allocate buffer. Note that realloc may move
|
||||
// memory to other locations.
|
||||
if (!data || bufferSize < (size_t) size + decoded)
|
||||
if (!data || bufferSize < size + decoded)
|
||||
{
|
||||
while (bufferSize < (size_t) size + decoded)
|
||||
while (bufferSize < size + decoded)
|
||||
bufferSize <<= 1;
|
||||
data = (uint8 *) realloc(data, bufferSize);
|
||||
}
|
||||
@@ -61,21 +61,21 @@ SoundData::SoundData(Decoder *decoder)
|
||||
// Copy memory into new part of memory.
|
||||
memcpy(data + size, decoder->getBuffer(), decoded);
|
||||
|
||||
// Keep this up to date.
|
||||
size += decoded;
|
||||
|
||||
// Overflow check.
|
||||
if (size < 0)
|
||||
if (size > std::numeric_limits<size_t>::max() - decoded)
|
||||
{
|
||||
free(data);
|
||||
throw love::Exception("Not enough memory.");
|
||||
}
|
||||
|
||||
// Keep this up to date.
|
||||
size += decoded;
|
||||
|
||||
decoded = decoder->decode();
|
||||
}
|
||||
|
||||
// Shrink buffer if necessary.
|
||||
if (data && bufferSize > (size_t) size)
|
||||
if (data && bufferSize > size)
|
||||
data = (uint8 *) realloc(data, size);
|
||||
|
||||
channels = decoder->getChannels();
|
||||
@@ -136,7 +136,7 @@ void SoundData::load(int samples, int sampleRate, int bitDepth, int channels, vo
|
||||
|
||||
double realsize = samples;
|
||||
realsize *= (bitDepth / 8) * channels;
|
||||
if (realsize > INT_MAX)
|
||||
if (realsize > std::numeric_limits<size_t>::max())
|
||||
throw love::Exception("Data is too big!");
|
||||
|
||||
data = (uint8 *) malloc(size);
|
||||
@@ -154,9 +154,9 @@ void *SoundData::getData() const
|
||||
return (void *)data;
|
||||
}
|
||||
|
||||
int SoundData::getSize() const
|
||||
size_t SoundData::getSize() const
|
||||
{
|
||||
return (int)size;
|
||||
return size;
|
||||
}
|
||||
|
||||
int SoundData::getChannels() const
|
||||
@@ -187,7 +187,7 @@ float SoundData::getDuration() const
|
||||
void SoundData::setSample(int i, float sample)
|
||||
{
|
||||
// Check range.
|
||||
if (i < 0 || i >= size/(bitDepth/8))
|
||||
if (i < 0 || (size_t) i >= size/(bitDepth/8))
|
||||
throw love::Exception("Attempt to set out-of-range sample!");
|
||||
|
||||
if (bitDepth == 16)
|
||||
@@ -206,7 +206,7 @@ void SoundData::setSample(int i, float sample)
|
||||
float SoundData::getSample(int i) const
|
||||
{
|
||||
// Check range.
|
||||
if (i < 0 || i >= size/(bitDepth/8))
|
||||
if (i < 0 || (size_t) i >= size/(bitDepth/8))
|
||||
throw love::Exception("Attempt to get out-of-range sample!");
|
||||
|
||||
if (bitDepth == 16)
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
// Implements Data.
|
||||
void *getData() const;
|
||||
int getSize() const;
|
||||
size_t getSize() const;
|
||||
|
||||
virtual int getChannels() const;
|
||||
virtual int getBitDepth() const;
|
||||
@@ -60,7 +60,7 @@ private:
|
||||
void load(int samples, int sampleRate, int bitDepth, int channels, void *newData = 0);
|
||||
|
||||
uint8 *data;
|
||||
int size;
|
||||
size_t size;
|
||||
|
||||
int sampleRate;
|
||||
int bitDepth;
|
||||
|
||||
Reference in New Issue
Block a user