From: Vsevolod Stakhov Date: Thu, 17 Oct 2019 17:19:18 +0000 (+0100) Subject: [Minor] Do not use floating point when extending buffers X-Git-Tag: 2.1~81 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3351b30b969716f83d9166025c6d940e7eedde5f;p=rspamd.git [Minor] Do not use floating point when extending buffers --- diff --git a/src/client/rspamdclient.c b/src/client/rspamdclient.c index 7b1bcb73e..b8e89fcd7 100644 --- a/src/client/rspamdclient.c +++ b/src/client/rspamdclient.c @@ -187,7 +187,7 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn, if (zout.pos == zout.size) { /* We need to extend output buffer */ - zout.size = zout.size * 1.5 + 1.0; + zout.size = zout.size * 2; zout.dst = g_realloc (zout.dst, zout.size); } } diff --git a/src/libmime/archives.c b/src/libmime/archives.c index f3ad60067..d938dbcf3 100644 --- a/src/libmime/archives.c +++ b/src/libmime/archives.c @@ -1439,7 +1439,7 @@ rspamd_7zip_ucs2_to_utf8 (struct rspamd_task *task, const guchar *p, UChar32 wc; UBool is_error = 0; - res = g_string_sized_new ((end - p) * 1.5 + sizeof (wc) + 1); + res = g_string_sized_new ((end - p) * 3 / 2 + sizeof (wc) + 1); up = (guint16 *)p; while (src_pos < len) { diff --git a/src/libserver/task.c b/src/libserver/task.c index 3756e7c63..884489821 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -593,7 +593,7 @@ rspamd_task_load_message (struct rspamd_task *task, if (zout.pos == zout.size) { /* We need to extend output buffer */ - zout.size = zout.size * 1.5 + 1.0; + zout.size = zout.size * 2 + 1; zout.dst = g_realloc (zout.dst, zout.size); } } diff --git a/src/libutil/map.c b/src/libutil/map.c index 123d31c5f..02e3913a4 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -456,7 +456,7 @@ http_map_finish (struct rspamd_http_connection *conn, if (zout.pos == zout.size) { /* We need to extend output buffer */ - zout.size = zout.size * 1.5 + 1.0; + zout.size = zout.size * 2 + 1.0; out = g_realloc (zout.dst, zout.size); zout.dst = out; } @@ -835,7 +835,7 @@ read_map_file (struct rspamd_map *map, struct file_map_data *data, if (zout.pos == zout.size) { /* We need to extend output buffer */ - zout.size = zout.size * 1.5 + 1.0; + zout.size = zout.size * 2 + 1; out = g_realloc (zout.dst, zout.size); zout.dst = out; } @@ -922,7 +922,7 @@ read_map_static (struct rspamd_map *map, struct static_map_data *data, if (zout.pos == zout.size) { /* We need to extend output buffer */ - zout.size = zout.size * 1.5 + 1.0; + zout.size = zout.size * 2 + 1; out = g_realloc (zout.dst, zout.size); zout.dst = out; } @@ -1201,7 +1201,7 @@ rspamd_map_read_cached (struct rspamd_map *map, struct rspamd_map_backend *bk, if (zout.pos == zout.size) { /* We need to extend output buffer */ - zout.size = zout.size * 1.5 + 1.0; + zout.size = zout.size * 2 + 1; out = g_realloc (zout.dst, zout.size); zout.dst = out; } diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 0057dc472..461130157 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -2211,7 +2211,7 @@ lua_util_zstd_decompress (lua_State *L) if (zin.pos < zin.size && zout.pos == zout.size) { /* We need to extend output buffer */ - zout.size = zout.size * 1.5 + 1.0; + zout.size = zout.size * 2; out = g_realloc (zout.dst, zout.size); zout.dst = out; } diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index dbf905609..66ab623f8 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -1144,7 +1144,7 @@ proxy_request_decompress (struct rspamd_http_message *msg) if (zout.pos == zout.size) { /* We need to extend output buffer */ - zout.size = zout.size * 1.5 + 1.0; + zout.size = zout.size * 2 + 1; body = rspamd_fstring_grow (body, zout.size); zout.size = body->allocated; zout.dst = body->str;