'libs/ardour' - Use 'std::vector' instead of dynamically sized arrays (required to...
authorJohn Emmas <johne53@tiscali.co.uk>
Sun, 4 Aug 2013 14:17:19 +0000 (15:17 +0100)
committerJohn Emmas <johne53@tiscali.co.uk>
Sun, 4 Aug 2013 14:17:19 +0000 (15:17 +0100)
libs/ardour/broadcast_info.cc
libs/ardour/export_graph_builder.cc
libs/ardour/io.cc
libs/ardour/ladspa_plugin.cc
libs/ardour/lv2_plugin.cc
libs/ardour/region_factory.cc
libs/ardour/sndfilesource.cc

index 78c6132f851cb90a42d801e65efe104322cef10d..a08d2c7991c6b0044bea6625b0a7c969db05066b 100644 (file)
@@ -22,6 +22,7 @@
 #include <iostream>
 #include <sstream>
 #include <iomanip>
+#include <vector>
 
 #include <glibmm.h>
 
@@ -37,15 +38,15 @@ namespace ARDOUR
 static void
 snprintf_bounded_null_filled (char* target, size_t target_size, char const * fmt, ...)
 {
-       char buf[target_size+1];
+       std::vector<char> buf(target_size+1);
        va_list ap;
 
        va_start (ap, fmt);
-       vsnprintf (buf, target_size+1, fmt, ap);
+       vsnprintf (&buf[0], target_size+1, fmt, ap);
        va_end (ap);
 
        memset (target, 0, target_size);
-       memcpy (target, buf, target_size);
+       memcpy (target, &buf[0], target_size);
 
 }
 
index c7875c0b9b62ab1429f2e5ce23cc93d830f42f9d..127546e8fc9af86b94c6739811a7169b2c7ae772 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "ardour/export_graph_builder.h"
 
+#include <vector>
+
 #include <glibmm/miscutils.h>
 
 #include "audiographer/process_context.h"
@@ -317,8 +319,8 @@ ExportGraphBuilder::Normalizer::Normalizer (ExportGraphBuilder & parent, FileSpe
 {
        std::string tmpfile_path = parent.session.session_directory().export_path();
        tmpfile_path = Glib::build_filename(tmpfile_path, "XXXXXX");
-       char tmpfile_path_buf[tmpfile_path.size() + 1];
-       std::copy(tmpfile_path.begin(), tmpfile_path.end(), tmpfile_path_buf);
+       std::vector<char> tmpfile_path_buf(tmpfile_path.size() + 1);
+       std::copy(tmpfile_path.begin(), tmpfile_path.end(), tmpfile_path_buf.begin());
        tmpfile_path_buf[tmpfile_path.size()] = '\0';
 
        config = new_config;
@@ -334,7 +336,7 @@ ExportGraphBuilder::Normalizer::Normalizer (ExportGraphBuilder & parent, FileSpe
        normalizer->add_output (threader);
 
        int format = ExportFormatBase::F_RAW | ExportFormatBase::SF_Float;
-       tmp_file.reset (new TmpFile<float> (tmpfile_path_buf, format, channels, config.format->sample_rate()));
+       tmp_file.reset (new TmpFile<float> (&tmpfile_path_buf[0], format, channels, config.format->sample_rate()));
        tmp_file->FileWritten.connect_same_thread (post_processing_connection,
                                                   boost::bind (&Normalizer::start_post_processing, this));
 
index 1349d49a0ce1c36667c4cff1b57f151ebd188778..4498e4fbd87759d61d07f610c79f03e1f42be923 100644 (file)
@@ -19,6 +19,7 @@
 #include <fstream>
 #include <algorithm>
 #include <cmath>
+#include <vector>
 
 #include <unistd.h>
 #include <locale.h>
@@ -1379,20 +1380,20 @@ IO::build_legal_port_name (DataType type)
 
        limit = name_size - _session.engine().client_name().length() - (suffix.length() + 5);
 
-       char buf1[name_size+1];
-       char buf2[name_size+1];
+       std::vector<char> buf1(name_size+1);
+       std::vector<char> buf2(name_size+1);
 
        /* colons are illegal in port names, so fix that */
 
        string nom = _name.val();
        replace_all (nom, ":", ";");
 
-       snprintf (buf1, name_size+1, ("%.*s/%s"), limit, nom.c_str(), suffix.c_str());
+       snprintf (&buf1[0], name_size+1, ("%.*s/%s"), limit, nom.c_str(), suffix.c_str());
 
-       int port_number = find_port_hole (buf1);
-       snprintf (buf2, name_size+1, "%s %d", buf1, port_number);
+       int port_number = find_port_hole (&buf1[0]);
+       snprintf (&buf2[0], name_size+1, "%s %d", buf1, port_number);
 
-       return string (buf2);
+       return string (&buf2[0]);
 }
 
 int32_t
@@ -1410,13 +1411,13 @@ IO::find_port_hole (const char* base)
         */
 
        for (n = 1; n < 9999; ++n) {
-               char buf[jack_port_name_size()];
+               std::vector<char> buf(jack_port_name_size());
                PortSet::iterator i = _ports.begin();
 
-               snprintf (buf, jack_port_name_size(), _("%s %u"), base, n);
+               snprintf (&buf[0], jack_port_name_size(), _("%s %u"), base, n);
 
                for ( ; i != _ports.end(); ++i) {
-                       if (i->name() == buf) {
+                       if (string(i->name()) == string(&buf[0])) {
                                break;
                        }
                }
index 38d0d8b9447860d33c8de6abe2b9e64e67583156..c78d8a28ddea85da5026ade4abf5fa75ceacce63 100644 (file)
@@ -919,8 +919,8 @@ LadspaPlugin::do_save_preset (string name)
 
        lrdf_defaults defaults;
        defaults.count = input_parameter_pids.size ();
-       lrdf_portvalue portvalues[input_parameter_pids.size()];
-       defaults.items = portvalues;
+       std::vector<lrdf_portvalue> portvalues(input_parameter_pids.size());
+       defaults.items = &portvalues[0];
 
        for (vector<int>::size_type i = 0; i < input_parameter_pids.size(); ++i) {
                portvalues[i].pid = input_parameter_pids[i];
index 04012a7ada8bd7224f0c849c8aa02518c9284d2a..4f1f9b96776deb4fbecab1baa3efcb5540a6dcd6 100644 (file)
@@ -1119,16 +1119,16 @@ LV2Plugin::write_to(RingBuffer<uint8_t>* dest,
                     uint32_t             size,
                     const uint8_t*       body)
 {
-       const uint32_t buf_size = sizeof(UIMessage) + size;
-       uint8_t        buf[buf_size];
+       const uint32_t  buf_size = sizeof(UIMessage) + size;
+       vector<uint8_t> buf(buf_size);
 
-       UIMessage* msg = (UIMessage*)buf;
+       UIMessage* msg = (UIMessage*)&buf[0];
        msg->index    = index;
        msg->protocol = protocol;
        msg->size     = size;
        memcpy(msg + 1, body, size);
 
-       return (dest->write(buf, buf_size) == buf_size);
+       return (dest->write(&buf[0], buf_size) == buf_size);
 }
 
 bool
@@ -1185,13 +1185,13 @@ LV2Plugin::emit_to_ui(void* controller, UIMessageSink sink)
                        error << "Error reading from Plugin=>UI RingBuffer" << endmsg;
                        break;
                }
-               uint8_t body[msg.size];
-               if (_to_ui->read(body, msg.size) != msg.size) {
+               vector<uint8_t> body(msg.size);
+               if (_to_ui->read(&body[0], msg.size) != msg.size) {
                        error << "Error reading from Plugin=>UI RingBuffer" << endmsg;
                        break;
                }
 
-               sink(controller, msg.index, msg.size, msg.protocol, body);
+               sink(controller, msg.index, msg.size, msg.protocol, &body[0]);
 
                read_space -= sizeof(msg) + msg.size;
        }
@@ -1671,15 +1671,15 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
                                error << "Error reading from UI=>Plugin RingBuffer" << endmsg;
                                break;
                        }
-                       uint8_t body[msg.size];
-                       if (_from_ui->read(body, msg.size) != msg.size) {
+                       vector<uint8_t> body(msg.size);
+                       if (_from_ui->read(&body[0], msg.size) != msg.size) {
                                error << "Error reading from UI=>Plugin RingBuffer" << endmsg;
                                break;
                        }
                        if (msg.protocol == urids.atom_eventTransfer) {
                                LV2_Evbuf*            buf  = _ev_buffers[msg.index];
                                LV2_Evbuf_Iterator    i    = lv2_evbuf_end(buf);
-                               const LV2_Atom* const atom = (const LV2_Atom*)body;
+                               const LV2_Atom* const atom = (const LV2_Atom*)&body[0];
                                if (!lv2_evbuf_write(&i, nframes, 0, atom->type, atom->size,
                                                (const uint8_t*)(atom + 1))) {
                                        error << "Failed to write data to LV2 event buffer\n";
index 3e815247504ee3cab21387c2a47877853f0054fd..44f8c34ddd3be482fd5377805f83bce3371ae571 100644 (file)
@@ -564,7 +564,7 @@ RegionFactory::new_region_name (string old)
        uint32_t number;
        string::size_type len = old.length() + 64;
        string remainder;
-       char buf[len];
+       std::vector<char> buf(len);
 
        if ((last_period = old.find_last_of ('.')) == string::npos) {
 
@@ -603,8 +603,8 @@ RegionFactory::new_region_name (string old)
 
                number++;
 
-               snprintf (buf, len, "%s%" PRIu32 "%s", old.substr (0, last_period + 1).c_str(), number, remainder.c_str());
-               sbuf = buf;
+               snprintf (&buf[0], len, "%s%" PRIu32 "%s", old.substr (0, last_period + 1).c_str(), number, remainder.c_str());
+               sbuf = &buf[0];
 
                if (region_name_map.find (sbuf) == region_name_map.end ()) {
                        break;
@@ -612,7 +612,7 @@ RegionFactory::new_region_name (string old)
        }
 
        if (number != (UINT_MAX-1)) {
-               return buf;
+               return &buf[0];
        }
 
        error << string_compose (_("cannot create new name for region \"%1\""), old) << endmsg;
index f29682aeaa7e27aa918835d23c4ab190af608b93..2aae84085a42bb2d54471ded483407768875bd43 100644 (file)
@@ -766,12 +766,12 @@ SndFileSource::crossfade (Sample* data, framecnt_t cnt, int fade_in)
 
        } else if (xfade < xfade_frames) {
 
-               gain_t in[xfade];
-               gain_t out[xfade];
+               std::vector<gain_t> in(xfade);
+               std::vector<gain_t> out(xfade);
 
                /* short xfade, compute custom curve */
 
-               compute_equal_power_fades (xfade, in, out);
+               compute_equal_power_fades (xfade, &in[0], &out[0]);
 
                for (framecnt_t n = 0; n < xfade; ++n) {
                        xfade_buf[n] = (xfade_buf[n] * out[n]) + (fade_data[n] * in[n]);