Browse Source

Merged in audit_branch fixes

IOSAD-186
parent
commit
af680d4a14
6 changed files with 92 additions and 40 deletions
  1. +1
    -0
      src/aux_mime_msg.c
  2. +16
    -23
      src/bloblist.c
  3. +15
    -0
      src/bloblist.h
  4. +1
    -1
      src/pEpEngine.c
  5. +41
    -16
      src/stringlist.c
  6. +18
    -0
      test/src/StringlistTest.cc

+ 1
- 0
src/aux_mime_msg.c View File

@ -278,5 +278,6 @@ pEp_error:
return status;
}
#else
// This is here to please ISO C - it needs a compilation unit. Value will never be used.
const int the_answer_my_friend = 42;
#endif

+ 16
- 23
src/bloblist.c View File

@ -80,47 +80,37 @@ DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src)
assert(src);
if (src == NULL)
return NULL;
bloblist_t *bloblist = NULL;
// head
char *blob2 = malloc(src->size);
assert(blob2);
if (blob2 == NULL)
goto enomem;
memcpy(blob2, src->value, src->size);
bloblist_t* head_ptr = NULL;
bloblist_t** dst_curr_ptr = &head_ptr;
bloblist = new_bloblist(blob2, src->size, src->mime_type, src->filename);
if (bloblist == NULL)
goto enomem;
blob2 = NULL;
const bloblist_t* src_curr = src;
bloblist_t* src_curr = src->next;
bloblist_t** dst_curr_ptr = &bloblist->next;
char* blob2 = NULL;
// list
while (src_curr) {
for ( ; src_curr; src_curr = src_curr->next, dst_curr_ptr = &((*dst_curr_ptr)->next)) {
blob2 = malloc(src_curr->size);
assert(blob2);
if (blob2 == NULL)
goto enomem;
// This is why we don't calloc
memcpy(blob2, src_curr->value, src_curr->size);
*dst_curr_ptr = new_bloblist(blob2, src_curr->size, src_curr->mime_type, src_curr->filename);
if (*dst_curr_ptr == NULL)
goto enomem;
src_curr = src_curr->next;
dst_curr_ptr = &((*dst_curr_ptr)->next);
}
return bloblist;
if (!head_ptr)
return NULL;
return head_ptr;
enomem:
free(blob2);
free_bloblist(bloblist);
free_bloblist(head_ptr);
return NULL;
}
@ -168,7 +158,10 @@ DYNAMIC_API bloblist_t* bloblist_join(bloblist_t* first, bloblist_t* second) {
return second;
if (!second)
return first;
if (first == second)
return first;
bloblist_t* list_curr = first;
while (list_curr->next) {


+ 15
- 0
src/bloblist.h View File

@ -126,6 +126,21 @@ DYNAMIC_API int bloblist_length(const bloblist_t *bloblist);
DYNAMIC_API void set_blob_disposition(bloblist_t* blob,
content_disposition_type disposition);
// bloblist_join() - append second list to the first.
//
// parameters:
// first (in) first bloblist, to be head of list if not NULL
// second (in) bloblist to append to first bloblist; if first
// bloblist is NULL, this will be the head of the list
//
// return value:
// head of the joined bloblist
//
// caveats:
// This function appends the actual bloblist to the end of the first - ownership
// of the second bloblist goes to the list. THERE IS NO COPYING.
// Also, if the same pointer is sent in twice, there is no join - the original
// list will be returned as is.
DYNAMIC_API bloblist_t* bloblist_join(bloblist_t* first, bloblist_t* second);
#ifdef __cplusplus


+ 1
- 1
src/pEpEngine.c View File

@ -2760,7 +2760,7 @@ DYNAMIC_API PEP_STATUS log_event(
{
#if defined(_WIN32) && !defined(NDEBUG)
log_output_debug(title, entity, description, comment);
log_output_debug(title, entity, description, comment);
#endif
#if defined(ANDROID) && !defined(NDEBUG)


+ 41
- 16
src/stringlist.c View File

@ -139,31 +139,35 @@ DYNAMIC_API stringlist_t *stringlist_add_unique(
return NULL;
stringlist_t *result = NULL;
if(_stringlist_add_first(stringlist, &result, value))
return result;
if (!stringlist)
return NULL; // If the previous call fails somehow. this code is bizarre.
stringlist_t* list_curr = stringlist;
bool found = false;
while (list_curr->next) {
if(strcmp(list_curr->value,value)==0)
found = true;
stringlist_t** next_ptr_addr = NULL;
while (list_curr) {
next_ptr_addr = &list_curr->next;
if (strcmp(list_curr->value, value) == 0)
return list_curr;
list_curr = list_curr->next;
}
if(strcmp(list_curr->value,value)==0)
found = true;
if (!found) {
list_curr->next = new_stringlist(value);
if (!next_ptr_addr)
return NULL; // This is an error, because stringlist_add_first should
// have handled this case
assert(list_curr->next);
if (list_curr->next == NULL)
return NULL;
*next_ptr_addr = new_stringlist(value);
if (!*next_ptr_addr)
return NULL;
return *next_ptr_addr;
return list_curr->next;
} else {
return list_curr;
}
}
@ -181,6 +185,27 @@ DYNAMIC_API stringlist_t *stringlist_append(
return stringlist;
stringlist_t *_s = stringlist;
if (stringlist == second) {
// Passing in the same pointer twice is not cool.
// Since the semantics are to copy the second list,
// we'll just do that, presuming that the
// caller wants this.
second = stringlist_dup(stringlist);
stringlist_t** end_ptr = NULL;
while (_s) {
end_ptr = &_s->next;
_s = _s->next;
}
if (!end_ptr)
return NULL;
*end_ptr = second;
return stringlist;
}
stringlist_t *_s2;
for (_s2 = second; _s2 != NULL; _s2 = _s2->next) {
_s = stringlist_add(_s, _s2->value);


+ 18
- 0
test/src/StringlistTest.cc View File

@ -365,3 +365,21 @@ TEST_F(StringlistTest, check_string_to_stringlist_commas_to_two) {
ASSERT_STREQ(sl->value, str0);
ASSERT_STREQ(sl->next->value, str1);
}
TEST_F(StringlistTest, check_stringlist_append_self) {
const char* str0 = "I am so tired";
const char* str1 = "of doing stuff";
const char* str2 = "Bob";
stringlist_t* s1 = new_stringlist(str0);
stringlist_add(s1, str1);
stringlist_add(s1, str2);
ASSERT_EQ(stringlist_length(s1), 3);
stringlist_t* s2 = stringlist_append(s1, s1);
ASSERT_EQ(s1, s2);
ASSERT_EQ(stringlist_length(s1), 6);
ASSERT_STREQ(str0, s1->next->next->next->value);
ASSERT_STREQ(str1, s1->next->next->next->next->value);
ASSERT_STREQ(str2, s1->next->next->next->next->next->value);
}

Loading…
Cancel
Save