mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: turn a memblock in the parser to std::string
This avoid memory-management troubles. Had to convert a few of the parsers (cochran, datatrak, liquivision) to C++. Also had to convert libdivecomputer.c. This was less painful than expected. std::string is used because parts of the code assumes that the data is null terminated after the last character of the data. std::string does precisely that. One disadvantage is that std::string clears its memory when resizing / initializing. Thus we read the file onto freshly cleared data, which some might thing is a performance regression. Until someone shows me that this matters, I don't care. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
615dd376f3
commit
c9a10733d3
12 changed files with 233 additions and 285 deletions
|
@ -41,8 +41,8 @@ static const struct models_table_t g_models[] = {
|
|||
{0xEE, 0x44, "Uwatec Unknown model", DC_FAMILY_UWATEC_ALADIN},
|
||||
};
|
||||
|
||||
#define JUMP(_ptr, _n) if ((long) (_ptr += _n) > maxbuf) goto bail
|
||||
#define CHECK(_ptr, _n) if ((long) _ptr + _n > maxbuf) goto bail
|
||||
#define JUMP(_ptr, _n) if ((char *) (_ptr += _n) > (char *)maxbuf) goto bail
|
||||
#define CHECK(_ptr, _n) if ((char *) _ptr + _n > (char *)maxbuf) goto bail
|
||||
#define read_bytes(_n) \
|
||||
switch (_n) { \
|
||||
case 1: \
|
||||
|
@ -62,10 +62,12 @@ static const struct models_table_t g_models[] = {
|
|||
|
||||
#define read_string(_property) \
|
||||
CHECK(membuf, tmp_1byte); \
|
||||
{ \
|
||||
unsigned char *_property##tmp = (unsigned char *)calloc(tmp_1byte + 1, 1); \
|
||||
_property##tmp = memcpy(_property##tmp, membuf, tmp_1byte);\
|
||||
_property##tmp = (unsigned char*)memcpy(_property##tmp, membuf, tmp_1byte);\
|
||||
_property = (unsigned char *)strcat(to_utf8(_property##tmp), ""); \
|
||||
free(_property##tmp);\
|
||||
JUMP(membuf, tmp_1byte);
|
||||
JUMP(membuf, tmp_1byte); \
|
||||
}
|
||||
|
||||
#endif // DATATRAK_HEADER_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue