fix buffering issue in the LCP profile parser (issue #3788)
This commit is contained in:
@@ -678,7 +678,9 @@ void XMLCALL LCPProfile::XmlStartHandler(void *pLCPProfile, const char *el, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pProf->lastTag, nameStart);
|
strcpy(pProf->lastTag, nameStart);
|
||||||
XmlTextHandler(pLCPProfile, attr[i + 1], strlen(attr[i + 1]));
|
|
||||||
|
pProf->handle_text(attr[i+1]);
|
||||||
|
//XmlTextHandler(pLCPProfile, attr[i + 1], strlen(attr[i + 1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -690,24 +692,33 @@ void XMLCALL LCPProfile::XmlTextHandler(void *pLCPProfile, const XML_Char *s, in
|
|||||||
if (!pProf->inCamProfiles || pProf->inAlternateLensID || pProf->inAlternateLensNames || *pProf->inInvalidTag) {
|
if (!pProf->inCamProfiles || pProf->inAlternateLensID || pProf->inAlternateLensNames || *pProf->inInvalidTag) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < len; ++i) {
|
||||||
|
pProf->textbuf << s[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LCPProfile::handle_text(std::string text)
|
||||||
|
{
|
||||||
|
const char *raw = text.c_str();
|
||||||
|
|
||||||
// Check if it contains non-whitespaces (there are several calls to this for one tag unfortunately)
|
// Check if it contains non-whitespaces (there are several calls to this for one tag unfortunately)
|
||||||
bool onlyWhiteSpace = true;
|
bool onlyWhiteSpace = true;
|
||||||
int i = 0;
|
for (size_t i = 0; i < text.size(); ++i) {
|
||||||
|
if (!isspace(text[i])) {
|
||||||
while (i < len && onlyWhiteSpace) {
|
onlyWhiteSpace = false;
|
||||||
onlyWhiteSpace = isspace(s[i]);
|
break;
|
||||||
i++;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onlyWhiteSpace) {
|
if (onlyWhiteSpace) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LCPProfile *pProf = this;
|
||||||
|
|
||||||
// convert to null terminated
|
// convert to null terminated
|
||||||
char raw[len + 1];
|
|
||||||
memcpy(raw, s, len);
|
|
||||||
raw[len] = 0;
|
|
||||||
char* tag = pProf->lastTag;
|
char* tag = pProf->lastTag;
|
||||||
|
|
||||||
// Common data section
|
// Common data section
|
||||||
@@ -732,15 +743,12 @@ void XMLCALL LCPProfile::XmlTextHandler(void *pLCPProfile, const XML_Char *s, in
|
|||||||
// WARNING: called by different threads, that may run on different local settings,
|
// WARNING: called by different threads, that may run on different local settings,
|
||||||
// so don't use system params
|
// so don't use system params
|
||||||
if (atof("1,2345") == 1.2345) {
|
if (atof("1,2345") == 1.2345) {
|
||||||
char* p = raw;
|
for (size_t i = 0; i < text.size(); ++i) {
|
||||||
|
if (text[i] == '.') {
|
||||||
while (*p) {
|
text[i] = ',';
|
||||||
if (*p == '.') {
|
|
||||||
*p = ',';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p++;
|
|
||||||
}
|
}
|
||||||
|
raw = text.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pProf->firstLIDone) {
|
if (!pProf->firstLIDone) {
|
||||||
@@ -789,6 +797,9 @@ void XMLCALL LCPProfile::XmlEndHandler(void *pLCPProfile, const char *el)
|
|||||||
{
|
{
|
||||||
LCPProfile *pProf = static_cast<LCPProfile*>(pLCPProfile);
|
LCPProfile *pProf = static_cast<LCPProfile*>(pLCPProfile);
|
||||||
|
|
||||||
|
pProf->handle_text(pProf->textbuf.str());
|
||||||
|
pProf->textbuf.str("");
|
||||||
|
|
||||||
// We ignore everything in dirty tag till it's gone
|
// We ignore everything in dirty tag till it's gone
|
||||||
if (*pProf->inInvalidTag) {
|
if (*pProf->inInvalidTag) {
|
||||||
if (strstr(el, pProf->inInvalidTag)) {
|
if (strstr(el, pProf->inInvalidTag)) {
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <glibmm.h>
|
#include <glibmm.h>
|
||||||
#include <expat.h>
|
#include <expat.h>
|
||||||
@@ -94,6 +95,9 @@ class LCPProfile
|
|||||||
|
|
||||||
int filterBadFrames(double maxAvgDevFac, int minFramesLeft);
|
int filterBadFrames(double maxAvgDevFac, int minFramesLeft);
|
||||||
|
|
||||||
|
void handle_text(std::string text);
|
||||||
|
std::ostringstream textbuf;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Common data
|
// Common data
|
||||||
Glib::ustring profileName, lensPrettyName, cameraPrettyName, lens, camera; // lens/camera(=model) can be auto-matched with DNG
|
Glib::ustring profileName, lensPrettyName, cameraPrettyName, lens, camera; // lens/camera(=model) can be auto-matched with DNG
|
||||||
|
Reference in New Issue
Block a user