Mercurial > dovecot > original-hg > dovecot-1.2
diff src/imap/cmd-sort.c @ 765:553f050c8313 HEAD
Added buffer API. Point is to hide all buffer writing behind this API which
verifies that nothing overflows. Much better than doing the same checks all
around the code, even if it is slightly slower.
Buffer reading is still mostly done directly, that isn't such a big security
risk and I can't think of a reasonable API for it anyway.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 08 Dec 2002 07:23:07 +0200 |
parents | f57c52738f90 |
children | 8b3518bb327e |
line wrap: on
line diff
--- a/src/imap/cmd-sort.c Fri Dec 06 03:09:22 2002 +0200 +++ b/src/imap/cmd-sort.c Sun Dec 08 07:23:07 2002 +0200 @@ -1,6 +1,7 @@ /* Copyright (C) 2002 Timo Sirainen */ #include "common.h" +#include "buffer.h" #include "commands.h" #include "mail-search.h" #include "mail-sort.h" @@ -25,12 +26,12 @@ static MailSortType *get_sort_program(Client *client, ImapArg *args) { - MailSortType *program, *temp_prog; - size_t program_alloc, program_size; + MailSortType type; + Buffer *buf; int i; - program_alloc = 32; program_size = 0; - program = t_new(MailSortType, program_alloc+1); + buf = buffer_create_dynamic(data_stack_pool, 32 * sizeof(MailSortType), + (size_t)-1); while (args->type == IMAP_ARG_ATOM || args->type == IMAP_ARG_STRING) { const char *arg = args->data.str; @@ -46,20 +47,12 @@ return NULL; } - if (program_size == program_alloc) { - program_alloc *= 2; - if (!t_try_realloc(program, program_alloc+1)) { - temp_prog = t_new(MailSortType, program_alloc); - memcpy(temp_prog, program, - sizeof(MailSortType) * program_size); - program = temp_prog; - } - } - program[program_size++] = sort_names[i].type; + buffer_append(buf, &sort_names[i].type, sizeof(MailSortType)); args++; } - program[program_size] = MAIL_SORT_END; + type = MAIL_SORT_END; + buffer_append(buf, &type, sizeof(type)); if (args->type != IMAP_ARG_EOL) { client_send_command_error(client, @@ -67,7 +60,7 @@ return NULL; } - return program; + return buffer_free_without_data(buf); } int cmd_sort(Client *client)