Mercurial > libpst
changeset 47:5fb8d997feed
more fixes for 64 bit format
author | carl |
---|---|
date | Sun, 13 Jan 2008 12:55:59 -0800 |
parents | b2a7f2e0926a |
children | f66078abed38 |
files | ChangeLog TODO configure.in src/libpst.c src/libpst.h |
diffstat | 5 files changed, 83 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sat Jan 12 15:20:53 2008 -0800 +++ b/ChangeLog Sun Jan 13 12:55:59 2008 -0800 @@ -1,3 +1,8 @@ +LibPST 0.6.3 (2008-01-13) +=============================== + + * More type consistency issues found by splint. + LibPST 0.6.2 (2008-01-12) =============================== @@ -5,6 +10,7 @@ * All buffer sizes changed to size_t, all file offsets changed to off_t, all function names start with pst_, many other type consistency issues found by splint. Many changes to #llx in debug printing for 64 bit items. + All id values are now uint64_t. LibPST 0.6.1 (2008-01-06) ===============================
--- a/TODO Sat Jan 12 15:20:53 2008 -0800 +++ b/TODO Sun Jan 13 12:55:59 2008 -0800 @@ -0,0 +1,7 @@ +Code items that seems to be incorrect, but need verification: + +1) case 0x360A: // PR_SUBFOLDERS Has children + +Is that really an int32_t flag. All the other boolean flags seem be +int16_t. +
--- a/configure.in Sat Jan 12 15:20:53 2008 -0800 +++ b/configure.in Sun Jan 13 12:55:59 2008 -0800 @@ -1,7 +1,7 @@ AC_INIT(configure.in) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(libpst,0.6.2) +AM_INIT_AUTOMAKE(libpst,0.6.3) AC_PATH_PROGS(BASH, bash) AC_LANG_CPLUSPLUS
--- a/src/libpst.c Sat Jan 12 15:20:53 2008 -0800 +++ b/src/libpst.c Sun Jan 13 12:55:59 2008 -0800 @@ -455,7 +455,7 @@ wt = (char*) xmalloc((size_t)(tint+2)); // plus 2 for a uni-code zero memset(wt, 0, (size_t)(tint+2)); memcpy(wt, &(headerbuffer[xattrib.extended+sizeof(tint)]), (size_t)tint); - ptr->data = pst_wide_to_single(wt, tint); + ptr->data = pst_wide_to_single(wt, (size_t)tint); free(wt); DEBUG_INDEX(("Read string (converted from UTF-16): %s\n", ptr->data)); } else { @@ -1263,7 +1263,7 @@ int count_rec; int32_t num_list; int32_t cur_list; - int32_t block_type; + int block_type; uint32_t rec_size = 0; uint32_t ind_ptr; unsigned char* list_start; @@ -1400,7 +1400,7 @@ } rec_size = seven_c_blk.rec_size; - num_list = seven_c_blk.item_count; + num_list = (int32_t)(unsigned)seven_c_blk.item_count; if (pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, seven_c_blk.b_five_offset, &block_offset4)) { DEBUG_WARN(("internal error (7c.b5 offset %#x) in reading block id %#x\n", seven_c_blk.b_five_offset, block_id)); @@ -1471,7 +1471,7 @@ na_ptr->items = (struct pst_num_item**) xmalloc(sizeof(struct pst_num_item)*num_list); na_ptr->count_item = num_list; na_ptr->orig_count = num_list; - na_ptr->count_array = num_recs; // each record will have a record of the total number of records + na_ptr->count_array = (int32_t)num_recs; // each record will have a record of the total number of records for (x=0; x<num_list; x++) na_ptr->items[x] = NULL; x = 0; @@ -1481,13 +1481,13 @@ for (cur_list=0; cur_list<num_list; cur_list++) { //we will increase fr_ptr as we progress through index unsigned char* value_pointer = NULL; // needed for block type 2 with values larger than 4 bytes size_t value_size = 0; - if (block_type == (int32_t)1) { + if (block_type == 1) { memcpy(&table_rec, fr_ptr, sizeof(table_rec)); LE16_CPU(table_rec.type); LE16_CPU(table_rec.ref_type); //LE32_CPU(table_rec.value); // done later, some may be order invariant fr_ptr += sizeof(table_rec); - } else if (block_type == (int32_t)2) { + } else if (block_type == 2) { // we will copy the table2_rec values into a table_rec record so that we can keep the rest of the code memcpy(&table2_rec, fr_ptr, sizeof(table2_rec)); LE16_CPU(table2_rec.ref_type); @@ -1720,7 +1720,7 @@ int pst_process(pst_num_array *list , pst_item *item, pst_item_attach *attach) { int32_t x, t; - int32_t next = 0; + int next = 0; pst_item_extra_field *ef; DEBUG_ENT("pst_process"); @@ -1752,7 +1752,7 @@ // If set to true, the sender allows this email to be autoforwarded DEBUG_EMAIL(("AutoForward allowed - ")); MALLOC_EMAIL(item); - if (*((short int*)list->items[x]->data) != 0) { + if (*(int16_t*)list->items[x]->data != 0) { DEBUG_EMAIL(("True\n")); item->email->autoforward = 1; } else { @@ -1774,7 +1774,7 @@ memcpy(&(item->email->importance), list->items[x]->data, sizeof(item->email->importance)); LE32_CPU(item->email->importance); t = item->email->importance; - DEBUG_EMAIL(("%s [%i]\n", (t==0?"Low":(t==1?"Normal":"High")), t)); + DEBUG_EMAIL(("%s [%i]\n", ((int)t==0?"Low":((int)t==1?"Normal":"High")), t)); break; case 0x001A: // PR_MESSAGE_CLASS Ascii type of messages - NOT FOLDERS // must be case insensitive @@ -1828,7 +1828,7 @@ case 0x0029:// PR_READ_RECEIPT_REQUESTED DEBUG_EMAIL(("Read Receipt - ")); MALLOC_EMAIL(item); - if (*(short int*)list->items[x]->data != 0) { + if (*(int16_t*)list->items[x]->data != 0) { DEBUG_EMAIL(("True\n")); item->email->read_receipt = 1; } else { @@ -1838,7 +1838,7 @@ break; case 0x002B: // PR_RECIPIENT_REASSIGNMENT_PROHIBITED DEBUG_EMAIL(("Reassignment Prohibited (Private) - ")); - if (*(short int*)list->items[x]->data != 0) { + if (*(int16_t*)list->items[x]->data != 0) { DEBUG_EMAIL(("True\n")); item->private_member = 1; } else { @@ -1857,8 +1857,8 @@ memcpy(&(item->email->orig_sensitivity), list->items[x]->data, sizeof(item->email->orig_sensitivity)); LE32_CPU(item->email->orig_sensitivity); t = item->email->orig_sensitivity; - DEBUG_EMAIL(("%s [%i]\n", (t==0?"None":(t==1?"Personal": - (t==2?"Private":"Company Confidential"))), t)); + DEBUG_EMAIL(("%s [%i]\n", ((int)t==0?"None":((int)t==1?"Personal": + ((int)t==2?"Private":"Company Confidential"))), t)); break; case 0x0036: // PR_SENSITIVITY // sender's opinion of the sensitivity of an email @@ -1871,11 +1871,10 @@ memcpy(&(item->email->sensitivity), list->items[x]->data, sizeof(item->email->sensitivity)); LE32_CPU(item->email->sensitivity); t = item->email->sensitivity; - DEBUG_EMAIL(("%s [%i]\n", (t==0?"None":(t==1?"Personal": - (t==2?"Private":"Company Confidential"))), t)); + DEBUG_EMAIL(("%s [%i]\n", ((int)t==0?"None":((int)t==1?"Personal": + ((int)t==2?"Private":"Company Confidential"))), t)); break; case 0x0037: // PR_SUBJECT raw subject - // if (list->items[x]->id == 0x0037) { DEBUG_EMAIL(("Raw Subject - ")); MALLOC_EMAIL(item); item->email->subject = (pst_item_email_subject*) realloc(item->email->subject, sizeof(pst_item_email_subject)); @@ -1892,9 +1891,9 @@ } else { DEBUG_EMAIL(("Raw Subject has control codes\n")); // there might be some control bytes in the first and second bytes - item->email->subject->off1 = list->items[x]->data[0]; - item->email->subject->off2 = list->items[x]->data[1]; - item->email->subject->subj = realloc(item->email->subject->subj, (list->items[x]->size-2)+1); + item->email->subject->off1 = (int)(unsigned)list->items[x]->data[0]; + item->email->subject->off2 = (int)(unsigned)list->items[x]->data[1]; + item->email->subject->subj = realloc(item->email->subject->subj, list->items[x]->size-1); memset(item->email->subject->subj, 0, list->items[x]->size-1); memcpy(item->email->subject->subj, &(list->items[x]->data[2]), list->items[x]->size-2); } @@ -2103,7 +2102,7 @@ // I am not too sure how this works DEBUG_EMAIL(("Delete after submit - ")); MALLOC_EMAIL(item); - if (*(int16_t*) list->items[x]->data != 0) { + if (*(int16_t*)list->items[x]->data != 0) { DEBUG_EMAIL(("True\n")); item->email->delete_after_submit = 1; } else { @@ -2357,7 +2356,7 @@ case 0x360A: // PR_SUBFOLDERS Has children DEBUG_EMAIL(("Has Subfolders - ")); MALLOC_FOLDER(item); - if (*((int32_t*)list->items[x]->data) != 0) { + if (*(int32_t*)list->items[x]->data != 0) { DEBUG_EMAIL(("True\n")); item->folder->subfolder = 1; } else { @@ -2754,7 +2753,7 @@ case 0x3A40: // PR_SEND_RICH_INFO DEBUG_EMAIL(("Can receive Rich Text - ")); MALLOC_CONTACT(item); - if(*(int16_t*)list->items[x]->data != 0) { + if (*(int16_t*)list->items[x]->data != 0) { DEBUG_EMAIL(("True\n")); item->contact->rich_text = 1; } else { @@ -3278,26 +3277,26 @@ - 0x1102 - Array of Binary data */ // DEBUG_EMAIL(("Unknown id [%#x, size=%#x]\n", list->items[x]->id, list->items[x]->size)); - if (list->items[x]->type == 0x02) { + if (list->items[x]->type == (uint32_t)0x02) { DEBUG_EMAIL(("Unknown 16bit int = %hi\n", *(int16_t*)list->items[x]->data)); - } else if (list->items[x]->type == 0x03) { + } else if (list->items[x]->type == (uint32_t)0x03) { DEBUG_EMAIL(("Unknown 32bit int = %i\n", *(int32_t*)list->items[x]->data)); - } else if (list->items[x]->type == 0x0b) { + } else if (list->items[x]->type == (uint32_t)0x0b) { DEBUG_EMAIL(("Unknown 16bit boolean = %s [%hi]\n", (*((int16_t*)list->items[x]->data)!=0?"True":"False"), *((int16_t*)list->items[x]->data))); - } else if (list->items[x]->type == 0x1e) { + } else if (list->items[x]->type == (uint32_t)0x1e) { DEBUG_EMAIL(("Unknown String Data = \"%s\" [%#x]\n", list->items[x]->data, list->items[x]->type)); - } else if (list->items[x]->type == 0x40) { + } else if (list->items[x]->type == (uint32_t)0x40) { DEBUG_EMAIL(("Unknown Date = \"%s\" [%#x]\n", fileTimeToAscii((FILETIME*)list->items[x]->data), list->items[x]->type)); - } else if (list->items[x]->type == 0x102) { + } else if (list->items[x]->type == (uint32_t)0x102) { DEBUG_EMAIL(("Unknown Binary Data [size = %#x]\n", list->items[x]->size)); DEBUG_HEXDUMP(list->items[x]->data, list->items[x]->size); - } else if (list->items[x]->type == 0x101E) { + } else if (list->items[x]->type == (uint32_t)0x101E) { DEBUG_EMAIL(("Unknown Array of Strings [%#x]\n", list->items[x]->type)); } else { @@ -3432,7 +3431,7 @@ LE16_CPU(block_head.count); if (block_head.type != (uint16_t)0x0002) { // some sort of constant? - WARN(("Unknown constant [%#x] at start of id2 values [offset %#llx].\n", block_head.type, list->offset)); + WARN(("Unknown constant [%#hx] at start of id2 values [offset %#llx].\n", block_head.type, list->offset)); if (buf) free(buf); DEBUG_RET(); return NULL; @@ -3930,7 +3929,7 @@ buf3 = (char*) realloc(buf3, size+1); buf3[size] = '\0'; *buf = buf3; - fseek(pf->fp, fpos, SEEK_SET); + (void)fseek(pf->fp, fpos, SEEK_SET); DEBUG_RET(); return size; } @@ -3938,7 +3937,7 @@ buf3 = (char*) realloc(buf3, size+1); buf3[size] = '\0'; *buf = buf3; - fseek(pf->fp, fpos, SEEK_SET); + (void)fseek(pf->fp, fpos, SEEK_SET); DEBUG_RET(); return size; } @@ -4035,7 +4034,7 @@ DEBUG_RET(); return 1; } - if (fread(buf, 1, size, fp) < size) { + if (fread(buf, (size_t)1, size, fp) < size) { DEBUG_RET(); return 2; } @@ -4046,7 +4045,7 @@ int pst_get (FILE *fp, void *buf, size_t size) { DEBUG_ENT("pst_get"); - if (fread(buf, 1, size, fp) < size) { + if (fread(buf, (size_t)1, size, fp) < size) { DEBUG_RET(); return 1; } @@ -4087,7 +4086,7 @@ DEBUG_INDEX(("id = %#x, record size = %#x, offset = %#x\n", id, rec->size, rec->offset)); *b = (char*) xmalloc(rec->size+1); - rsize = fread(*b, 1, rec->size, pf->fp); + rsize = fread(*b, (size_t)1, rec->size, pf->fp); if (rsize != rec->size) { DEBUG_WARN(("Didn't read all the size. fread returned less [%i instead of %i]\n", rsize, rec->size)); if (feof(pf->fp)) { @@ -4132,12 +4131,12 @@ } else if ((h->base64 == 1) && h->fp) { t = base64_encode(b, ret); if (t) { - (void)pst_fwrite(t, 1, strlen(t), h->fp); + (void)pst_fwrite(t, (size_t)1, strlen(t), h->fp); free(t); // caught by valgrind } free(b); } else if (h->fp) { - (void)pst_fwrite(b, 1, ret, h->fp); + (void)pst_fwrite(b, (size_t)1, ret, h->fp); free(b); } else { // h-> does not specify any output @@ -4178,12 +4177,12 @@ else if (h->base64 == 1 && h->fp) { t = base64_encode(buf3, a); if (t) { - (void)pst_fwrite(t, 1, strlen(t), h->fp); + (void)pst_fwrite(t, (size_t)1, strlen(t), h->fp); free(t); // caught by valgrind } free(buf3); } else if (h->fp) { - (void)pst_fwrite(buf3, 1, a, h->fp); + (void)pst_fwrite(buf3, (size_t)1, a, h->fp); free(buf3); } else { // h-> does not specify any output @@ -4227,12 +4226,12 @@ t = base64_encode(buf2, z-b); if (t) { DEBUG_READ(("writing %i bytes to file as base64 [%i]. Currently %i\n", z, strlen(t), size)); - (void)pst_fwrite(t, 1, strlen(t), h->fp); + (void)pst_fwrite(t, (size_t)1, strlen(t), h->fp); free(t); // caught by valgrind } } else if (h->fp) { DEBUG_READ(("writing %i bytes to file. Currently %i\n", z, size)); - (void)pst_fwrite(buf2, 1, z, h->fp); + (void)pst_fwrite(buf2, (size_t)1, z, h->fp); } else { // h-> does not specify any output } @@ -4341,7 +4340,7 @@ } -char * pst_wide_to_single(char *wt, int32_t size) { +char * pst_wide_to_single(char *wt, size_t size) { // returns the first byte of each wide char. the size is the number of bytes in source char *x, *y; DEBUG_ENT("pst_wide_to_single"); @@ -4362,7 +4361,8 @@ char *pst_rfc2426_escape(char *str) { static char* buf = NULL; char *ret, *a, *b; - int x = 0, y, z; + size_t x = 0; + int y, z; DEBUG_ENT("rfc2426_escape"); if (!str) ret = str; @@ -4423,12 +4423,11 @@ char *pst_rfc2425_datetime_format(FILETIME *ft) { - static char* buffer = NULL; + static char buffer[30]; struct tm *stm = NULL; DEBUG_ENT("rfc2425_datetime_format"); - if (!buffer) buffer = malloc(30); // should be enough for the date as defined below stm = fileTimeToStructTM(ft); - if (strftime(buffer, 30, "%Y-%m-%dT%H:%M:%SZ", stm)==0) { + if (strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%SZ", stm)==0) { DEBUG_INFO(("Problem occured formatting date\n")); } DEBUG_RET(); @@ -4437,12 +4436,11 @@ char *pst_rfc2445_datetime_format(FILETIME *ft) { - static char* buffer = NULL; + static char buffer[30]; struct tm *stm = NULL; DEBUG_ENT("rfc2445_datetime_format"); - if (!buffer) buffer = malloc(30); // should be enough for the date as defined below stm = fileTimeToStructTM(ft); - if (strftime(buffer, 30, "%Y%m%dT%H%M%SZ", stm)==0) { + if (strftime(buffer, sizeof(buffer), "%Y%m%dT%H%M%SZ", stm)==0) { DEBUG_INFO(("Problem occured formatting date\n")); } DEBUG_RET();
--- a/src/libpst.h Sat Jan 12 15:20:53 2008 -0800 +++ b/src/libpst.h Sun Jan 13 12:55:59 2008 -0800 @@ -191,21 +191,21 @@ } pst_desc_ll; typedef struct pst_item_email_subject { - int32_t off1; - int32_t off2; + int off1; + int off2; char *subj; } pst_item_email_subject; typedef struct pst_item_email { FILETIME *arrival_date; - int32_t autoforward; // 1 = true, 0 = not set, -1 = false + int autoforward; // 1 = true, 0 = not set, -1 = false char *body; char *cc_address; char *common_name; int32_t conv_index; - int32_t conversion_prohib; - int32_t delete_after_submit; // 1 = true, 0 = false - int32_t delivery_report; // 1 = true, 0 = false + int conversion_prohib; // 1 = true, 0 = false + int delete_after_submit; // 1 = true, 0 = false + int delivery_report; // 1 = true, 0 = false char *encrypted_body; int32_t encrypted_body_size; char *encrypted_htmlbody; @@ -215,9 +215,9 @@ char *htmlbody; int32_t importance; char *in_reply_to; - int32_t message_cc_me; // 1 = true, 0 = false - int32_t message_recip_me; // 1 = true, 0 = false - int32_t message_to_me; // 1 = true, 0 = false + int message_cc_me; // 1 = true, 0 = false + int message_recip_me; // 1 = true, 0 = false + int message_to_me; // 1 = true, 0 = false char *messageid; int32_t orig_sensitivity; char *outlook_recipient; @@ -227,12 +227,12 @@ char *outlook_sender2; int32_t priority; char *proc_subject; - int32_t read_receipt; + int read_receipt; // 1 = true, 0 = false char *recip_access; char *recip_address; char *recip2_access; char *recip2_address; - int32_t reply_requested; + int reply_requested; // 1 = true, 0 = false char *reply_to; char *return_path_address; int32_t rtf_body_char_count; @@ -240,7 +240,7 @@ char *rtf_body_tag; char *rtf_compressed; uint32_t rtf_compressed_size; - int32_t rtf_in_sync; // 1 = true, 0 = doesn't exist, -1 = false + int rtf_in_sync; // 1 = true, 0 = doesn't exist, -1 = false int32_t rtf_ws_prefix_count; int32_t rtf_ws_trailing_count; char *sender_access; @@ -258,7 +258,7 @@ int32_t email_count; int32_t unseen_email_count; int32_t assoc_count; - char subfolder; + int subfolder; // 1 = true, 0 = false } pst_item_folder; typedef struct pst_item_message_store { @@ -333,7 +333,7 @@ char *keyword; char *language; char *location; - int32_t mail_permission; + int mail_permission; // 1 = true, 0 = false char *manager_name; char *middle_name; char *mileage; @@ -356,7 +356,7 @@ char *primary_phone; char *profession; char *radio_phone; - int32_t rich_text; + int rich_text; // 1 = true, 0 = false char *spouse_name; char *suffix; char *surname; @@ -397,10 +397,10 @@ char *location; FILETIME *reminder; FILETIME *start; - char *timezonestring; + char *timezonestring; int32_t showas; int32_t label; - int32_t all_day; + int all_day; // 1 = true, 0 = false } pst_item_appointment; typedef struct pst_item { @@ -412,7 +412,7 @@ struct pst_item_extra_field *extra_fields; // linked list of extra headers and such struct pst_item_journal *journal; // data reffering to a journal entry struct pst_item_appointment *appointment; // data reffering to a calendar entry - int32_t type; + int type; char *ascii_type; char *file_as; char *comment; @@ -420,10 +420,10 @@ char *outlook_version; char *record_key; // probably 16 bytes long. size_t record_key_size; - int32_t response_requested; + int response_requested; // 1 = true, 0 = false FILETIME *create_date; FILETIME *modify_date; - int32_t private_member; + int private_member; // 1 = true, 0 = false } pst_item; typedef struct pst_x_attrib_ll { @@ -468,7 +468,7 @@ struct pst_num_item { uint32_t id; unsigned char *data; - uint32_t type; + uint32_t type; size_t size; char *extra; }; @@ -533,7 +533,7 @@ int pst_strincmp(char *a, char *b, size_t x); int pst_stricmp(char *a, char *b); size_t pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream); -char * pst_wide_to_single(char *wt, int32_t size); +char * pst_wide_to_single(char *wt, size_t size); char * pst_rfc2426_escape(char *str); int pst_chr_count(char *str, char x);