Ticket #3927: mythsoap-null-terminate.patch

File mythsoap-null-terminate.patch, 1.2 KB (added by dburr@…, 18 years ago)

NULL terminate data returned from mythsoap

  • mythmovies/ignyte/mythsoap.cpp

     
    1 #include <mythtv/mythcontext.h>
    2 
    31#include "mythsoap.h"
     2#include <iostream>
    43
    54void MythSoap::doSoapRequest(QString host, QString path, QString soapAction,
    65                             QString query)
     
    3534
    3635void MythSoap::httpDone(bool error)
    3736{
     37    using namespace std;
    3838    if (error)
    3939    {
    4040        cerr << "Error in mythsoap.o retrieving data: " << http.errorString() << endl << flush;
    4141    }
    4242    else
    4343    {
    44         m_data = http.readAll();
    45         //cout << "Data: " << m_data.data() << endl << flush;
     44        const Q_ULONG len = http.bytesAvailable();
     45        // QMemArray::assign() will own this so we don't have to delete it
     46        char* buffer = new char[len + 1];
     47        if(buffer) {
     48            http.readBlock(buffer, len);
     49            buffer[len] = '\0';
     50            m_data.assign(buffer, len + 1);
     51            //cout << "Data: " << m_data.data() << endl << flush;
     52        } else {
     53            cerr << "Failed to alloc memory in mythsoap.o" << endl;
     54        }
    4655    }
    4756    m_done = true;
    4857}