mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-07 21:03:57 +00:00
cleanup: don't NUL-terminate membuffer in uploadDiveLogsDE
The data of the membuffer is passed as a data/length pair to xmlReadMemory(). There is no point in NUL-terminating it. Moreover, pass the data directly to xmlReadMemory() instead of via variables. These variables are reused later with a different meaning, making this super-confusing. The membuf variable is turned from "const char *" to "char *" to signal that we own the buffer. Amazingly, zip_source_buffer() frees the buffer, even though a "const void *" is passed in. This API is pure madness. Add a comment. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
69914964f6
commit
b18b3119b5
1 changed files with 3 additions and 5 deletions
|
@ -94,7 +94,7 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected)
|
||||||
for_each_dive (i, dive) {
|
for_each_dive (i, dive) {
|
||||||
char filename[PATH_MAX];
|
char filename[PATH_MAX];
|
||||||
int streamsize;
|
int streamsize;
|
||||||
const char *membuf;
|
char *membuf;
|
||||||
xmlDoc *transformed;
|
xmlDoc *transformed;
|
||||||
struct zip_source *s;
|
struct zip_source *s;
|
||||||
struct membufferpp mb;
|
struct membufferpp mb;
|
||||||
|
@ -137,14 +137,12 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected)
|
||||||
if (ds) {
|
if (ds) {
|
||||||
put_format(&mb, "</divelog>\n");
|
put_format(&mb, "</divelog>\n");
|
||||||
}
|
}
|
||||||
membuf = mb_cstring(&mb);
|
|
||||||
streamsize = mb.len;
|
|
||||||
/*
|
/*
|
||||||
* Parse the memory buffer into XML document and
|
* Parse the memory buffer into XML document and
|
||||||
* transform it to divelogs.de format, finally dumping
|
* transform it to divelogs.de format, finally dumping
|
||||||
* the XML into a character buffer.
|
* the XML into a character buffer.
|
||||||
*/
|
*/
|
||||||
xmlDoc *doc = xmlReadMemory(membuf, streamsize, "divelog", NULL, 0);
|
xmlDoc *doc = xmlReadMemory(mb.buffer, mb.len, "divelog", NULL, 0);
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
qWarning() << errPrefix << "could not parse back into memory the XML file we've just created!";
|
qWarning() << errPrefix << "could not parse back into memory the XML file we've just created!";
|
||||||
report_error(tr("internal error").toUtf8());
|
report_error(tr("internal error").toUtf8());
|
||||||
|
@ -171,7 +169,7 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected)
|
||||||
* Save the XML document into a zip file.
|
* Save the XML document into a zip file.
|
||||||
*/
|
*/
|
||||||
snprintf(filename, PATH_MAX, "%d.xml", i + 1);
|
snprintf(filename, PATH_MAX, "%d.xml", i + 1);
|
||||||
s = zip_source_buffer(zip, membuf, streamsize, 1);
|
s = zip_source_buffer(zip, membuf, streamsize, 1); // frees membuffer!
|
||||||
if (s) {
|
if (s) {
|
||||||
int64_t ret = zip_add(zip, filename, s);
|
int64_t ret = zip_add(zip, filename, s);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue