From 0f0256980b69163c4a39c441bfce0fdf1daaaca4 Mon Sep 17 00:00:00 2001 From: Sander Mertens Date: Fri, 21 Jun 2024 10:14:13 -0700 Subject: [PATCH] Replace usage of strbuf_append with strbuf_appendint --- flecs.c | 23 +++++++++++++++-------- flecs.h | 2 +- include/flecs/os_api.h | 2 +- src/addons/rest.c | 23 +++++++++++++++-------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/flecs.c b/flecs.c index d153d9edb..a391e945e 100644 --- a/flecs.c +++ b/flecs.c @@ -25145,7 +25145,9 @@ bool flecs_rest_put_entity( return true; } - ecs_strbuf_append(&reply->body, "{\"id\":\"%u\"}", (uint32_t)result); + ecs_strbuf_appendlit(&reply->body, "{\"id\":\""); + ecs_strbuf_appendint(&reply->body, (uint32_t)result); + ecs_strbuf_appendlit(&reply->body, "\"}"); return true; } @@ -25973,8 +25975,10 @@ void flecs_rest_reply_table_append_memory( } ecs_strbuf_list_push(reply, "{", ","); - ecs_strbuf_list_append(reply, "\"used\":%d", used); - ecs_strbuf_list_append(reply, "\"allocated\":%d", allocated); + ecs_strbuf_list_appendlit(reply, "\"used\":"); + ecs_strbuf_appendint(reply, used); + ecs_strbuf_list_appendlit(reply, "\"allocated\":"); + ecs_strbuf_appendint(reply, allocated); ecs_strbuf_list_pop(reply, "}"); } @@ -25986,11 +25990,13 @@ void flecs_rest_reply_table_append( { ecs_strbuf_list_next(reply); ecs_strbuf_list_push(reply, "{", ","); - ecs_strbuf_list_append(reply, "\"id\":%u", (uint32_t)table->id); - ecs_strbuf_list_appendstr(reply, "\"type\":"); + ecs_strbuf_list_appendlit(reply, "\"id\":"); + ecs_strbuf_appendint(reply, (uint32_t)table->id); + ecs_strbuf_list_appendlit(reply, "\"type\":"); flecs_rest_reply_table_append_type(world, reply, table); - ecs_strbuf_list_append(reply, "\"count\":%d", ecs_table_count(table)); - ecs_strbuf_list_append(reply, "\"memory\":"); + ecs_strbuf_list_appendlit(reply, "\"count\":"); + ecs_strbuf_appendint(reply, ecs_table_count(table)); + ecs_strbuf_list_appendlit(reply, "\"memory\":"); flecs_rest_reply_table_append_memory(reply, table); ecs_strbuf_list_pop(reply, "}"); } @@ -26242,7 +26248,8 @@ bool flecs_rest_get_commands_capture( (void)req; const ecs_world_info_t *wi = ecs_get_world_info(world); ecs_strbuf_appendstr(&reply->body, "{"); - ecs_strbuf_append(&reply->body, "\"frame\":%u", wi->frame_count_total); + ecs_strbuf_appendlit(&reply->body, "\"frame\":"); + ecs_strbuf_appendint(&reply->body, wi->frame_count_total); ecs_strbuf_appendstr(&reply->body, "}"); ecs_map_init_if(&impl->cmd_captures, &world->allocator); diff --git a/flecs.h b/flecs.h index 843921ac7..57ede0b3b 100644 --- a/flecs.h +++ b/flecs.h @@ -2639,7 +2639,7 @@ void ecs_os_set_api_defaults(void); #if !defined(ECS_TARGET_POSIX) && !defined(ECS_TARGET_MINGW) #define ecs_os_strcat(str1, str2) strcat_s(str1, INT_MAX, str2) #define ecs_os_snprintf(ptr, len, ...) sprintf_s(ptr, ECS_CAST(size_t, len), __VA_ARGS__) -#define ecs_os_vsnprintf(ptr, len, fmt, args) vsprintf_s(ptr, ECS_CAST(size_t, len), fmt, args) +#define ecs_os_vsnprintf(ptr, len, fmt, args) vsnprintf(ptr, ECS_CAST(size_t, len), fmt, args) #define ecs_os_strcpy(str1, str2) strcpy_s(str1, INT_MAX, str2) #define ecs_os_strncpy(str1, str2, len) strncpy_s(str1, INT_MAX, str2, ECS_CAST(size_t, len)) #else diff --git a/include/flecs/os_api.h b/include/flecs/os_api.h index a7980a9ba..ca5ed1cf4 100644 --- a/include/flecs/os_api.h +++ b/include/flecs/os_api.h @@ -454,7 +454,7 @@ void ecs_os_set_api_defaults(void); #if !defined(ECS_TARGET_POSIX) && !defined(ECS_TARGET_MINGW) #define ecs_os_strcat(str1, str2) strcat_s(str1, INT_MAX, str2) #define ecs_os_snprintf(ptr, len, ...) sprintf_s(ptr, ECS_CAST(size_t, len), __VA_ARGS__) -#define ecs_os_vsnprintf(ptr, len, fmt, args) vsprintf_s(ptr, ECS_CAST(size_t, len), fmt, args) +#define ecs_os_vsnprintf(ptr, len, fmt, args) vsnprintf(ptr, ECS_CAST(size_t, len), fmt, args) #define ecs_os_strcpy(str1, str2) strcpy_s(str1, INT_MAX, str2) #define ecs_os_strncpy(str1, str2, len) strncpy_s(str1, INT_MAX, str2, ECS_CAST(size_t, len)) #else diff --git a/src/addons/rest.c b/src/addons/rest.c index 5f0f68c40..70041f52a 100644 --- a/src/addons/rest.c +++ b/src/addons/rest.c @@ -251,7 +251,9 @@ bool flecs_rest_put_entity( return true; } - ecs_strbuf_append(&reply->body, "{\"id\":\"%u\"}", (uint32_t)result); + ecs_strbuf_appendlit(&reply->body, "{\"id\":\""); + ecs_strbuf_appendint(&reply->body, (uint32_t)result); + ecs_strbuf_appendlit(&reply->body, "\"}"); return true; } @@ -1079,8 +1081,10 @@ void flecs_rest_reply_table_append_memory( } ecs_strbuf_list_push(reply, "{", ","); - ecs_strbuf_list_append(reply, "\"used\":%d", used); - ecs_strbuf_list_append(reply, "\"allocated\":%d", allocated); + ecs_strbuf_list_appendlit(reply, "\"used\":"); + ecs_strbuf_appendint(reply, used); + ecs_strbuf_list_appendlit(reply, "\"allocated\":"); + ecs_strbuf_appendint(reply, allocated); ecs_strbuf_list_pop(reply, "}"); } @@ -1092,11 +1096,13 @@ void flecs_rest_reply_table_append( { ecs_strbuf_list_next(reply); ecs_strbuf_list_push(reply, "{", ","); - ecs_strbuf_list_append(reply, "\"id\":%u", (uint32_t)table->id); - ecs_strbuf_list_appendstr(reply, "\"type\":"); + ecs_strbuf_list_appendlit(reply, "\"id\":"); + ecs_strbuf_appendint(reply, (uint32_t)table->id); + ecs_strbuf_list_appendlit(reply, "\"type\":"); flecs_rest_reply_table_append_type(world, reply, table); - ecs_strbuf_list_append(reply, "\"count\":%d", ecs_table_count(table)); - ecs_strbuf_list_append(reply, "\"memory\":"); + ecs_strbuf_list_appendlit(reply, "\"count\":"); + ecs_strbuf_appendint(reply, ecs_table_count(table)); + ecs_strbuf_list_appendlit(reply, "\"memory\":"); flecs_rest_reply_table_append_memory(reply, table); ecs_strbuf_list_pop(reply, "}"); } @@ -1348,7 +1354,8 @@ bool flecs_rest_get_commands_capture( (void)req; const ecs_world_info_t *wi = ecs_get_world_info(world); ecs_strbuf_appendstr(&reply->body, "{"); - ecs_strbuf_append(&reply->body, "\"frame\":%u", wi->frame_count_total); + ecs_strbuf_appendlit(&reply->body, "\"frame\":"); + ecs_strbuf_appendint(&reply->body, wi->frame_count_total); ecs_strbuf_appendstr(&reply->body, "}"); ecs_map_init_if(&impl->cmd_captures, &world->allocator);