[PATCH 3/3] make allocation fixed instead of variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]