[Spice-devel] [PATCH 3/3] make allocation fixed instead of variable

Frediano Ziglio fziglio at redhat.com
Tue Feb 23 16:06:37 UTC 2016


Due to the way C handle constant variable the usage of these constant
were used as variable making compiler generate something like alloca
call while could compute allocation size statically.
Fix this using enum.
You can see the difference in the generated object file.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/reds-stream.c | 2 +-
 server/tree.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/server/reds-stream.c b/server/reds-stream.c
index 140b767..4930953 100644
--- a/server/reds-stream.c
+++ b/server/reds-stream.c
@@ -261,7 +261,7 @@ int reds_stream_send_msgfd(RedsStream *stream, int fd)
     struct iovec iov;
     int r;
 
-    const size_t fd_size = 1 * sizeof(int);
+    enum { fd_size = 1 * sizeof(int) };
     struct cmsghdr *cmsg;
     union {
         struct cmsghdr hdr;
diff --git a/server/tree.c b/server/tree.c
index 9e5a281..41e78d2 100644
--- a/server/tree.c
+++ b/server/tree.c
@@ -130,7 +130,7 @@ static void dump_item(TreeItem *item, void *data)
     switch (item->type) {
     case TREE_ITEM_TYPE_DRAWABLE: {
         Drawable *drawable = SPICE_CONTAINEROF(item, Drawable, tree_item.base);
-        const int max_indent = 200;
+        enum { max_indent = 200 };
         char indent_str[max_indent + 1];
         int indent_str_len;
 
-- 
2.5.0



More information about the Spice-devel mailing list