diff --git a/seabolt/src/bolt/logging.c b/seabolt/src/bolt/logging.c index 16889a08..b6725998 100644 --- a/seabolt/src/bolt/logging.c +++ b/seabolt/src/bolt/logging.c @@ -48,16 +48,19 @@ void BoltLog_destroy(struct BoltLog* log) void _perform_log_call(log_func func, int state, const char* format, va_list args) { - int size = 512*sizeof(char); + size_t size = 512*sizeof(char); char* message_fmt = (char*) BoltMem_allocate(size); while (1) { - int written = vsnprintf(message_fmt, size, format, args); + va_list args_copy; + va_copy(args_copy, args); + size_t written = vsnprintf(message_fmt, size, format, args_copy); + va_end(args_copy); if (writtendebug_enabled) { - const char* message_name = NULL; + const char* message_name = "?"; if (message_name_resolver!=NULL) { message_name = message_name_resolver(code); } struct StringBuilder* builder = StringBuilder_create(); BoltValue_write(builder, fields, struct_name_resolver); - BoltLog_debug(log, "%s[%" PRIu64 "] %s %s", peer, request_id, message_name==NULL ? "?" : message_name, - StringBuilder_get_string(builder)); + BoltLog_debug(log, "%s[%" PRIu64 "] %s %s", peer, request_id, message_name, StringBuilder_get_string(builder)); StringBuilder_destroy(builder); } } diff --git a/seabolt/src/bolt/utils.c b/seabolt/src/bolt/utils.c index 4c71c0f6..04cd59e9 100644 --- a/seabolt/src/bolt/utils.c +++ b/seabolt/src/bolt/utils.c @@ -26,10 +26,10 @@ struct StringBuilder* StringBuilder_create() { struct StringBuilder* builder = (struct StringBuilder*) BoltMem_allocate(sizeof(struct StringBuilder)); - builder->buffer = BoltMem_allocate(1*sizeof(char)); - builder->buffer[0] = '\0'; + builder->buffer = (char*) BoltMem_allocate(256*sizeof(char)); + builder->buffer[0] = 0; builder->buffer_pos = 0; - builder->buffer_size = 1; + builder->buffer_size = 256; return builder; } @@ -45,7 +45,7 @@ void StringBuilder_ensure_buffer(struct StringBuilder* builder, size_t size_to_a return; } - size_t new_size = builder->buffer_pos+size_to_add+1; + size_t new_size = builder->buffer_pos+size_to_add; builder->buffer = (char*) BoltMem_reallocate(builder->buffer, builder->buffer_size, new_size); builder->buffer_size = new_size; } @@ -57,27 +57,27 @@ void StringBuilder_append(struct StringBuilder* builder, const char* string) void StringBuilder_append_n(struct StringBuilder* builder, const char* string, const size_t len) { - StringBuilder_ensure_buffer(builder, len); + StringBuilder_ensure_buffer(builder, len+1); strncpy(builder->buffer+builder->buffer_pos, string, len); builder->buffer_pos += len; - builder->buffer[builder->buffer_pos] = '\0'; + builder->buffer[builder->buffer_pos] = 0; } void StringBuilder_append_f(struct StringBuilder* builder, const char* format, ...) { - int size = 512*sizeof(char); - char* message_fmt = BoltMem_allocate(size); + size_t size = 10240*sizeof(char); + char* message_fmt = (char*) BoltMem_allocate(size); while (1) { va_list args; va_start(args, format); - int written = vsnprintf(message_fmt, size, format, args); + size_t written = vsnprintf(message_fmt, size, format, args); va_end(args); if (writtensize; i++) { - const char* key = BoltDictionary_get_key(value, i); + struct BoltValue* key = BoltDictionary_key(value, i); if (key!=NULL) { if (comma) StringBuilder_append(builder, ", "); - StringBuilder_append_n(builder, key, (size_t) (BoltDictionary_get_key_size(value, i))); + StringBuilder_append_n(builder, BoltString_get(key), (size_t) key->size); StringBuilder_append(builder, ": "); BoltValue_write(builder, BoltDictionary_value(value, i), struct_name_resolver); comma = 1;