#include "cal_vcalendar.h"
#include "cal_vcalendar_make.h"
#include "cal_vcalendar_parse.h"
+#include "cal_utils.h"
#define ICALENAR_BUFFER_MAX (1024*1024)
foreach_data->user_data = user_data;
foreach_data->ret = true;
+ int error = CALENDAR_ERROR_NONE;
+
while (fgets(buf, sizeof(buf), file)) {
- if (len + sizeof(buf) < buf_size) {
- len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
- } else {
+ int added_len = cal_add_safe(len, strlen(buf));
+ if (added_len < 0) {
+ ERR("cal_add_safe() Fail");
+ error = CALENDAR_ERROR_SYSTEM;
+ break;
+ }
+ if (buf_size <= added_len) {
char *new_stream;
buf_size *= 2;
new_stream = realloc(stream, buf_size);
- if (new_stream) {
- stream = new_stream;
- } else {
+ if (NULL == new_stream) {
/* LCOV_EXCL_START */
ERR("out of memory");
- free(stream);
- fclose(file);
- free(foreach_data);
- calendar_list_destroy(list, true);
- return CALENDAR_ERROR_OUT_OF_MEMORY;
+ error = CALENDAR_ERROR_OUT_OF_MEMORY;
+ break;
/* LCOV_EXCL_STOP */
}
- len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
+ stream = new_stream;
+ }
+
+ int copyed_len = snprintf(stream + len, strlen(buf) +1, "%s", buf);
+ len = cal_add_safe(copyed_len, len);
+ if (len < 0) {
+ /* LCOV_EXCL_START */
+ ERR("cal_add_safe() Fail");
+ error = CALENDAR_ERROR_SYSTEM;
+ break;
+ /* LCOV_EXCL_STOP */
}
if (CAL_STRING_EQUAL == strncmp(buf, "END:VCALENDAR", strlen("END:VCALENDAR"))) {
DBG("end vcalendar");
- int err;
char *vcalendar_object = NULL;
__calendar_vcalendar_get_vcalendar_object(stream, &vcalendar_object);
- err = cal_vcalendar_parse_vcalendar_object(vcalendar_object, list, foreach_data);
- if (CALENDAR_ERROR_NONE != err || false == foreach_data->ret) {
+ error = cal_vcalendar_parse_vcalendar_object(vcalendar_object, list, foreach_data);
+ if (CALENDAR_ERROR_NONE != error) {
+ /* LCOV_EXCL_START */
+ ERR("cal_vcalendar_parse_vcalendar_object() failed(%d)", error);
+ free(vcalendar_object);
+ break;
+ /* LCOV_EXCL_STOP */
+ }
+ if (false == foreach_data->ret) {
/* LCOV_EXCL_START */
- ERR("cal_vcalendar_parse_vcalendar_object() failed(%d)", err);
- calendar_list_destroy(list, true);
+ ERR("foreach_data->ret is NULL");
free(vcalendar_object);
- free(stream);
- free(foreach_data);
- fclose(file);
- return err;
+ error = CALENDAR_ERROR_SYSTEM;
+ break;
/* LCOV_EXCL_STOP */
}
free(vcalendar_object);
free(foreach_data);
fclose(file);
- return CALENDAR_ERROR_NONE;
+ return error;
}