1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 10:39:27 +02:00

resilience: initialize all parameters to zero

This commit is contained in:
B. Petersen 2018-07-06 14:45:54 +02:00
parent e6eb4eff3e
commit bc1fda3050
27 changed files with 558 additions and 445 deletions

View file

@ -169,7 +169,10 @@ int dc_aheader_set_from_string(dc_aheader_t* aheader, const char* header_str__)
(c) for parsing, we ignore `\r\n` as well as tabs for spaces */
#define AHEADER_WS "\t\r\n "
char* header_str = NULL;
char *p, *beg_attr_name, *after_attr_name, *beg_attr_value;
char* p = NULL;
char* beg_attr_name = NULL;
char* after_attr_name = NULL;
char* beg_attr_value = NULL;
int success = 0;
dc_aheader_empty(aheader);
@ -271,7 +274,7 @@ void dc_aheader_unref(dc_aheader_t* aheader)
*/
dc_aheader_t* dc_aheader_new_from_imffields(const char* wanted_from, const struct mailimf_fields* header)
{
clistiter* cur;
clistiter* cur = NULL;
dc_aheader_t* fine_header = NULL;
if (wanted_from == NULL || header == NULL) {

View file

@ -482,7 +482,8 @@ void dc_apeerstate_apply_gossip(dc_apeerstate_t* peerstate, const dc_aheader_t*
int dc_apeerstate_recalc_fingerprint(dc_apeerstate_t* peerstate)
{
int success = 0;
char* old_public_fingerprint = NULL, *old_gossip_fingerprint = NULL;
char* old_public_fingerprint = NULL;
char* old_gossip_fingerprint = NULL;
if (peerstate == NULL) {
goto cleanup;

View file

@ -38,7 +38,7 @@
*/
dc_array_t* dc_array_new(dc_context_t* context, size_t initsize)
{
dc_array_t* array;
dc_array_t* array = NULL;
array = (dc_array_t*) malloc(sizeof(dc_array_t));
if (array==NULL) {
@ -93,13 +93,11 @@ void dc_array_unref(dc_array_t* array)
*/
void dc_array_free_ptr(dc_array_t* array)
{
size_t i;
if (array==NULL || array->magic != DC_ARRAY_MAGIC) {
return;
}
for (i = 0; i < array->count; i++) {
for (size_t i = 0; i < array->count; i++) {
free((void*)array->array[i]);
array->array[i] = 0;
}
@ -135,7 +133,8 @@ dc_array_t* dc_array_duplicate(const dc_array_t* array)
static int cmp_intptr_t(const void* p1, const void* p2)
{
uintptr_t v1 = *(uintptr_t*)p1, v2 = *(uintptr_t*)p2;
uintptr_t v1 = *(uintptr_t*)p1;
uintptr_t v2 = *(uintptr_t*)p2;
return (v1<v2)? -1 : ((v1>v2)? 1 : 0); /* CAVE: do not use v1-v2 as the uintptr_t may be 64bit and the return value may be 32bit only... */
}

View file

@ -301,7 +301,8 @@ int dc_chatlist_load_from_db(dc_chatlist_t* chatlist, int listflags, const char*
int success = 0;
int add_archived_link_item = 0;
sqlite3_stmt* stmt = NULL;
char* strLikeCmd = NULL, *query = NULL;
char* strLikeCmd = NULL;
char* query = NULL;
if (chatlist == NULL || chatlist->magic != DC_CHATLIST_MAGIC || chatlist->context == NULL) {
goto cleanup;

View file

@ -88,7 +88,7 @@ typedef struct moz_autoconfigure_t
static void moz_autoconfigure_starttag_cb(void* userdata, const char* tag, char** attr)
{
moz_autoconfigure_t* moz_ac = (moz_autoconfigure_t*)userdata;
const char* p1;
const char* p1 = NULL;
if (strcmp(tag, "incomingserver")==0) {
moz_ac->tag_server = (moz_ac->out_imap_set==0 && (p1=dc_attr_find(attr, "type"))!=NULL && strcasecmp(p1, "imap")==0)? MOZ_SERVER_IMAP : 0;
@ -98,10 +98,18 @@ static void moz_autoconfigure_starttag_cb(void* userdata, const char* tag, char*
moz_ac->tag_server = moz_ac->out_smtp_set==0? MOZ_SERVER_SMTP : 0;
moz_ac->tag_config = 0;
}
else if (strcmp(tag, "hostname")==0) { moz_ac->tag_config = MOZ_HOSTNAME; }
else if (strcmp(tag, "port")==0 ) { moz_ac->tag_config = MOZ_PORT; }
else if (strcmp(tag, "sockettype")==0) { moz_ac->tag_config = MOZ_SOCKETTYPE; }
else if (strcmp(tag, "username")==0) { moz_ac->tag_config = MOZ_USERNAME; }
else if (strcmp(tag, "hostname")==0) {
moz_ac->tag_config = MOZ_HOSTNAME;
}
else if (strcmp(tag, "port")==0 ) {
moz_ac->tag_config = MOZ_PORT;
}
else if (strcmp(tag, "sockettype")==0) {
moz_ac->tag_config = MOZ_SOCKETTYPE;
}
else if (strcmp(tag, "username")==0) {
moz_ac->tag_config = MOZ_USERNAME;
}
}
@ -115,11 +123,25 @@ static void moz_autoconfigure_text_cb(void* userdata, const char* text, int len)
dc_str_replace(&val, "%EMAILLOCALPART%", moz_ac->in_emaillocalpart);
dc_str_replace(&val, "%EMAILDOMAIN%", moz_ac->in_emaildomain);
if (moz_ac->tag_server == MOZ_SERVER_IMAP) {
if (moz_ac->tag_server==MOZ_SERVER_IMAP)
{
switch (moz_ac->tag_config) {
case MOZ_HOSTNAME: free(moz_ac->out->mail_server); moz_ac->out->mail_server = val; val = NULL; break;
case MOZ_PORT: moz_ac->out->mail_port = atoi(val); break;
case MOZ_USERNAME: free(moz_ac->out->mail_user); moz_ac->out->mail_user = val; val = NULL; break;
case MOZ_HOSTNAME:
free(moz_ac->out->mail_server);
moz_ac->out->mail_server = val;
val = NULL;
break;
case MOZ_PORT:
moz_ac->out->mail_port = atoi(val);
break;
case MOZ_USERNAME:
free(moz_ac->out->mail_user);
moz_ac->out->mail_user = val;
val = NULL;
break;
case MOZ_SOCKETTYPE:
if (strcasecmp(val, "ssl")==0) { moz_ac->out->server_flags |=DC_LP_IMAP_SOCKET_SSL; }
if (strcasecmp(val, "starttls")==0) { moz_ac->out->server_flags |=DC_LP_IMAP_SOCKET_STARTTLS; }
@ -127,11 +149,25 @@ static void moz_autoconfigure_text_cb(void* userdata, const char* text, int len)
break;
}
}
else if (moz_ac->tag_server == MOZ_SERVER_SMTP) {
else if (moz_ac->tag_server==MOZ_SERVER_SMTP)
{
switch (moz_ac->tag_config) {
case MOZ_HOSTNAME: free(moz_ac->out->send_server); moz_ac->out->send_server = val; val = NULL; break;
case MOZ_PORT: moz_ac->out->send_port = atoi(val); break;
case MOZ_USERNAME: free(moz_ac->out->send_user); moz_ac->out->send_user = val; val = NULL; break;
case MOZ_HOSTNAME:
free(moz_ac->out->send_server);
moz_ac->out->send_server = val;
val = NULL;
break;
case MOZ_PORT:
moz_ac->out->send_port = atoi(val);
break;
case MOZ_USERNAME:
free(moz_ac->out->send_user);
moz_ac->out->send_user = val;
val = NULL;
break;
case MOZ_SOCKETTYPE:
if (strcasecmp(val, "ssl")==0) { moz_ac->out->server_flags |=DC_LP_SMTP_SOCKET_SSL; }
if (strcasecmp(val, "starttls")==0) { moz_ac->out->server_flags |=DC_LP_SMTP_SOCKET_STARTTLS; }
@ -282,14 +318,16 @@ static void outlk_autodiscover_endtag_cb(void* userdata, const char* tag)
ssl_on = (outlk_ad->config[OUTLK_SSL] && strcasecmp(outlk_ad->config[OUTLK_SSL], "on")==0),
ssl_off = (outlk_ad->config[OUTLK_SSL] && strcasecmp(outlk_ad->config[OUTLK_SSL], "off")==0);
if (strcasecmp(outlk_ad->config[OUTLK_TYPE], "imap")==0 && outlk_ad->out_imap_set==0) {
if (strcasecmp(outlk_ad->config[OUTLK_TYPE], "imap")==0 && outlk_ad->out_imap_set==0)
{
outlk_ad->out->mail_server = dc_strdup_keep_null(outlk_ad->config[OUTLK_SERVER]);
outlk_ad->out->mail_port = port;
if (ssl_on) { outlk_ad->out->server_flags |= DC_LP_IMAP_SOCKET_SSL; }
else if (ssl_off) { outlk_ad->out->server_flags |= DC_LP_IMAP_SOCKET_PLAIN; }
outlk_ad->out_imap_set = 1;
}
else if (strcasecmp(outlk_ad->config[OUTLK_TYPE], "smtp")==0 && outlk_ad->out_smtp_set==0) {
else if (strcasecmp(outlk_ad->config[OUTLK_TYPE], "smtp")==0 && outlk_ad->out_smtp_set==0)
{
outlk_ad->out->send_server = dc_strdup_keep_null(outlk_ad->config[OUTLK_SERVER]);
outlk_ad->out->send_port = port;
if (ssl_on) { outlk_ad->out->server_flags |= DC_LP_SMTP_SOCKET_SSL; }
@ -333,7 +371,8 @@ static dc_loginparam_t* outlk_autodiscover(dc_context_t* context, const char* ur
url = dc_strdup(outlk_ad.config[OUTLK_REDIRECTURL]);
dc_loginparam_unref(outlk_ad.out);
outlk_clean_config(&outlk_ad);
free(xml_raw); xml_raw = NULL;
free(xml_raw);
xml_raw = NULL;
}
else {
break;
@ -366,7 +405,8 @@ cleanup:
void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job)
{
int success = 0, i;
int success = 0;
int i = 0;
int imap_connected_here = 0;
int smtp_connected_here = 0;
int ongoing_allocated_here = 0;

View file

@ -315,7 +315,8 @@ void dc_e2ee_encrypt(dc_context_t* context, const clist* recipients_addr,
int min_verified,
struct mailmime* in_out_message, dc_e2ee_helper_t* helper)
{
int col = 0, do_encrypt = 0;
int col = 0;
int do_encrypt = 0;
dc_aheader_t* autocryptheader = dc_aheader_new();
struct mailimf_fields* imffields_unprotected = NULL; /*just a pointer into mailmime structure, must not be freed*/
dc_keyring_t* keyring = dc_keyring_new();
@ -536,7 +537,8 @@ void dc_e2ee_thanks(dc_e2ee_helper_t* helper)
static int has_decrypted_pgp_armor(const char* str__, int str_bytes)
{
const unsigned char *str_end = (const unsigned char*)str__+str_bytes, *p=(const unsigned char*)str__;
const unsigned char* str_end = (const unsigned char*)str__+str_bytes;
const unsigned char* p=(const unsigned char*)str__;
while (p < str_end) {
if (*p > ' ') {
break;
@ -558,7 +560,7 @@ static int decrypt_part(dc_context_t* context,
dc_hash_t* ret_valid_signatures,
struct mailmime** ret_decrypted_mime)
{
struct mailmime_data* mime_data;
struct mailmime_data* mime_data = NULL;
int mime_transfer_encoding = MAILMIME_MECHANISM_BINARY;
char* transfer_decoding_buffer = NULL; /* mmap_string_unref()'d if set */
const char* decoded_data = NULL; /* must not be free()'d */
@ -663,8 +665,8 @@ static int decrypt_recursive(dc_context_t* context,
struct mailimf_fields** ret_gossip_headers,
int* ret_has_unencrypted_parts)
{
struct mailmime_content* ct;
clistiter* cur;
struct mailmime_content* ct = NULL;
clistiter* cur = NULL;
if (context == NULL || mime == NULL) {
return 0;
@ -725,7 +727,7 @@ static int decrypt_recursive(dc_context_t* context,
static dc_hash_t* update_gossip_peerstates(dc_context_t* context, time_t message_time, struct mailimf_fields* imffields, const struct mailimf_fields* gossip_headers)
{
clistiter* cur1;
clistiter* cur1 = NULL;
dc_hash_t* recipients = NULL;
dc_hash_t* gossipped_addr = NULL;
@ -801,7 +803,8 @@ void dc_e2ee_decrypt(dc_context_t* context, struct mailmime* in_out_message,
dc_aheader_t* autocryptheader = NULL;
time_t message_time = 0;
dc_apeerstate_t* peerstate = dc_apeerstate_new(context);
char* from = NULL, *self_addr = NULL;
char* from = NULL;
char* self_addr = NULL;
dc_keyring_t* private_keyring = dc_keyring_new();
dc_keyring_t* public_keyring_for_validate = dc_keyring_new();
struct mailimf_fields* gossip_headers = NULL;

View file

@ -303,9 +303,11 @@ cleanup:
char* dc_decrypt_setup_file(dc_context_t* context, const char* passphrase, const char* filecontent)
{
char* fc_buf = NULL;
const char *fc_headerline = NULL, *fc_base64 = NULL;
const char* fc_headerline = NULL;
const char* fc_base64 = NULL;
char* binary = NULL;
size_t binary_bytes = 0, indx = 0;
size_t binary_bytes = 0;
size_t indx = 0;
pgp_io_t io;
pgp_memory_t* outmem = NULL;
char* payload = NULL;
@ -357,10 +359,9 @@ cleanup:
char* dc_create_setup_code(dc_context_t* context)
{
#define CODE_ELEMS 9
uint16_t random_val;
int i;
uint16_t random_val = 0;
int i = 0;
dc_strbuilder_t ret;
dc_strbuilder_init(&ret, 0);
for (i = 0; i < CODE_ELEMS; i++)
@ -392,7 +393,7 @@ char* dc_normalize_setup_code(dc_context_t* context, const char* in)
dc_strbuilder_t out;
dc_strbuilder_init(&out, 0);
int outlen;
int outlen = 0;
const char* p1 = in;
while (*p1) {
@ -542,7 +543,9 @@ static int set_self_key(dc_context_t* context, const char* armored, int set_defa
{
int success = 0;
char* buf = NULL;
const char* buf_headerline, *buf_preferencrypt, *buf_base64; // pointers inside buf, MUST NOT be free()'d
const char* buf_headerline = NULL; // pointer inside buf, MUST NOT be free()'d
const char* buf_preferencrypt = NULL; // - " -
const char* buf_base64 = NULL; // - " -
dc_key_t* private_key = dc_key_new();
dc_key_t* public_key = dc_key_new();
sqlite3_stmt* stmt = NULL;
@ -701,7 +704,8 @@ static int export_self_keys(dc_context_t* context, const char* dir)
{
int success = 0;
sqlite3_stmt* stmt = NULL;
int id = 0, is_default = 0;
int id = 0;
int is_default = 0;
dc_key_t* public_key = dc_key_new();
dc_key_t* private_key = dc_key_new();
@ -750,9 +754,9 @@ static int import_self_keys(dc_context_t* context, const char* dir_name)
int set_default = 0;
char* buf = NULL;
size_t buf_bytes = 0;
const char* private_key; // a pointer inside buf, MUST NOT be free()'d
const char* private_key = NULL; // a pointer inside buf, MUST NOT be free()'d
char* buf2 = NULL;
const char* buf2_headerline; // a pointer inside buf2, MUST NOT be free()'d
const char* buf2_headerline = NULL; // a pointer inside buf2, MUST NOT be free()'d
if (context==NULL || context->magic != DC_CONTEXT_MAGIC || dir_name==NULL) {
goto cleanup;
@ -840,19 +844,21 @@ The macro avoids weird values of 0% or 100% while still working. */
static int export_backup(dc_context_t* context, const char* dir)
{
int success = 0, closed = 0;
int success = 0;
int closed = 0;
char* dest_pathNfilename = NULL;
dc_sqlite3_t* dest_sql = NULL;
time_t now = time(NULL);
DIR* dir_handle = NULL;
struct dirent* dir_entry;
struct dirent* dir_entry = NULL;
int prefix_len = strlen(DC_BAK_PREFIX);
int suffix_len = strlen(DC_BAK_SUFFIX);
char* curr_pathNfilename = NULL;
void* buf = NULL;
size_t buf_bytes = 0;
sqlite3_stmt* stmt = NULL;
int total_files_count = 0, processed_files_count = 0;
int total_files_count = 0;
int processed_files_count = 0;
int delete_dest_file = 0;
/* get a fine backup file name (the name includes the date so that multiple backup instances are possible)
@ -1002,7 +1008,8 @@ static int import_backup(dc_context_t* context, const char* backup_to_import)
*/
int success = 0;
int processed_files_count = 0, total_files_count = 0;
int processed_files_count = 0;
int total_files_count = 0;
sqlite3_stmt* stmt = NULL;
char* pathNfilename = NULL;
char* repl_from = NULL;
@ -1324,7 +1331,7 @@ char* dc_imex_has_backup(dc_context_t* context, const char* dir_name)
char* ret = NULL;
time_t ret_backup_time = 0;
DIR* dir_handle = NULL;
struct dirent* dir_entry;
struct dirent* dir_entry = NULL;
int prefix_len = strlen(DC_BAK_PREFIX);
int suffix_len = strlen(DC_BAK_SUFFIX);
char* curr_pathNfilename = NULL;

View file

@ -75,10 +75,9 @@ cleanup:
static void dc_job_do_DC_JOB_SEND_MSG_TO_IMAP(dc_context_t* context, dc_job_t* job)
{
dc_mimefactory_t mimefactory;
char* server_folder = NULL;
uint32_t server_uid = 0;
dc_mimefactory_t mimefactory;
dc_mimefactory_init(&mimefactory, context);
/* connect to IMAP-server */
@ -476,8 +475,8 @@ static void dc_suspend_smtp_thread(dc_context_t* context, int suspend)
void dc_job_add(dc_context_t* context, int action, int foreign_id, const char* param, int delay_seconds)
{
time_t timestamp = time(NULL);
sqlite3_stmt* stmt;
int thread;
sqlite3_stmt* stmt = NULL;
int thread = 0;
if (action >= DC_IMAP_THREAD && action < DC_IMAP_THREAD+1000) {
thread = DC_IMAP_THREAD;

View file

@ -162,9 +162,11 @@ int dc_key_set_from_base64(dc_key_t* key, const char* base64, int type)
int dc_key_set_from_file(dc_key_t* key, const char* pathNfilename, dc_context_t* context)
{
char* buf = NULL;
const char *headerline, *base64; // just pointers inside buf, must not be freed
size_t buf_bytes;
int type = -1, success = 0;
const char* headerline = NULL; // just pointer inside buf, must not be freed
const char* base64 = NULL; // - " -
size_t buf_bytes = 0;
int type = -1;
int success = 0;
dc_key_empty(key);
@ -319,10 +321,9 @@ static long crc_octets(const unsigned char *octets, size_t len)
#define CRC24_INIT 0xB704CEL
#define CRC24_POLY 0x1864CFBL
long crc = CRC24_INIT;
int i;
while (len--) {
crc ^= (*octets++) << 16;
for (i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
crc <<= 1;
if (crc & 0x1000000)
crc ^= CRC24_POLY;
@ -396,7 +397,8 @@ char* dc_key_render_base64(const dc_key_t* key, int break_every, const char* bre
char* dc_key_render_asc(const dc_key_t* key, const char* add_header_lines /*must be terminated by \r\n*/)
{
/* see RFC 4880, 6.2. Forming ASCII Armor, https://tools.ietf.org/html/rfc4880#section-6.2 */
char *base64 = NULL, *ret = NULL;
char* base64 = NULL;
char* ret = NULL;
if (key==NULL) {
goto cleanup;
@ -446,7 +448,8 @@ cleanup:
/* make a fingerprint human-readable */
char* dc_format_fingerprint(const char* fingerprint)
{
int i = 0, fingerprint_len = strlen(fingerprint);
int i = 0;
int fingerprint_len = strlen(fingerprint);
dc_strbuilder_t ret;
dc_strbuilder_init(&ret, 0);

View file

@ -45,12 +45,11 @@ dc_keyring_t* dc_keyring_new()
void dc_keyring_unref(dc_keyring_t* keyring)
{
int i;
if (keyring == NULL) {
return;
}
for (i = 0; i < keyring->count; i++) {
for (int i = 0; i < keyring->count; i++) {
dc_key_unref(keyring->keys[i]);
}
free(keyring->keys);

View file

@ -297,9 +297,9 @@ cleanup:
static struct mailmime* build_body_text(char* text)
{
struct mailmime_fields* mime_fields;
struct mailmime* message_part;
struct mailmime_content* content;
struct mailmime_fields* mime_fields = NULL;
struct mailmime* message_part = NULL;
struct mailmime_content* content = NULL;
content = mailmime_content_new_with_str("text/plain");
clist_append(content->ct_parameters, mailmime_param_new_with_data("charset", "utf-8")); /* format=flowed currently does not really affect us, see https://www.ietf.org/rfc/rfc3676.txt */
@ -315,9 +315,9 @@ static struct mailmime* build_body_text(char* text)
static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_name, char** ret_file_name_as_sent)
{
struct mailmime_fields* mime_fields;
struct mailmime_fields* mime_fields = NULL;
struct mailmime* mime_sub = NULL;
struct mailmime_content* content;
struct mailmime_content* content = NULL;
char* pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
char* mimetype = dc_param_get(msg->param, DC_PARAM_MIMETYPE, NULL);
@ -437,7 +437,8 @@ cleanup:
static char* get_subject(const dc_chat_t* chat, const dc_msg_t* msg, int afwd_email)
{
dc_context_t* context = chat? chat->context : NULL;
char *ret, *raw_subject = dc_msg_get_summarytext_by_raw(msg->type, msg->text, msg->param, DC_APPROX_SUBJECT_CHARS, context);
char* ret = NULL;
char* raw_subject = dc_msg_get_summarytext_by_raw(msg->type, msg->text, msg->param, DC_APPROX_SUBJECT_CHARS, context);
const char* fwd = afwd_email? "Fwd: " : "";
if (dc_param_get_int(msg->param, DC_PARAM_CMD, 0) == DC_CMD_AUTOCRYPT_SETUP_MESSAGE)
@ -466,19 +467,20 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
return 0;
}
struct mailimf_fields* imf_fields;
struct mailimf_fields* imf_fields = NULL;
struct mailmime* message = NULL;
char* message_text = NULL, *message_text2 = NULL, *subject_str = NULL;
char* message_text = NULL;
char* message_text2 = NULL;
char* subject_str = NULL;
int afwd_email = 0;
int col = 0;
int success = 0;
int parts = 0;
dc_e2ee_helper_t e2ee_helper;
int e2ee_guaranteed = 0;
int min_verified = DC_NOT_VERIFIED;
int force_plaintext = 0; // 1=add Autocrypt-header (needed eg. for handshaking), 2=no Autocrypte-header (used for MDN)
char* grpimage = NULL;
dc_e2ee_helper_t e2ee_helper;
memset(&e2ee_helper, 0, sizeof(dc_e2ee_helper_t));

View file

@ -577,13 +577,11 @@ struct mailimf_fields* mailmime_find_mailimf_fields(struct mailmime* mime)
char* mailimf_find_first_addr(const struct mailimf_mailbox_list* mb_list)
{
clistiter* cur;
if (mb_list == NULL) {
return NULL;
}
for (cur = clist_begin(mb_list->mb_list); cur!=NULL ; cur=clist_next(cur)) {
for (clistiter* cur = clist_begin(mb_list->mb_list); cur!=NULL ; cur=clist_next(cur)) {
struct mailimf_mailbox* mb = (struct mailimf_mailbox*)clist_content(cur);
if (mb && mb->mb_addr_spec) {
return dc_addr_normalize(mb->mb_addr_spec);
@ -599,8 +597,7 @@ struct mailimf_field* mailimf_find_field(struct mailimf_fields* header, int want
return NULL;
}
clistiter* cur1;
for (cur1 = clist_begin(header->fld_list); cur1!=NULL ; cur1=clist_next(cur1))
for (clistiter* cur1 = clist_begin(header->fld_list); cur1!=NULL ; cur1=clist_next(cur1))
{
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur1);
if (field)
@ -622,8 +619,7 @@ struct mailimf_optional_field* mailimf_find_optional_field(struct mailimf_fields
return NULL;
}
clistiter* cur1;
for (cur1 = clist_begin(header->fld_list); cur1!=NULL ; cur1=clist_next(cur1))
for (clistiter* cur1 = clist_begin(header->fld_list); cur1!=NULL ; cur1=clist_next(cur1))
{
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur1);
if (field && field->fld_type == MAILIMF_FIELD_OPTIONAL_FIELD)
@ -642,8 +638,7 @@ struct mailimf_optional_field* mailimf_find_optional_field(struct mailimf_fields
static int mailmime_is_attachment_disposition(struct mailmime* mime)
{
if (mime->mm_mime_fields != NULL) {
clistiter* cur;
for (cur = clist_begin(mime->mm_mime_fields->fld_list); cur != NULL; cur = clist_next(cur)) {
for (clistiter* cur = clist_begin(mime->mm_mime_fields->fld_list); cur != NULL; cur = clist_next(cur)) {
struct mailmime_field* field = (struct mailmime_field*)clist_content(cur);
if (field && field->fld_type == MAILMIME_FIELD_DISPOSITION && field->fld_data.fld_disposition) {
if (field->fld_data.fld_disposition->dsp_type
@ -676,7 +671,7 @@ static int mailmime_get_mime_type(struct mailmime* mime, int* msg_type)
#define DC_MIMETYPE_AC_SETUP_FILE 111
struct mailmime_content* c = mime->mm_content_type;
int dummy; if (msg_type == NULL) { msg_type = &dummy; }
int dummy = 0; if (msg_type == NULL) { msg_type = &dummy; }
*msg_type = DC_MSG_UNDEFINED;
if (c == NULL || c->ct_type == NULL) {

View file

@ -264,7 +264,7 @@ time_t dc_msg_get_timestamp(const dc_msg_t* msg)
*/
char* dc_msg_get_text(const dc_msg_t* msg)
{
char* ret;
char* ret = NULL;
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
return dc_strdup(NULL);
@ -316,7 +316,8 @@ cleanup:
*/
char* dc_msg_get_filename(const dc_msg_t* msg)
{
char* ret = NULL, *pathNfilename = NULL;
char* ret = NULL;
char* pathNfilename = NULL;
if (msg == NULL || msg->magic != DC_MSG_MAGIC) {
goto cleanup;
@ -957,7 +958,10 @@ void dc_msg_get_authorNtitle_from_filename(const char* pathNfilename, char** ret
{
/* function extracts AUTHOR and TITLE from a path given as `/path/other folder/AUTHOR - TITLE.mp3`
if the mark ` - ` is not preset, the whole name (without suffix) is used as the title and the author is NULL. */
char *author = NULL, *title = NULL, *p;
char* author = NULL;
char* title = NULL;
char* p = NULL;
dc_split_filename(pathNfilename, &title, NULL);
p = strstr(title, " - ");
if (p) {
@ -975,7 +979,9 @@ char* dc_msg_get_summarytext_by_raw(int type, const char* text, dc_param_t* para
{
/* get a summary text, result must be free()'d, never returns NULL. */
char* ret = NULL;
char* pathNfilename = NULL, *label = NULL, *value = NULL;
char* pathNfilename = NULL;
char* label = NULL;
char* value = NULL;
switch (type) {
case DC_MSG_IMAGE:

View file

@ -29,7 +29,8 @@
static char* find_param(char* haystack, int key, char** ret_p2)
{
char *p1, *p2;
char* p1 = NULL;
char* p2 = NULL;
/* let p1 point to the start of the */
p1 = haystack;
@ -68,7 +69,7 @@ static char* find_param(char* haystack, int key, char** ret_p2)
*/
dc_param_t* dc_param_new()
{
dc_param_t* param;
dc_param_t* param = NULL;
if ((param=calloc(1, sizeof(dc_param_t)))==NULL) {
exit(28); /* cannot allocate little memory, unrecoverable error */
@ -171,7 +172,7 @@ void dc_param_set_urlencoded(dc_param_t* param, const char* urlencoded)
*/
int dc_param_exists(dc_param_t* param, int key)
{
char *p2;
char *p2 = NULL;
if (param == NULL || key == 0) {
return 0;
@ -192,7 +193,10 @@ int dc_param_exists(dc_param_t* param, int key)
*/
char* dc_param_get(dc_param_t* param, int key, const char* def)
{
char *p1, *p2, bak, *ret;
char* p1 = NULL;
char* p2 = NULL;
char bak = 0;
char* ret = NULL;
if (param == NULL || key == 0) {
return def? dc_strdup(def) : NULL;
@ -250,7 +254,9 @@ int32_t dc_param_get_int(dc_param_t* param, int key, int32_t def)
*/
void dc_param_set(dc_param_t* param, int key, const char* value)
{
char *old1, *old2, *new1 = NULL;
char* old1 = NULL;
char* old2 = NULL;
char* new1 = NULL;
if (param == NULL || key == 0) {
return;

View file

@ -88,7 +88,8 @@ int dc_split_armored_data(char* buf, const char** ret_headerline, const char** r
int success = 0;
size_t line_chars = 0;
char* line = buf;
char* p1 = buf, *p2;
char* p1 = buf;
char* p2 = NULL;
char* headerline = NULL;
char* base64 = NULL;
#define PGP_WS "\t\r\n "
@ -218,7 +219,7 @@ static unsigned add_key_prefs(pgp_create_sig_t *sig)
static void add_selfsigned_userid(pgp_key_t *skey, pgp_key_t *pkey, const uint8_t *userid, time_t key_expiry)
{
/* similar to pgp_add_selfsigned_userid() which, however, uses different key flags */
pgp_create_sig_t *sig;
pgp_create_sig_t* sig = NULL;
pgp_subpacket_t sigpacket;
pgp_memory_t* mem_sig = NULL;
pgp_output_t* sigoutput = NULL;
@ -261,7 +262,7 @@ static void add_selfsigned_userid(pgp_key_t *skey, pgp_key_t *pkey, const uint8_
static void add_subkey_binding_signature(pgp_subkeysig_t* p, pgp_key_t* primarykey, pgp_key_t* subkey, pgp_key_t* seckey)
{
/*add "0x18: Subkey Binding Signature" packet, PGP_SIG_SUBKEY */
pgp_create_sig_t* sig;
pgp_create_sig_t* sig = NULL;
pgp_output_t* sigoutput = NULL;
pgp_memory_t* mem_sig = NULL;
@ -293,11 +294,15 @@ static void add_subkey_binding_signature(pgp_subkeysig_t* p, pgp_key_t* primaryk
int dc_pgp_create_keypair(dc_context_t* context, const char* addr, dc_key_t* ret_public_key, dc_key_t* ret_private_key)
{
int success = 0;
pgp_key_t seckey, pubkey, subkey;
pgp_key_t seckey;
pgp_key_t pubkey;
pgp_key_t subkey;
uint8_t subkeyid[PGP_KEY_ID_SIZE];
uint8_t* user_id = NULL;
pgp_memory_t *pubmem = pgp_memory_new(), *secmem = pgp_memory_new();
pgp_output_t *pubout = pgp_output_new(), *secout = pgp_output_new();
pgp_memory_t* pubmem = pgp_memory_new();
pgp_memory_t* secmem = pgp_memory_new();
pgp_output_t* pubout = pgp_output_new();
pgp_output_t* secout = pgp_output_new();
memset(&seckey, 0, sizeof(pgp_key_t));
memset(&pubkey, 0, sizeof(pgp_key_t));
@ -542,7 +547,8 @@ int dc_pgp_pk_encrypt( dc_context_t* context,
pgp_keyring_t* dummy_keys = calloc(1, sizeof(pgp_keyring_t));
pgp_memory_t* keysmem = pgp_memory_new();
pgp_memory_t* signedmem = NULL;
int i, success = 0;
int i = 0;
int success = 0;
if (context==NULL || plain_text==NULL || plain_bytes==0 || ret_ctext==NULL || ret_ctext_bytes==NULL
|| raw_public_keys_for_encryption==NULL || raw_public_keys_for_encryption->count<=0
@ -636,7 +642,8 @@ int dc_pgp_pk_decrypt( dc_context_t* context,
key_id_t* recipients_key_ids = NULL;
unsigned recipients_count = 0;
pgp_memory_t* keysmem = pgp_memory_new();
int i, success = 0;
int i = 0;
int success = 0;
if (context==NULL || ctext==NULL || ctext_bytes==0 || ret_plain==NULL || ret_plain_bytes==NULL
|| raw_private_keys_for_decryption==NULL || raw_private_keys_for_decryption->count<=0

View file

@ -45,8 +45,8 @@
dc_lot_t* dc_check_qr(dc_context_t* context, const char* qr)
{
char* payload = NULL;
char* addr = NULL; /* must be normalized, if set */
char* fingerprint = NULL; /* must be normalized, if set */
char* addr = NULL; // must be normalized, if set
char* fingerprint = NULL; // must be normalized, if set
char* name = NULL;
char* invitenumber = NULL;
char* auth = NULL;

View file

@ -39,7 +39,7 @@
static void add_or_lookup_contact_by_addr(dc_context_t* context, const char* display_name_enc, const char* addr_spec, int origin, dc_array_t* ids, int* check_self)
{
/* is addr_spec equal to SELF? */
int dummy;
int dummy = 0;
if (check_self == NULL) { check_self = &dummy; }
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || addr_spec == NULL) {
@ -79,13 +79,11 @@ static void add_or_lookup_contact_by_addr(dc_context_t* context, const char* dis
static void dc_add_or_lookup_contacts_by_mailbox_list(dc_context_t* context, const struct mailimf_mailbox_list* mb_list, int origin, dc_array_t* ids, int* check_self)
{
clistiter* cur;
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || mb_list == NULL) {
return;
}
for (cur = clist_begin(mb_list->mb_list); cur!=NULL ; cur=clist_next(cur)) {
for (clistiter* cur = clist_begin(mb_list->mb_list); cur!=NULL ; cur=clist_next(cur)) {
struct mailimf_mailbox* mb = (struct mailimf_mailbox*)clist_content(cur);
if (mb) {
add_or_lookup_contact_by_addr(context, mb->mb_display_name, mb->mb_addr_spec, origin, ids, check_self);
@ -96,13 +94,11 @@ static void dc_add_or_lookup_contacts_by_mailbox_list(dc_context_t* context, con
static void dc_add_or_lookup_contacts_by_address_list(dc_context_t* context, const struct mailimf_address_list* adr_list, int origin, dc_array_t* ids, int* check_self)
{
clistiter* cur;
if (context == NULL || context->magic != DC_CONTEXT_MAGIC || adr_list == NULL /*may be NULL eg. if bcc is given as `Bcc: \n` in the header */) {
return;
}
for (cur = clist_begin(adr_list->ad_list); cur!=NULL ; cur=clist_next(cur)) {
for (clistiter* cur = clist_begin(adr_list->ad_list); cur!=NULL ; cur=clist_next(cur)) {
struct mailimf_address* adr = (struct mailimf_address*)clist_content(cur);
if (adr) {
if (adr->ad_type == MAILIMF_ADDRESS_MAILBOX) {
@ -167,7 +163,7 @@ static int dc_is_reply_to_known_message(dc_context_t* context, dc_mimeparser_t*
/* check if the message is a reply to a known message; the replies are identified by the Message-ID from
`In-Reply-To`/`References:` (to support non-Delta-Clients) or from `Chat-Predecessor:` (Delta clients, see comment in dc_chat.c) */
struct mailimf_optional_field* optional_field;
struct mailimf_optional_field* optional_field = NULL;
if ((optional_field=dc_mimeparser_lookup_optional_field2(mime_parser, "Chat-Predecessor", "X-MrPredecessor")) != NULL)
{
if (is_known_rfc724_mid(context, optional_field->fld_value)) {
@ -175,7 +171,7 @@ static int dc_is_reply_to_known_message(dc_context_t* context, dc_mimeparser_t*
}
}
struct mailimf_field* field;
struct mailimf_field* field = NULL;
if ((field=dc_mimeparser_lookup_field(mime_parser, "In-Reply-To"))!=NULL
&& field->fld_type == MAILIMF_FIELD_IN_REPLY_TO)
{
@ -229,8 +225,7 @@ static int is_msgrmsg_rfc724_mid(dc_context_t* context, const char* rfc724_mid)
static int is_msgrmsg_rfc724_mid_in_list(dc_context_t* context, const clist* mid_list)
{
if (mid_list) {
clistiter* cur;
for (cur = clist_begin(mid_list); cur!=NULL ; cur=clist_next(cur)) {
for (clistiter* cur = clist_begin(mid_list); cur!=NULL ; cur=clist_next(cur)) {
if (is_msgrmsg_rfc724_mid(context, clist_content(cur))) {
return 1;
}
@ -250,7 +245,7 @@ static int dc_is_reply_to_messenger_message(dc_context_t* context, dc_mimeparser
- it is okay, if the referenced messages are moved to trash here
- no check for the Chat-* headers (function is only called if it is no messenger message itself) */
struct mailimf_field* field;
struct mailimf_field* field = NULL;
if ((field=dc_mimeparser_lookup_field(mime_parser, "In-Reply-To"))!=NULL
&& field->fld_type==MAILIMF_FIELD_IN_REPLY_TO)
{
@ -330,7 +325,8 @@ static dc_array_t* search_chat_ids_by_contact_ids(dc_context_t* context, const d
/* searches chat_id's by the given contact IDs, may return zero, one or more chat_id's */
sqlite3_stmt* stmt = NULL;
dc_array_t* contact_ids = dc_array_new(context, 23);
char* contact_ids_str = NULL, *q3 = NULL;
char* contact_ids_str = NULL;
char* q3 = NULL;
dc_array_t* chat_ids = dc_array_new(context, 23);
if (context == NULL || context->magic != DC_CONTEXT_MAGIC) {
@ -418,13 +414,14 @@ static char* create_adhoc_grp_id(dc_context_t* context, dc_array_t* member_ids /
*/
dc_array_t* member_addrs = dc_array_new(context, 23);
char* member_ids_str = dc_array_get_string(member_ids, ",");
dc_strbuilder_t member_cs;
sqlite3_stmt* stmt = NULL;
char* q3 = NULL, *addr;
int i, iCnt;
char* q3 = NULL;
char* addr = NULL;
int i = 0;
int iCnt = 0;
uint8_t* binary_hash = NULL;
char* ret = NULL;
dc_strbuilder_t member_cs;
dc_strbuilder_init(&member_cs, 0);
/* collect all addresses and sort them */
@ -510,9 +507,11 @@ static void create_or_lookup_adhoc_group(dc_context_t* context, dc_mimeparser_t*
group matching the to-list or if we can create one */
dc_array_t* member_ids = NULL;
uint32_t chat_id = 0;
int chat_id_blocked = 0, i;
int chat_id_blocked = 0;
int i = 0;
dc_array_t* chat_ids = NULL;
char* chat_ids_str = NULL, *q3 = NULL;
char* chat_ids_str = NULL;
char* q3 = NULL;
sqlite3_stmt* stmt = NULL;
char* grpid = NULL;
char* grpname = NULL;
@ -692,11 +691,11 @@ static void create_or_lookup_group(dc_context_t* context, dc_mimeparser_t* mime_
char* grpid = NULL;
char* grpname = NULL;
sqlite3_stmt* stmt;
int i, to_ids_cnt = dc_array_get_cnt(to_ids);
int i = 0;
int to_ids_cnt = dc_array_get_cnt(to_ids);
char* self_addr = NULL;
int recreate_member_list = 0;
int send_EVENT_CHAT_MODIFIED = 0;
char* X_MrRemoveFromGrp = NULL; /* pointer somewhere into mime_parser, must not be freed */
char* X_MrAddToGrp = NULL; /* pointer somewhere into mime_parser, must not be freed */
int X_MrGrpNameChanged = 0;
@ -958,7 +957,8 @@ void dc_receive_imf(dc_context_t* context, const char* imf_raw_not_terminated, s
int add_delete_job = 0;
sqlite3_stmt* stmt = NULL;
size_t i, icnt;
size_t i = 0;
size_t icnt = 0;
uint32_t first_dblocal_id = 0;
char* rfc724_mid = NULL; /* Message-ID from the header */
time_t sort_timestamp = DC_INVALID_TIMESTAMP;

View file

@ -143,9 +143,13 @@ Function based upon ezxml_decode() from the "ezxml" parser which is
Copyright 2004-2006 Aaron Voisine <aaron@voisine.org> */
static char* xml_decode(char* s, char type)
{
char *e, *r = s;
char* e = NULL;
char* r = s;
const char* original_buf = s;
long b, c, d, l;
long b = 0;
long c = 0;
long d = 0;
long l = 0;
for (; *s; s++) { /* normalize line endings */
while (*s == '\r') {
@ -324,7 +328,10 @@ void dc_saxparser_set_text_handler (dc_saxparser_t* saxparser, dc_saxparser_text
void dc_saxparser_parse(dc_saxparser_t* saxparser, const char* buf_start__)
{
char bak, *buf_start, *last_text_start, *p;
char bak = 0;
char* buf_start = NULL;
char* last_text_start = NULL;
char* p = NULL;
#define MAX_ATTR 100 /* attributes per tag - a fixed border here is a security feature, not a limit */
char* attr[(MAX_ATTR+1)*2]; /* attributes as key/value pairs, +1 for terminating the list */

View file

@ -125,8 +125,10 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char
/* split the given buffer into lines */
carray* lines = dc_split_into_lines(buf_terminated);
int l, l_first = 0, l_last = carray_count(lines)-1; /* if l_last is -1, there are no lines */
char* line;
int l = 0;
int l_first = 0;
int l_last = carray_count(lines)-1; /* if l_last is -1, there are no lines */
char* line = NULL;
/* search for the line `-- ` and ignore this and all following lines
If the line contains more characters, it is _not_ treated as the footer start mark (hi, Thorsten) */
@ -303,7 +305,8 @@ static char* dc_simplify_simplify_plain_text(dc_simplify_t* simplify, const char
char* dc_simplify_simplify(dc_simplify_t* simplify, const char* in_unterminated, int in_bytes, int is_html)
{
/* create a copy of the given buffer */
char* out = NULL, *temp = NULL;
char* out = NULL;
char* temp = NULL;
if (simplify == NULL || in_unterminated == NULL || in_bytes <= 0) {
return dc_strdup("");

View file

@ -54,10 +54,9 @@ safe. However, there are some points to keep in mind:
void dc_sqlite3_log_error(dc_sqlite3_t* sql, const char* msg_format, ...)
{
char* msg;
char* msg = NULL;
const char* notSetUp = "SQLite object not set up.";
va_list va;
va_start(va, msg_format);
msg = sqlite3_vmprintf(msg_format, va); if (msg == NULL) { dc_log_error(sql->context, 0, "Bad log format string \"%s\".", msg_format); }
dc_log_error(sql->context, 0, "%s SQLite says: %s", msg, sql->cobj? sqlite3_errmsg(sql->cobj) : notSetUp);
@ -92,7 +91,7 @@ int dc_sqlite3_execute(dc_sqlite3_t* sql, const char* querystr)
{
int success = 0;
sqlite3_stmt* stmt = NULL;
int sqlState;
int sqlState = 0;
stmt = dc_sqlite3_prepare(sql, querystr);
if (stmt == NULL) {
@ -513,7 +512,7 @@ int dc_sqlite3_table_exists(dc_sqlite3_t* sql, const char* name)
int ret = 0;
char* querystr = NULL;
sqlite3_stmt* stmt = NULL;
int sqlState;
int sqlState = 0;
if ((querystr=sqlite3_mprintf("PRAGMA table_info(%s)", name)) == NULL) { /* this statement cannot be used with binded variables */
dc_log_error(sql->context, 0, "dc_sqlite3_table_exists_(): Out of memory.");
@ -553,8 +552,8 @@ cleanup:
int dc_sqlite3_set_config(dc_sqlite3_t* sql, const char* key, const char* value)
{
int state;
sqlite3_stmt* stmt;
int state = 0;
sqlite3_stmt* stmt = NULL;
if (key == NULL) {
dc_log_error(sql->context, 0, "dc_sqlite3_set_config(): Bad parameter.");
@ -614,7 +613,7 @@ int dc_sqlite3_set_config(dc_sqlite3_t* sql, const char* key, const char* value)
char* dc_sqlite3_get_config(dc_sqlite3_t* sql, const char* key, const char* def) /* the returned string must be free()'d, NULL is only returned if def is NULL */
{
sqlite3_stmt* stmt;
sqlite3_stmt* stmt = NULL;
if (!dc_sqlite3_is_open(sql) || key == NULL) {
return dc_strdup_keep_null(def);

View file

@ -124,8 +124,8 @@ char* dc_strbuilder_cat(dc_strbuilder_t* strbuilder, const char* text)
void dc_strbuilder_catf(dc_strbuilder_t* strbuilder, const char* format, ...)
{
char testbuf[1];
char* buf;
int char_cnt_without_zero;
char* buf = NULL;
int char_cnt_without_zero = 0;
va_list argp;
va_list argp_copy;

View file

@ -155,7 +155,7 @@ char* dc_urldecode(const char* to_decode)
static int to_be_quoted(const char * word, size_t size)
{
const char* cur = word;
size_t i;
size_t i = 0;
for (i = 0; i < size; i++)
{
@ -198,10 +198,10 @@ static int to_be_quoted(const char * word, size_t size)
static int quote_word(const char* display_charset, MMAPString* mmapstr, const char* word, size_t size)
{
const char * cur;
size_t i;
const char* cur = NULL;
size_t i = 0;
char hex[4];
int col;
int col = 0;
if (mmap_string_append(mmapstr, "=?") == NULL) {
return 0;
@ -502,9 +502,16 @@ char* dc_encode_modified_utf7(const char* to_encode, int change_spaces)
#define UTF16LOEND 0xDFFFUL
#define UNDEFINED 64
unsigned int utf8pos, utf8total, c, utf7mode, bitstogo, utf16flag;
unsigned long ucs4 = 0, bitbuf = 0;
char *dst, *res;
unsigned int utf8pos = 0;
unsigned int utf8total = 0;
unsigned int c = 0;
unsigned int utf7mode = 0;
unsigned int bitstogo = 0;
unsigned int utf16flag = 0;
unsigned long ucs4 = 0;
unsigned long bitbuf = 0;
char* dst = NULL;
char* res = NULL;
if (!to_encode) {
return dc_strdup("");
@ -635,11 +642,16 @@ char* dc_encode_modified_utf7(const char* to_encode, int change_spaces)
*/
char* dc_decode_modified_utf7(const char *to_decode, int change_spaces)
{
unsigned c, i, bitcount;
unsigned long ucs4, utf16, bitbuf;
unsigned c = 0;
unsigned i = 0;
unsigned bitcount = 0;
unsigned long ucs4 = 0;
unsigned long utf16 = 0;
unsigned long bitbuf = 0;
unsigned char base64[256];
const char *src;
char *dst, *res;
const char* src = NULL;
char* dst = NULL;
char* res = NULL;
if (to_decode == NULL) {
return dc_strdup("");
@ -825,7 +837,8 @@ char* dc_encode_ext_header(const char* to_encode)
*/
char* dc_decode_ext_header(const char* to_decode)
{
char *decoded = NULL, *charset = NULL;
char* decoded = NULL;
char* charset = NULL;
const char* p2 = NULL;
if (to_decode == NULL) {

View file

@ -51,7 +51,7 @@ int dc_exactly_one_bit_set(int v)
char* dc_strdup(const char* s) /* strdup(NULL) is undefined, save_strdup(NULL) returns an empty string in this case */
{
char* ret;
char* ret = NULL;
if (s) {
if ((ret=strdup(s)) == NULL) {
exit(16); /* cannot allocate (little) memory, unrecoverable error */
@ -80,8 +80,8 @@ int dc_atoi_null_is_0(const char* s)
void dc_ltrim(char* buf)
{
size_t len;
const unsigned char* cur;
size_t len = 0;
const unsigned char* cur = NULL;
if (buf && *buf) {
len = strlen(buf);
@ -100,8 +100,8 @@ void dc_ltrim(char* buf)
void dc_rtrim(char* buf)
{
size_t len;
unsigned char* cur;
size_t len = 0;
unsigned char* cur = NULL;
if (buf && *buf) {
len = strlen(buf);
@ -150,7 +150,10 @@ char* dc_strlower(const char* in) /* the result must be free()'d */
*/
int dc_str_replace(char** haystack, const char* needle, const char* replacement)
{
int replacements = 0, start_search_pos = 0, needle_len, replacement_len;
int replacements = 0;
int start_search_pos = 0;
int needle_len = 0;
int replacement_len = 0;
if (haystack==NULL || *haystack==NULL || needle == NULL || needle[0]==0) {
return 0;
@ -242,7 +245,7 @@ char* dc_null_terminate(const char* in, int bytes) /* the result must be free()'
char* dc_binary_to_uc_hex(const uint8_t* buf, size_t bytes)
{
char* hex = NULL;
int i;
int i = 0;
if (buf == NULL || bytes <= 0) {
goto cleanup;
@ -264,8 +267,8 @@ cleanup:
char* dc_mprintf(const char* format, ...)
{
char testbuf[1];
char* buf;
int char_cnt_without_zero;
char* buf = NULL;
int char_cnt_without_zero = 0;
va_list argp;
va_list argp_copy;
@ -369,7 +372,12 @@ void dc_replace_bad_utf8_chars(char* buf)
unsigned char* p1 = (unsigned char*)buf; /* force unsigned - otherwise the `> ' '` comparison will fail */
int p1len = strlen(buf);
int c, i, ix, n, j;
int c = 0;
int i = 0;
int ix = 0;
int n = 0;
int j = 0;
for (i=0, ix=p1len; i < ix; i++)
{
c = p1[i];
@ -407,7 +415,8 @@ error:
#if 0 /* not needed at the moment */
static size_t dc_utf8_strlen(const char* s)
{
size_t i = 0, j = 0;
size_t i = 0;
size_t j = 0;
while (s[i]) {
if ((s[i]&0xC0) != 0x80)
j++;
@ -420,7 +429,8 @@ static size_t dc_utf8_strlen(const char* s)
static size_t dc_utf8_strnlen(const char* s, size_t n)
{
size_t i = 0, j = 0;
size_t i = 0;
size_t j = 0;
while (i < n) {
if ((s[i]&0xC0) != 0x80)
j++;
@ -495,11 +505,11 @@ void dc_truncate_str(char* buf, int approx_chars)
carray* dc_split_into_lines(const char* buf_terminated)
{
carray* lines = carray_new(1024);
size_t line_chars = 0;
const char* p1 = buf_terminated;
const char* line_start = p1;
unsigned int l_indx;
unsigned int l_indx = 0;
while (*p1) {
if (*p1 == '\n') {
carray_add(lines, (void*)strndup(line_start, line_chars), &l_indx);
@ -539,8 +549,10 @@ char* dc_insert_breaks(const char* in, int break_every, const char* break_chars)
return dc_strdup(in);
}
int out_len = strlen(in), chars_added = 0;
int out_len = strlen(in);
int chars_added = 0;
int break_chars_len = strlen(break_chars);
out_len += (out_len/break_every+1)*break_chars_len + 1/*nullbyte*/;
char* out = malloc(out_len);
@ -569,8 +581,7 @@ char* dc_insert_breaks(const char* in, int break_every, const char* break_chars)
void clist_free_content(const clist* haystack)
{
clistiter* iter;
for (iter=clist_begin(haystack); iter!=NULL; iter=clist_next(iter)) {
for (clistiter* iter=clist_begin(haystack); iter!=NULL; iter=clist_next(iter)) {
free(iter->data);
iter->data = NULL;
}
@ -579,8 +590,7 @@ void clist_free_content(const clist* haystack)
int clist_search_string_nocase(const clist* haystack, const char* needle)
{
clistiter* iter;
for (iter=clist_begin(haystack); iter!=NULL; iter=clist_next(iter)) {
for (clistiter* iter=clist_begin(haystack); iter!=NULL; iter=clist_next(iter)) {
if (strcasecmp((const char*)iter->data, needle)==0) {
return 1;
}
@ -596,7 +606,7 @@ int clist_search_string_nocase(const clist* haystack, const char* needle)
static int tmcomp(struct tm * atmp, struct tm * btmp) /* from mailcore2 */
{
int result;
int result = 0;
if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
(result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
@ -610,11 +620,12 @@ static int tmcomp(struct tm * atmp, struct tm * btmp) /* from mailcore2 */
static time_t mkgmtime(struct tm * tmp) /* from mailcore2 */
{
int dir;
int bits;
int saved_seconds;
time_t t;
struct tm yourtm, mytm;
int dir = 0;
int bits = 0;
int saved_seconds = 0;
time_t t = 0;
struct tm yourtm;
struct tm mytm;
yourtm = *tmp;
saved_seconds = yourtm.tm_sec;
@ -656,9 +667,9 @@ static time_t mkgmtime(struct tm * tmp) /* from mailcore2 */
time_t dc_timestamp_from_date(struct mailimf_date_time * date_time) /* from mailcore2 */
{
struct tm tmval;
time_t timeval;
int zone_min;
int zone_hour;
time_t timeval = 0;
int zone_min = 0;
int zone_hour = 0;
tmval.tm_sec = date_time->dt_sec;
tmval.tm_min = date_time->dt_min;
@ -722,11 +733,11 @@ struct mailimap_date_time* dc_timestamp_to_mailimap_date_time(time_t timeval)
{
struct tm gmt;
struct tm lt;
int off;
int off = 0;
struct mailimap_date_time* date_time;
int sign;
int hour;
int min;
int sign = 0;
int hour = 0;
int min = 0;
gmtime_r(&timeval, &gmt);
localtime_r(&timeval, &lt);
@ -911,8 +922,10 @@ char* dc_create_incoming_rfc724_mid(time_t message_timestamp, uint32_t contact_i
}
/* find out the largest receiver ID (we could also take the smallest, but it should be unique) */
size_t i, icnt = dc_array_get_cnt(contact_ids_to);
size_t i = 0;
size_t icnt = dc_array_get_cnt(contact_ids_to);
uint32_t largest_id_to = 0;
for (i = 0; i < icnt; i++) {
uint32_t cur_id = dc_array_get_id(contact_ids_to, i);
if (cur_id > largest_id_to) {
@ -930,8 +943,9 @@ char* dc_extract_grpid_from_rfc724_mid(const char* mid)
{
/* extract our group ID from Message-IDs as `Gr.12345678901.morerandom@domain.de`; "12345678901" is the wanted ID in this example. */
int success = 0;
char* grpid = NULL, *p1;
int grpid_len;
char* grpid = NULL;
char* p1 = NULL;
int grpid_len = 0;
if (mid == NULL || strlen(mid)<8 || mid[0]!='G' || mid[1]!='r' || mid[2]!='.') {
goto cleanup;
@ -961,9 +975,8 @@ cleanup:
char* dc_extract_grpid_from_rfc724_mid_list(const clist* list)
{
clistiter* cur;
if (list) {
for (cur = clist_begin(list); cur!=NULL ; cur=clist_next(cur)) {
for (clistiter* cur = clist_begin(list); cur!=NULL ; cur=clist_next(cur)) {
const char* mid = clist_content(cur);
char* grpid = dc_extract_grpid_from_rfc724_mid(mid);
if (grpid) {
@ -1039,10 +1052,12 @@ int dc_delete_file(const char* pathNfilename, dc_context_t* log/*may be NULL*/)
int dc_copy_file(const char* src, const char* dest, dc_context_t* log/*may be NULL*/)
{
int success = 0, fd_src = -1, fd_dest = -1;
int success = 0;
int fd_src = -1;
int fd_dest = -1;
#define DC_COPY_BUF_SIZE 4096
char buf[DC_COPY_BUF_SIZE];
size_t bytes_read;
size_t bytes_read = 0;
int anything_copied = 0;
if (src==NULL || dest==NULL) {
@ -1118,8 +1133,10 @@ void dc_split_filename(const char* pathNfilename, char** ret_basename, char** re
maybe the detection could be more intelligent, however, for the moment, it is just file)
- if there is no suffix, the returned suffix string is empty, eg. "/path/foobar" is split into "foobar" and ""
- the case of the returned suffix is preserved; this is to allow reconstruction of (similar) names */
char* basename = dc_get_filename(pathNfilename), *suffix;
char* basename = dc_get_filename(pathNfilename);
char* suffix = NULL;
char* p1 = strrchr(basename, '.');
if (p1) {
suffix = dc_strdup(p1);
*p1 = 0;
@ -1150,10 +1167,13 @@ void dc_validate_filename(char* filename)
char* dc_get_fine_pathNfilename(const char* folder, const char* desired_filenameNsuffix__)
{
char* ret = NULL, *filenameNsuffix, *basename = NULL, *dotNSuffix = NULL;
char* ret = NULL;
char* filenameNsuffix = NULL;
char* basename = NULL;
char* dotNSuffix = NULL;
time_t now = time(NULL);
struct stat st;
int i;
int i = 0;
filenameNsuffix = dc_strdup(desired_filenameNsuffix__);
dc_validate_filename(filenameNsuffix);