summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/analyse_audio_job.cc21
-rw-r--r--src/lib/analyse_audio_job.h4
-rw-r--r--src/lib/audio_buffers.cc22
-rw-r--r--src/lib/audio_mapping.cc23
-rw-r--r--src/lib/cinema_sound_processor.cc4
-rw-r--r--src/lib/colour_conversion.cc4
-rw-r--r--src/lib/compose.hpp2
-rw-r--r--src/lib/cross_linux.cc7
-rw-r--r--src/lib/dcpomatic_socket.cc8
-rw-r--r--src/lib/dcpomatic_socket.h4
-rw-r--r--src/lib/digester.cc2
-rw-r--r--src/lib/digester.h2
-rw-r--r--src/lib/edid.cc6
-rw-r--r--src/lib/ffmpeg_decoder.cc9
-rw-r--r--src/lib/ffmpeg_image_proxy.cc14
-rw-r--r--src/lib/ffmpeg_image_proxy.h2
-rw-r--r--src/lib/film.cc2
-rw-r--r--src/lib/image.cc55
-rw-r--r--src/lib/image_decoder.cc3
-rw-r--r--src/lib/image_examiner.cc2
-rw-r--r--src/lib/image_filename_sorter.cc4
-rw-r--r--src/lib/internet.cc7
-rw-r--r--src/lib/j2k_image_proxy.cc4
-rw-r--r--src/lib/kdm_with_metadata.cc8
-rw-r--r--src/lib/playlist.cc12
-rw-r--r--src/lib/playlist.h2
-rw-r--r--src/lib/reel_writer.cc2
-rw-r--r--src/lib/render_text.cc3
-rw-r--r--src/lib/video_ring_buffers.cc2
-rw-r--r--src/lib/warnings.h27
30 files changed, 167 insertions, 100 deletions
diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc
index acd730a68..47beb0d43 100644
--- a/src/lib/analyse_audio_job.cc
+++ b/src/lib/analyse_audio_job.cc
@@ -92,7 +92,7 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> film, shared_ptr<const
}
/* XXX: is this right? Especially for more than 5.1? */
- vector<double> channel_corrections(film->audio_channels(), 1);
+ vector<double> channel_corrections(static_cast<size_t>(film->audio_channels()), 1);
add_if_required (channel_corrections, 4, -3); // Ls
add_if_required (channel_corrections, 5, -3); // Rs
add_if_required (channel_corrections, 6, -144); // HI
@@ -113,7 +113,7 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> film, shared_ptr<const
channel_corrections,
850, // suggested by leqm_nrt CLI source
64, // suggested by leqm_nrt CLI source
- boost::thread::hardware_concurrency()
+ static_cast<int>(boost::thread::hardware_concurrency())
));
}
@@ -231,16 +231,17 @@ AnalyseAudioJob::analyse (shared_ptr<const AudioBuffers> b, DCPTime time)
}
#endif
- int const frames = b->frames ();
- int const channels = b->channels ();
- vector<double> interleaved(frames * channels);
+ DCPOMATIC_ASSERT (b->frames());
+ DCPOMATIC_ASSERT (b->channels());
- for (int j = 0; j < channels; ++j) {
+ vector<double> interleaved(static_cast<size_t>(b->frames() * b->channels()));
+
+ for (int j = 0; j < b->channels(); ++j) {
float* data = b->data(j);
- for (int i = 0; i < frames; ++i) {
- float s = data[i];
+ for (Frame i = 0; i < b->frames(); ++i) {
+ float s = data[static_cast<size_t>(i)];
- interleaved[i * channels + j] = s;
+ interleaved[static_cast<size_t>(i * b->channels() + j)] = s;
float as = fabsf (s);
if (as < 10e-7) {
@@ -266,7 +267,7 @@ AnalyseAudioJob::analyse (shared_ptr<const AudioBuffers> b, DCPTime time)
_leqm->add(interleaved);
- _done += frames;
+ _done += b->frames();
DCPTime const length = _playlist->length (_film);
set_progress ((time.seconds() - _start.seconds()) / (length.seconds() - _start.seconds()));
diff --git a/src/lib/analyse_audio_job.h b/src/lib/analyse_audio_job.h
index f7cc3e256..8f88b0fa1 100644
--- a/src/lib/analyse_audio_job.h
+++ b/src/lib/analyse_audio_job.h
@@ -66,8 +66,8 @@ private:
dcpomatic::DCPTime _start;
bool _from_zero;
- int64_t _done;
- int64_t _samples_per_point;
+ Frame _done;
+ Frame _samples_per_point;
AudioPoint* _current;
float* _sample_peak;
diff --git a/src/lib/audio_buffers.cc b/src/lib/audio_buffers.cc
index cfe762659..739441b4c 100644
--- a/src/lib/audio_buffers.cc
+++ b/src/lib/audio_buffers.cc
@@ -89,13 +89,13 @@ AudioBuffers::allocate (int channels, int32_t frames)
_frames = frames;
_allocated_frames = frames;
- _data = static_cast<float**> (malloc (_channels * sizeof (float *)));
+ _data = static_cast<float**>(malloc(static_cast<size_t>(_channels) * sizeof(float *)));
if (!_data) {
throw bad_alloc ();
}
for (int i = 0; i < _channels; ++i) {
- _data[i] = static_cast<float*> (malloc (frames * sizeof (float)));
+ _data[i] = static_cast<float*>(malloc(static_cast<size_t>(frames) * sizeof(float)));
if (!_data[i]) {
throw bad_alloc ();
}
@@ -158,7 +158,8 @@ AudioBuffers::make_silent (int c)
/* This isn't really allowed, as all-bits-0 is not guaranteed to mean a 0 float,
but it seems that we can get away with it.
*/
- memset (_data[c], 0, _frames * sizeof(float));
+ DCPOMATIC_ASSERT (_frames >= 0);
+ memset (_data[c], 0, static_cast<size_t>(_frames) * sizeof(float));
}
/** Make some frames.
@@ -169,12 +170,13 @@ void
AudioBuffers::make_silent (int32_t from, int32_t frames)
{
DCPOMATIC_ASSERT ((from + frames) <= _allocated_frames);
+ DCPOMATIC_ASSERT (frames >= 0);
for (int c = 0; c < _channels; ++c) {
/* This isn't really allowed, as all-bits-0 is not guaranteed to mean a 0 float,
but it seems that we can get away with it.
*/
- memset (_data[c] + from, 0, frames * sizeof(float));
+ memset (_data[c] + from, 0, static_cast<size_t>(frames) * sizeof(float));
}
}
@@ -197,9 +199,10 @@ AudioBuffers::copy_from (AudioBuffers const * from, int32_t frames_to_copy, int3
DCPOMATIC_ASSERT (from);
DCPOMATIC_ASSERT (read_offset >= 0 && (read_offset + frames_to_copy) <= from->_allocated_frames);
DCPOMATIC_ASSERT (write_offset >= 0 && (write_offset + frames_to_copy) <= _allocated_frames);
+ DCPOMATIC_ASSERT (frames_to_copy > 0);
for (int i = 0; i < _channels; ++i) {
- memcpy (_data[i] + write_offset, from->_data[i] + read_offset, frames_to_copy * sizeof(float));
+ memcpy (_data[i] + write_offset, from->_data[i] + read_offset, static_cast<size_t>(frames_to_copy) * sizeof(float));
}
}
@@ -225,7 +228,7 @@ AudioBuffers::move (int32_t frames, int32_t from, int32_t to)
DCPOMATIC_ASSERT ((to + frames) <= _allocated_frames);
for (int i = 0; i < _channels; ++i) {
- memmove (_data[i] + to, _data[i] + from, frames * sizeof(float));
+ memmove (_data[i] + to, _data[i] + from, static_cast<size_t>(frames) * sizeof(float));
}
}
@@ -256,6 +259,8 @@ AudioBuffers::accumulate_channel (AudioBuffers const * from, int from_channel, i
void
AudioBuffers::ensure_size (int32_t frames)
{
+ DCPOMATIC_ASSERT (frames >= 0);
+
if (_allocated_frames >= frames) {
return;
}
@@ -272,7 +277,7 @@ AudioBuffers::ensure_size (int32_t frames)
frames++;
for (int i = 0; i < _channels; ++i) {
- _data[i] = static_cast<float*> (realloc (_data[i], frames * sizeof (float)));
+ _data[i] = static_cast<float*>(realloc(_data[i], static_cast<size_t>(frames) * sizeof (float)));
if (!_data[i]) {
throw bad_alloc ();
}
@@ -339,7 +344,8 @@ void
AudioBuffers::copy_channel_from (AudioBuffers const * from, int from_channel, int to_channel)
{
DCPOMATIC_ASSERT (from->frames() == frames());
- memcpy (data(to_channel), from->data(from_channel), frames() * sizeof (float));
+ DCPOMATIC_ASSERT (frames() >= 0);
+ memcpy (data(to_channel), from->data(from_channel), static_cast<size_t>(frames()) * sizeof(float));
}
/** Make a copy of these AudioBuffers */
diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc
index 05dfb7e89..e2f681680 100644
--- a/src/lib/audio_mapping.cc
+++ b/src/lib/audio_mapping.cc
@@ -60,12 +60,15 @@ AudioMapping::AudioMapping (int input_channels, int output_channels)
void
AudioMapping::setup (int input_channels, int output_channels)
{
+ DCPOMATIC_ASSERT (input_channels >= 0);
+ DCPOMATIC_ASSERT (output_channels >= 0);
+
_input_channels = input_channels;
_output_channels = output_channels;
- _gain.resize (_input_channels);
+ _gain.resize (static_cast<size_t>(_input_channels));
for (int i = 0; i < _input_channels; ++i) {
- _gain[i].resize (_output_channels);
+ _gain[i].resize (static_cast<size_t>(_output_channels));
}
make_zero ();
@@ -179,17 +182,17 @@ AudioMapping::AudioMapping (cxml::ConstNodePtr node, int state_version)
void
AudioMapping::set (int input_channel, int output_channel, float g)
{
- DCPOMATIC_ASSERT (input_channel < int(_gain.size()));
- DCPOMATIC_ASSERT (output_channel < int(_gain[0].size()));
- _gain[input_channel][output_channel] = g;
+ DCPOMATIC_ASSERT (input_channel >= 0 && input_channel < int(_gain.size()));
+ DCPOMATIC_ASSERT (output_channel >= 0 && output_channel < int(_gain[0].size()));
+ _gain[static_cast<size_t>(input_channel)][static_cast<size_t>(output_channel)] = g;
}
float
AudioMapping::get (int input_channel, int output_channel) const
{
- DCPOMATIC_ASSERT (input_channel < int (_gain.size()));
- DCPOMATIC_ASSERT (output_channel < int (_gain[0].size()));
- return _gain[input_channel][output_channel];
+ DCPOMATIC_ASSERT (input_channel >= 0 && input_channel < int(_gain.size()));
+ DCPOMATIC_ASSERT (output_channel >= 0 && output_channel < int(_gain[0].size()));
+ return _gain[static_cast<size_t>(input_channel)][static_cast<size_t>(output_channel)];
}
void
@@ -217,8 +220,8 @@ AudioMapping::digest () const
Digester digester;
digester.add (_input_channels);
digester.add (_output_channels);
- for (int i = 0; i < _input_channels; ++i) {
- for (int j = 0; j < _output_channels; ++j) {
+ for (size_t i = 0; i < static_cast<size_t>(_input_channels); ++i) {
+ for (int j = 0; j < static_cast<size_t>(_output_channels); ++j) {
digester.add (_gain[i][j]);
}
}
diff --git a/src/lib/cinema_sound_processor.cc b/src/lib/cinema_sound_processor.cc
index 1a3ba5a0f..9f1048274 100644
--- a/src/lib/cinema_sound_processor.cc
+++ b/src/lib/cinema_sound_processor.cc
@@ -107,8 +107,8 @@ CinemaSoundProcessor::as_index (CinemaSoundProcessor const * s)
CinemaSoundProcessor const *
CinemaSoundProcessor::from_index (int i)
{
- DCPOMATIC_ASSERT (i <= int(_cinema_sound_processors.size ()));
- return _cinema_sound_processors[i];
+ DCPOMATIC_ASSERT (i >= 0 && i < int(_cinema_sound_processors.size()));
+ return _cinema_sound_processors[static_cast<size_t>(i)];
}
float
diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc
index 2e052060e..93605b4c7 100644
--- a/src/lib/colour_conversion.cc
+++ b/src/lib/colour_conversion.cc
@@ -99,8 +99,8 @@ ColourConversion::ColourConversion (cxml::NodePtr node, int version)
/* Read in old <Matrix> nodes and convert them to chromaticities */
boost::numeric::ublas::matrix<double> C (3, 3);
for (list<cxml::NodePtr>::iterator i = m.begin(); i != m.end(); ++i) {
- int const ti = (*i)->number_attribute<int> ("i");
- int const tj = (*i)->number_attribute<int> ("j");
+ size_t const ti = (*i)->number_attribute<size_t>("i");
+ size_t const tj = (*i)->number_attribute<size_t>("j");
C(ti, tj) = raw_convert<double> ((*i)->content ());
}
diff --git a/src/lib/compose.hpp b/src/lib/compose.hpp
index 2c44f148b..37ad5efa1 100644
--- a/src/lib/compose.hpp
+++ b/src/lib/compose.hpp
@@ -152,7 +152,7 @@ namespace StringPrivate
// save string
output.push_back(fmt.substr(b, i - b));
- int n = 1; // number of digits
+ std::string::size_type n = 1; // number of digits
int spec_no = 0;
do {
diff --git a/src/lib/cross_linux.cc b/src/lib/cross_linux.cc
index 25fd3490e..c76293ce8 100644
--- a/src/lib/cross_linux.cc
+++ b/src/lib/cross_linux.cc
@@ -20,6 +20,7 @@
#include "cross.h"
#include "compose.hpp"
+#include "dcpomatic_assert.h"
#include "log.h"
#include "dcpomatic_log.h"
#include "config.h"
@@ -65,13 +66,15 @@ using boost::function;
void
dcpomatic_sleep_seconds (int s)
{
- sleep (s);
+ DCPOMATIC_ASSERT (s >= 0);
+ sleep (static_cast<unsigned int>(s));
}
void
dcpomatic_sleep_milliseconds (int ms)
{
- usleep (ms * 1000);
+ DCPOMATIC_ASSERT (ms >= 0);
+ usleep (static_cast<unsigned int>(ms) * 1000);
}
/** @return A string of CPU information (model name etc.) */
diff --git a/src/lib/dcpomatic_socket.cc b/src/lib/dcpomatic_socket.cc
index a0a7a1cf3..f2c8d12bf 100644
--- a/src/lib/dcpomatic_socket.cc
+++ b/src/lib/dcpomatic_socket.cc
@@ -79,7 +79,7 @@ Socket::connect (boost::asio::ip::tcp::endpoint endpoint)
* @param size Number of bytes to write.
*/
void
-Socket::write (uint8_t const * data, int size)
+Socket::write (uint8_t const * data, size_t size)
{
_deadline.expires_from_now (boost::posix_time::seconds (_timeout));
boost::system::error_code ec = boost::asio::error::would_block;
@@ -111,7 +111,7 @@ Socket::write (uint32_t v)
* @param size Number of bytes to read.
*/
void
-Socket::read (uint8_t* data, int size)
+Socket::read (uint8_t* data, size_t size)
{
_deadline.expires_from_now (boost::posix_time::seconds (_timeout));
boost::system::error_code ec = boost::asio::error::would_block;
@@ -200,7 +200,7 @@ bool
Socket::check_read_digest ()
{
DCPOMATIC_ASSERT (_read_digester);
- int const size = _read_digester->size ();
+ size_t const size = _read_digester->size ();
uint8_t ref[size];
_read_digester->get (ref);
@@ -220,7 +220,7 @@ void
Socket::finish_write_digest ()
{
DCPOMATIC_ASSERT (_write_digester);
- int const size = _write_digester->size();
+ size_t const size = _write_digester->size();
uint8_t buffer[size];
_write_digester->get (buffer);
diff --git a/src/lib/dcpomatic_socket.h b/src/lib/dcpomatic_socket.h
index 1fa0b046f..6f6f8cece 100644
--- a/src/lib/dcpomatic_socket.h
+++ b/src/lib/dcpomatic_socket.h
@@ -44,9 +44,9 @@ public:
void connect (boost::asio::ip::tcp::endpoint);
void write (uint32_t n);
- void write (uint8_t const * data, int size);
+ void write (uint8_t const * data, size_t size);
- void read (uint8_t* data, int size);
+ void read (uint8_t* data, size_t size);
uint32_t read_uint32 ();
class ReadDigestScope
diff --git a/src/lib/digester.cc b/src/lib/digester.cc
index 452452ba4..b2d2239e3 100644
--- a/src/lib/digester.cc
+++ b/src/lib/digester.cc
@@ -76,7 +76,7 @@ Digester::get (uint8_t* buffer) const
}
-int
+size_t
Digester::size () const
{
return MD5_DIGEST_SIZE;
diff --git a/src/lib/digester.h b/src/lib/digester.h
index 6cdaf2331..54626c10c 100644
--- a/src/lib/digester.h
+++ b/src/lib/digester.h
@@ -42,7 +42,7 @@ public:
void get (uint8_t* buffer) const;
- int size () const;
+ size_t size () const;
private:
mutable md5_ctx _context;
diff --git a/src/lib/edid.cc b/src/lib/edid.cc
index 3df65d325..bb078bb7f 100644
--- a/src/lib/edid.cc
+++ b/src/lib/edid.cc
@@ -78,7 +78,11 @@ get_monitors()
mon.manufacturer_product_code = (edid[11] << 8) | edid[10];
- mon.serial_number = (edid[15] << 24) | (edid[14] << 16) | (edid[13] << 8) | edid[12];
+ mon.serial_number = (static_cast<uint32_t>(edid[15]) << 24) |
+ (static_cast<uint32_t>(edid[14]) << 16) |
+ (static_cast<uint32_t>(edid[13]) << 8) |
+ static_cast<uint32_t>(edid[12]);
+
mon.week_of_manufacture = edid[16];
mon.year_of_manufacture = edid[17];
monitors.push_back (mon);
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index cfaf0361b..8cf68a208 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -420,7 +420,8 @@ FFmpegDecoder::decode_audio_packet ()
*/
AVPacket copy_packet = _packet;
- int const stream_index = copy_packet.stream_index;
+ DCPOMATIC_ASSERT (copy_packet.stream_index >= 0);
+ size_t const stream_index = static_cast<size_t>(copy_packet.stream_index);
/* XXX: inefficient */
vector<shared_ptr<FFmpegAudioStream> > streams = ffmpeg_content()->ffmpeg_audio_streams ();
@@ -645,8 +646,10 @@ FFmpegDecoder::decode_bitmap_subtitle (AVSubtitleRect const * rect, ContentTime
chosen by the user; created a `mapped' palette from those settings.
*/
map<RGBA, RGBA> colour_map = ffmpeg_content()->subtitle_stream()->colours ();
- vector<RGBA> mapped_palette (rect->nb_colors);
- for (int i = 0; i < rect->nb_colors; ++i) {
+ DCPOMATIC_ASSERT (rect->nb_colors);
+ size_t const colors = static_cast<size_t>(rect->nb_colors);
+ vector<RGBA> mapped_palette (colors);
+ for (size_t i = 0; i < colors; ++i) {
RGBA c (palette[2], palette[1], palette[0], palette[3]);
map<RGBA, RGBA>::const_iterator j = colour_map.find (c);
if (j != colour_map.end ()) {
diff --git a/src/lib/ffmpeg_image_proxy.cc b/src/lib/ffmpeg_image_proxy.cc
index db6059266..65c3ae29b 100644
--- a/src/lib/ffmpeg_image_proxy.cc
+++ b/src/lib/ffmpeg_image_proxy.cc
@@ -83,7 +83,7 @@ avio_seek_wrapper (void* data, int64_t offset, int whence)
int
FFmpegImageProxy::avio_read (uint8_t* buffer, int const amount)
{
- int const to_do = min(int64_t(amount), _data.size() - _pos);
+ size_t const to_do = min(static_cast<size_t>(amount), _data.size() - _pos);
if (to_do == 0) {
return AVERROR_EOF;
}
@@ -97,18 +97,22 @@ FFmpegImageProxy::avio_seek (int64_t const pos, int whence)
{
switch (whence) {
case AVSEEK_SIZE:
- return _data.size();
+ return static_cast<int64_t>(_data.size());
case SEEK_CUR:
- _pos += pos;
+ DCPOMATIC_ASSERT ((static_cast<int_64_t>(_pos) + pos) >= 0);
+ _pos = static_cast<size_t>(_pos + pos);
break;
case SEEK_SET:
- _pos = pos;
+ DCPOMATIC_ASSERT (pos >= 0);
+ _pos = static_cast<size_t>(pos);
break;
case SEEK_END:
- _pos = _data.size() - pos;
+ DCPOMATIC_ASSERT ((static_cast<int64_t>(_data.size()) - pos) >= 0);
+ _pos = static_cast<size_t>(_data.size() - pos);
break;
}
+ DCPOMATIC_ASSERT (_pos >= 0);
return _pos;
}
diff --git a/src/lib/ffmpeg_image_proxy.h b/src/lib/ffmpeg_image_proxy.h
index aa77003a4..139296d9b 100644
--- a/src/lib/ffmpeg_image_proxy.h
+++ b/src/lib/ffmpeg_image_proxy.h
@@ -44,7 +44,7 @@ public:
private:
dcp::Data _data;
- mutable int64_t _pos;
+ mutable size_t _pos;
/** Path of a file that this image came from, if applicable; stored so that
failed-decode errors can give more detail.
*/
diff --git a/src/lib/film.cc b/src/lib/film.cc
index cf7d04933..719a16f9c 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -1566,7 +1566,7 @@ Film::make_kdm (
/** @return The approximate disk space required to encode a DCP of this film with the
* current settings, in bytes.
*/
-uint64_t
+size_t
Film::required_disk_space () const
{
return _playlist->required_disk_space (shared_from_this(), j2k_bandwidth(), audio_channels(), audio_frame_rate());
diff --git a/src/lib/image.cc b/src/lib/image.cc
index 002c7df9a..e78358093 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -187,7 +187,8 @@ Image::crop_scale_window (
}
/* Prepare input data pointers with crop */
- uint8_t* scale_in_data[planes()];
+ DCPOMATIC_ASSERT (planes() > 0);
+ uint8_t* scale_in_data[static_cast<size_t>(planes())];
for (int c = 0; c < planes(); ++c) {
/* To work out the crop in bytes, start by multiplying
the crop by the (average) bytes per pixel. Then
@@ -206,7 +207,7 @@ Image::crop_scale_window (
throw PixelFormatError ("crop_scale_window()", out_format);
}
- uint8_t* scale_out_data[out->planes()];
+ uint8_t* scale_out_data[static_cast<size_t>(out->planes())];
for (int c = 0; c < out->planes(); ++c) {
/* See the note in the crop loop above */
int const x = lrintf (out->bytes_per_pixel(c) * corner.x) & ~ ((int) out_desc->log2_chroma_w);
@@ -302,9 +303,9 @@ Image::scale (dcp::Size out_size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_fo
void
Image::yuv_16_black (uint16_t v, bool alpha)
{
- memset (data()[0], 0, sample_size(0).height * stride()[0]);
+ memset (data()[0], 0, static_cast<size_t>(sample_size(0).height * stride()[0]));
for (int i = 1; i < 3; ++i) {
- int16_t* p = reinterpret_cast<int16_t*> (data()[i]);
+ uint16_t* p = reinterpret_cast<uint16_t*> (data()[i]);
int const lines = sample_size(i).height;
for (int y = 0; y < lines; ++y) {
/* We divide by 2 here because we are writing 2 bytes at a time */
@@ -316,7 +317,7 @@ Image::yuv_16_black (uint16_t v, bool alpha)
}
if (alpha) {
- memset (data()[3], 0, sample_size(3).height * stride()[3]);
+ memset (data()[3], 0, static_cast<size_t>(sample_size(3).height * stride()[3]));
}
}
@@ -345,7 +346,7 @@ Image::make_part_black (int x, int w)
int const s = stride()[0];
uint8_t* p = data()[0];
for (int y = 0; y < h; y++) {
- memset (p + x * bpp, 0, w * bpp);
+ memset (p + x * bpp, 0, static_cast<size_t>(w * bpp));
p += s;
}
break;
@@ -373,17 +374,17 @@ Image::make_black ()
case AV_PIX_FMT_YUV422P:
case AV_PIX_FMT_YUV444P:
case AV_PIX_FMT_YUV411P:
- memset (data()[0], 0, sample_size(0).height * stride()[0]);
- memset (data()[1], eight_bit_uv, sample_size(1).height * stride()[1]);
- memset (data()[2], eight_bit_uv, sample_size(2).height * stride()[2]);
+ memset (data()[0], 0, static_cast<size_t>(sample_size(0).height * stride()[0]));
+ memset (data()[1], eight_bit_uv, static_cast<size_t>(sample_size(1).height * stride()[1]));
+ memset (data()[2], eight_bit_uv, static_cast<size_t>(sample_size(2).height * stride()[2]));
break;
case AV_PIX_FMT_YUVJ420P:
case AV_PIX_FMT_YUVJ422P:
case AV_PIX_FMT_YUVJ444P:
- memset (data()[0], 0, sample_size(0).height * stride()[0]);
- memset (data()[1], eight_bit_uv + 1, sample_size(1).height * stride()[1]);
- memset (data()[2], eight_bit_uv + 1, sample_size(2).height * stride()[2]);
+ memset (data()[0], 0, static_cast<size_t>(sample_size(0).height * stride()[0]));
+ memset (data()[1], eight_bit_uv + 1, static_cast<size_t>(sample_size(1).height * stride()[1]));
+ memset (data()[2], eight_bit_uv + 1, static_cast<size_t>(sample_size(2).height * stride()[2]));
break;
case AV_PIX_FMT_YUV422P9LE:
@@ -456,7 +457,7 @@ Image::make_black ()
case AV_PIX_FMT_RGB48LE:
case AV_PIX_FMT_RGB48BE:
case AV_PIX_FMT_XYZ12LE:
- memset (data()[0], 0, sample_size(0).height * stride()[0]);
+ memset (data()[0], 0, static_cast<size_t>(sample_size(0).height * stride()[0]));
break;
case AV_PIX_FMT_UYVY422:
@@ -487,7 +488,7 @@ Image::make_transparent ()
throw PixelFormatError ("make_transparent()", _pixel_format);
}
- memset (data()[0], 0, sample_size(0).height * stride()[0]);
+ memset (data()[0], 0, static_cast<size_t>(sample_size(0).height * stride()[0]));
}
void
@@ -747,7 +748,7 @@ Image::copy (shared_ptr<const Image> other, Position<int> position)
for (int ty = position.y, oy = 0; ty < size().height && oy < other->size().height; ++ty, ++oy) {
uint8_t * const tp = data()[0] + ty * stride()[0] + position.x * 3;
uint8_t * const op = other->data()[0] + oy * other->stride()[0];
- memcpy (tp, op, N * 3);
+ memcpy (tp, op, static_cast<size_t>(N * 3));
}
}
@@ -758,7 +759,7 @@ Image::read_from_socket (shared_ptr<Socket> socket)
uint8_t* p = data()[i];
int const lines = sample_size(i).height;
for (int y = 0; y < lines; ++y) {
- socket->read (p, line_size()[i]);
+ socket->read (p, static_cast<size_t>(line_size()[i]));
p += stride()[i];
}
}
@@ -771,7 +772,7 @@ Image::write_to_socket (shared_ptr<Socket> socket) const
uint8_t* p = data()[i];
int const lines = sample_size(i).height;
for (int y = 0; y < lines; ++y) {
- socket->write (p, line_size()[i]);
+ socket->write (p, static_cast<size_t>(line_size()[i]));
p += stride()[i];
}
}
@@ -891,7 +892,7 @@ Image::allocate ()
|XXXwrittenXXX|<------line-size------------->|XXXwrittenXXXXXXwrittenXXX
^^^^ out of bounds
*/
- _data[i] = (uint8_t *) wrapped_av_malloc (_stride[i] * (sample_size(i).height + 1) + 32);
+ _data[i] = (uint8_t *) wrapped_av_malloc (static_cast<size_t>(_stride[i] * (sample_size(i).height + 1) + 32));
#if HAVE_VALGRIND_MEMCHECK_H
/* The data between the end of the line size and the stride is undefined but processed by
libswscale, causing lots of valgrind errors. Mark it all defined to quell these errors.
@@ -914,7 +915,7 @@ Image::Image (Image const & other)
uint8_t* q = other._data[i];
int const lines = sample_size(i).height;
for (int j = 0; j < lines; ++j) {
- memcpy (p, q, _line_size[i]);
+ memcpy (p, q, static_cast<size_t>(_line_size[i]));
p += stride()[i];
q += other.stride()[i];
}
@@ -933,7 +934,7 @@ Image::Image (AVFrame* frame)
uint8_t* q = frame->data[i];
int const lines = sample_size(i).height;
for (int j = 0; j < lines; ++j) {
- memcpy (p, q, _line_size[i]);
+ memcpy (p, q, static_cast<size_t>(_line_size[i]));
p += stride()[i];
/* AVFrame's linesize is what we call `stride' */
q += frame->linesize[i];
@@ -954,7 +955,7 @@ Image::Image (shared_ptr<const Image> other, bool aligned)
uint8_t* q = other->data()[i];
int const lines = sample_size(i).height;
for (int j = 0; j < lines; ++j) {
- memcpy (p, q, line_size()[i]);
+ memcpy (p, q, static_cast<size_t>(line_size()[i]));
p += stride()[i];
q += other->stride()[i];
}
@@ -1071,7 +1072,7 @@ operator== (Image const & a, Image const & b)
uint8_t* q = b.data()[c];
int const lines = a.sample_size(c).height;
for (int y = 0; y < lines; ++y) {
- if (memcmp (p, q, a.line_size()[c]) != 0) {
+ if (memcmp(p, q, static_cast<size_t>(a.line_size()[c])) != 0) {
return false;
}
@@ -1218,7 +1219,7 @@ Image::memory_used () const
{
size_t m = 0;
for (int i = 0; i < planes(); ++i) {
- m += _stride[i] * sample_size(i).height;
+ m += static_cast<size_t>(_stride[i] * sample_size(i).height);
}
return m;
}
@@ -1303,9 +1304,13 @@ Image::as_png () const
throw EncodeError (N_("could not create PNG info struct"));
}
- png_set_IHDR (png_ptr, info_ptr, size().width, size().height, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+ png_set_IHDR (
+ png_ptr, info_ptr,
+ static_cast<png_uint_32>(size().width), static_cast<png_uint_32>(size().height),
+ 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT
+ );
- png_byte ** row_pointers = reinterpret_cast<png_byte **>(png_malloc(png_ptr, size().height * sizeof(png_byte *)));
+ png_byte ** row_pointers = reinterpret_cast<png_byte **>(png_malloc(png_ptr, static_cast<size_t>(size().height) * sizeof(png_byte *)));
for (int i = 0; i < size().height; ++i) {
row_pointers[i] = (png_byte *) (data()[0] + i * stride()[0]);
}
diff --git a/src/lib/image_decoder.cc b/src/lib/image_decoder.cc
index 15187b11b..4052d8c2f 100644
--- a/src/lib/image_decoder.cc
+++ b/src/lib/image_decoder.cc
@@ -55,7 +55,8 @@ ImageDecoder::pass ()
if (!_image_content->still() || !_image) {
/* Either we need an image or we are using moving images, so load one */
- boost::filesystem::path path = _image_content->path (_image_content->still() ? 0 : _frame_video_position);
+ DCPOMATIC_ASSERT (_frame_video_position >= 0);
+ boost::filesystem::path path = _image_content->path (_image_content->still() ? 0 : static_cast<size_t>(_frame_video_position));
if (valid_j2k_file (path)) {
AVPixelFormat pf;
if (_image_content->video->colour_conversion()) {
diff --git a/src/lib/image_examiner.cc b/src/lib/image_examiner.cc
index 6586a0d09..1a949381d 100644
--- a/src/lib/image_examiner.cc
+++ b/src/lib/image_examiner.cc
@@ -70,7 +70,7 @@ ImageExaminer::ImageExaminer (shared_ptr<const Film> film, shared_ptr<const Imag
if (content->still ()) {
_video_length = Config::instance()->default_still_length() * video_frame_rate().get_value_or (film->video_frame_rate ());
} else {
- _video_length = _image_content->number_of_paths ();
+ _video_length = static_cast<Frame>(_image_content->number_of_paths());
}
}
diff --git a/src/lib/image_filename_sorter.cc b/src/lib/image_filename_sorter.cc
index 47f46e81d..aeb19917c 100644
--- a/src/lib/image_filename_sorter.cc
+++ b/src/lib/image_filename_sorter.cc
@@ -36,8 +36,8 @@ ImageFilenameSorter::operator() (boost::filesystem::path a, boost::filesystem::p
string an = extract_numbers (a);
string bn = extract_numbers (b);
- int const anl = an.length ();
- int const bnl = bn.length ();
+ size_t const anl = an.length ();
+ size_t const bnl = bn.length ();
if (anl > bnl) {
bn = string(anl - bnl, '0') + bn;
diff --git a/src/lib/internet.cc b/src/lib/internet.cc
index 943363d1a..c18b3a6e6 100644
--- a/src/lib/internet.cc
+++ b/src/lib/internet.cc
@@ -185,7 +185,12 @@ get_from_zip_url (string url, string file, bool pasv, bool skip_pasv_ip, functio
char buffer[4096];
while (true) {
int const N = zip_fread (file_in_zip, buffer, sizeof (buffer));
- checked_fwrite (buffer, N, f, temp_cert.file());
+ if (N == -1) {
+ zip_fclose (file_in_zip);
+ zip_close (zip);
+ return optional<string>(_("Could not read from ZIP file"));
+ }
+ checked_fwrite (buffer, static_cast<size_t>(N), f, temp_cert.file());
if (N < int (sizeof (buffer))) {
break;
}
diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc
index acf8bb052..29b50a577 100644
--- a/src/lib/j2k_image_proxy.cc
+++ b/src/lib/j2k_image_proxy.cc
@@ -108,7 +108,7 @@ J2KImageProxy::J2KImageProxy (shared_ptr<cxml::Node> xml, shared_ptr<Socket> soc
if (xml->optional_number_child<int> ("Eye")) {
_eye = static_cast<dcp::Eye> (xml->number_child<int> ("Eye"));
}
- _data = Data (xml->number_child<int> ("Size"));
+ _data = Data (xml->number_child<size_t>("Size"));
/* This only matters when we are using J2KImageProxy for the preview, which
will never use this constructor (which is only used for passing data to
encode servers). So we can put anything in here. It's a bit of a hack.
@@ -238,7 +238,7 @@ J2KImageProxy::memory_used () const
size_t m = _data.size();
if (_image) {
/* 3 components, 16-bits per pixel */
- m += 3 * 2 * _image->size().width * _image->size().height;
+ m += static_cast<size_t>(3 * 2 * _image->size().width * _image->size().height);
}
return m;
}
diff --git a/src/lib/kdm_with_metadata.cc b/src/lib/kdm_with_metadata.cc
index 0ef1b8f38..7c7c95f44 100644
--- a/src/lib/kdm_with_metadata.cc
+++ b/src/lib/kdm_with_metadata.cc
@@ -142,7 +142,7 @@ write_directories (
function<bool (boost::filesystem::path)> confirm_overwrite
)
{
- int written = 0;
+ size_t written = 0;
BOOST_FOREACH (list<KDMWithMetadataPtr> const & i, kdms) {
boost::filesystem::path path = directory;
@@ -154,7 +154,7 @@ write_directories (
written += i.size();
}
- return written;
+ return static_cast<int>(written);
}
@@ -168,7 +168,7 @@ write_zip_files (
function<bool (boost::filesystem::path)> confirm_overwrite
)
{
- int written = 0;
+ size_t written = 0;
BOOST_FOREACH (list<KDMWithMetadataPtr> const & i, kdms) {
boost::filesystem::path path = directory;
@@ -183,7 +183,7 @@ write_zip_files (
}
}
- return written;
+ return static_cast<size_t>(written);
}
diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc
index b96b0fbe0..30045e2e4 100644
--- a/src/lib/playlist.cc
+++ b/src/lib/playlist.cc
@@ -625,20 +625,22 @@ Playlist::move_later (shared_ptr<const Film> film, shared_ptr<Content> c)
c->set_position (film, c->position() + next_c->length_after_trim(film));
}
-int64_t
+size_t
Playlist::required_disk_space (shared_ptr<const Film> film, int j2k_bandwidth, int audio_channels, int audio_frame_rate) const
{
- int64_t video = uint64_t (j2k_bandwidth / 8) * length(film).seconds();
- int64_t audio = uint64_t (audio_channels * audio_frame_rate * 3) * length(film).seconds();
+ size_t video = static_cast<size_t>(j2k_bandwidth / 8) * length(film).seconds();
+ size_t audio = static_cast<size_t>(audio_channels * audio_frame_rate * 3) * length(film).seconds();
BOOST_FOREACH (shared_ptr<Content> i, content()) {
shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (i);
if (d) {
+ DCPTime const len = d->length_after_trim(film);
+ DCPOMATIC_ASSERT (len.get() >= 0);
if (d->reference_video()) {
- video -= uint64_t (j2k_bandwidth / 8) * d->length_after_trim(film).seconds();
+ video -= static_cast<size_t>(j2k_bandwidth / 8) * len.seconds();
}
if (d->reference_audio()) {
- audio -= uint64_t (audio_channels * audio_frame_rate * 3) * d->length_after_trim(film).seconds();
+ audio -= static_cast<size_t>(audio_channels * audio_frame_rate * 3) * len.seconds();
}
}
}
diff --git a/src/lib/playlist.h b/src/lib/playlist.h
index 51c13e33f..704a91eac 100644
--- a/src/lib/playlist.h
+++ b/src/lib/playlist.h
@@ -61,7 +61,7 @@ public:
dcpomatic::DCPTime length (boost::shared_ptr<const Film> film) const;
boost::optional<dcpomatic::DCPTime> start () const;
- int64_t required_disk_space (boost::shared_ptr<const Film> film, int j2k_bandwidth, int audio_channels, int audio_frame_rate) const;
+ size_t required_disk_space (boost::shared_ptr<const Film> film, int j2k_bandwidth, int audio_channels, int audio_frame_rate) const;
int best_video_frame_rate () const;
dcpomatic::DCPTime video_end (boost::shared_ptr<const Film> film) const;
diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc
index 770130798..17041f96a 100644
--- a/src/lib/reel_writer.cc
+++ b/src/lib/reel_writer.cc
@@ -766,7 +766,7 @@ ReelWriter::existing_picture_frame_ok (FILE* asset_file, shared_ptr<InfoFileHand
bool ok = true;
/* Read the data from the asset and hash it */
- dcpomatic_fseek (asset_file, info.offset, SEEK_SET);
+ dcpomatic_fseek (asset_file, static_cast<int64_t>(info.offset), SEEK_SET);
Data data (info.size);
size_t const read = fread (data.data().get(), 1, data.size(), asset_file);
LOG_GENERAL ("Read %1 bytes of asset data; wanted %2", read, info.size);
diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc
index de33f9380..347125712 100644
--- a/src/lib/render_text.cc
+++ b/src/lib/render_text.cc
@@ -24,10 +24,13 @@
#include "cross.h"
#include "font.h"
#include "dcpomatic_assert.h"
+#include "warnings.h"
#include <dcp/raw_convert.h>
#include <fontconfig/fontconfig.h>
+DCPOMATIC_DISABLE_WARNINGS
#include <cairomm/cairomm.h>
#include <pangomm.h>
+DCPOMATIC_ENABLE_WARNINGS
#include <pango/pangocairo.h>
#ifndef DCPOMATIC_HAVE_SHOW_IN_CAIRO_CONTEXT
#include <pango/pangocairo.h>
diff --git a/src/lib/video_ring_buffers.cc b/src/lib/video_ring_buffers.cc
index bfec507ea..92f26540d 100644
--- a/src/lib/video_ring_buffers.cc
+++ b/src/lib/video_ring_buffers.cc
@@ -57,7 +57,7 @@ Frame
VideoRingBuffers::size () const
{
boost::mutex::scoped_lock lm (_mutex);
- return _data.size ();
+ return static_cast<Frame>(_data.size());
}
bool
diff --git a/src/lib/warnings.h b/src/lib/warnings.h
new file mode 100644
index 000000000..c9ecdb19f
--- /dev/null
+++ b/src/lib/warnings.h
@@ -0,0 +1,27 @@
+/*
+ Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#define DCPOMATIC_DISABLE_WARNINGS \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wsign-conversion\"")
+ _Pragma("GCC diagnostic ignored \"-Wcast-function-type\"")
+
+#define DCPOMATIC_ENABLE_WARNINGS \
+ _Pragma("GCC diagnostic pop")