Commit 28132698 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

STL: simplify and fix memory leak

parent df363756
...@@ -78,49 +78,30 @@ static cct_number_t cct_nums[] = { {CCT_ISO_6937_2, "ISO_6937-2"}, ...@@ -78,49 +78,30 @@ static cct_number_t cct_nums[] = { {CCT_ISO_6937_2, "ISO_6937-2"},
{CCT_ISO_8859_8, "ISO_8859-8"} }; {CCT_ISO_8859_8, "ISO_8859-8"} };
static char *ParseText(uint8_t *data, int size, const char *charset) static char *ParseText(const uint8_t *data, size_t size, const char *charset)
{ {
char *text = strdup(""); char *text = malloc(size);
int text_size = 0; if (text == NULL)
return NULL;
size_t text_size = 0;
for (int i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
uint8_t code = data[i]; uint8_t code = data[i];
if (code == 0x8f) if (code == 0x8f)
break; break;
if (code == 0x7f)
char tmp[16] = "";
char *t = tmp;
if ((code >= 0x20 && code <= 0x7e) ||
(code >= 0xa0) )
snprintf(tmp, sizeof(tmp), "%c", code);
#if 0
else if (code == 0x80)
snprintf(tmp, sizeof(tmp), "<i>");
else if (code == 0x81)
snprintf(tmp, sizeof(tmp), "</i>");
else if (code == 0x82)
snprintf(tmp, sizeof(tmp), "<u>");
else if (code == 0x83)
snprintf(tmp, sizeof(tmp), "</u>");
#endif
else if (code == 0x8a)
snprintf(tmp, sizeof(tmp), "\n");
else {
t = NULL;
}
if (!t)
continue; continue;
size_t t_size = strlen(t); if (code & 0x60)
text = realloc_or_free(text, t_size + text_size + 1); text[text_size++] = code;
if (!text) if (code == 0x8a)
continue; text[text_size++] = '\n';
memcpy(&text[text_size], t, t_size);
text_size += t_size;
text[text_size] = '\0';
} }
return FromCharset(charset, text, text_size);
char *u8 = FromCharset(charset, text, text_size);
free(text);
return u8;
} }
static subpicture_t *Decode(decoder_t *dec, block_t **block) static subpicture_t *Decode(decoder_t *dec, block_t **block)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment