Replace realloc() et al in unmangle_ansi with stralloc.
I think this is correct. The code, both before and after, doesn't appear to NUL-terminate its output. Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
This commit is contained in:
parent
58481b88eb
commit
db53878cb1
@ -820,9 +820,7 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) {
|
||||
int params[16];
|
||||
int param_count = 0;
|
||||
int bold = 0;
|
||||
char *out;
|
||||
int out_len;
|
||||
int out_max;
|
||||
stralloc out = EMPTY_STRALLOC;
|
||||
char buffer[1024];
|
||||
int buf_at;
|
||||
int i, j, k;
|
||||
@ -1290,10 +1288,6 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) {
|
||||
fg = 0x07;
|
||||
bg = 0x00;
|
||||
|
||||
out_max = 256;
|
||||
out_len = 0;
|
||||
out = (char *)malloz(256);
|
||||
|
||||
for (i = 0; i < line_count; i++) {
|
||||
buf_at = 0;
|
||||
for (j = 0; j < 79; j++) {
|
||||
@ -1402,14 +1396,7 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) {
|
||||
}
|
||||
|
||||
buffer[buf_at++] = '\r';
|
||||
|
||||
while (buf_at + out_len > out_max) {
|
||||
out_max += 256;
|
||||
out = (char *)realloc(out, out_max);
|
||||
}
|
||||
|
||||
memcpy(&out[out_len], buffer, buf_at);
|
||||
out_len += buf_at;
|
||||
stralloc_catb(&out, buffer, buf_at);
|
||||
}
|
||||
|
||||
for (i = 0; i < line_count; i++) {
|
||||
@ -1420,12 +1407,12 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) {
|
||||
}
|
||||
free(fake_screen);
|
||||
|
||||
while (out[out_len - 2] == '\r') {
|
||||
out_len--;
|
||||
while (out.s[out.len - 2] == '\r') {
|
||||
out.len--;
|
||||
}
|
||||
|
||||
*body_out = out;
|
||||
*body_len = out_len;
|
||||
*body_out = out.s;
|
||||
*body_len = out.len;
|
||||
}
|
||||
|
||||
int read_message(struct user_record *user, struct msg_headers *msghs, int mailno, int newscan) {
|
||||
|
Reference in New Issue
Block a user