[Openvpn-devel] Fix types around buffer_list_push(_data)

Message ID 1515573259-20968-1-git-send-email-steffan.karger@fox-it.com
State Accepted
Headers show
Series [Openvpn-devel] Fix types around buffer_list_push(_data) | expand

Commit Message

Steffan Karger Jan. 9, 2018, 9:34 p.m. UTC
In C, strings are char pointers, not unsigned char pointers.  And
arbitrary data is represented by a void pointer.  Change buffer_list_push
and buffer_list_push_data to follow these rules, and remove any now
unneeded casts.

Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
---
 src/openvpn/buffer.c |  6 +++---
 src/openvpn/buffer.h |  4 ++--
 src/openvpn/manage.c | 12 ++++++------
 src/openvpn/manage.h |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

Comments

Gert Doering Jan. 11, 2018, 12:49 a.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

.. because it gets rid of lots of extra casts that are only there because
the base types have been wrong, and people added casts to make compilers
happy...  (my favourite gripe).

Your patch has been applied to the master and release/2.4 branch.

commit b395f36e578b2def9da8e9347c0afa79814c0c7d (master)
commit c4c7f9208057ee6551d37c0bdab3896f1f549ce1 (release/2.4)
Author: Steffan Karger
Date:   Wed Jan 10 09:34:19 2018 +0100

     Fix types around buffer_list_push(_data)

     Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <1515573259-20968-1-git-send-email-steffan.karger@fox-it.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg16186.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

Patch

diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index a0c2393..858bb08 100644
--- a/src/openvpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ -1169,7 +1169,7 @@  buffer_list_reset(struct buffer_list *ol)
 }
 
 void
-buffer_list_push(struct buffer_list *ol, const unsigned char *str)
+buffer_list_push(struct buffer_list *ol, const char *str)
 {
     if (str)
     {
@@ -1183,7 +1183,7 @@  buffer_list_push(struct buffer_list *ol, const unsigned char *str)
 }
 
 struct buffer_entry *
-buffer_list_push_data(struct buffer_list *ol, const uint8_t *data, size_t size)
+buffer_list_push_data(struct buffer_list *ol, const void *data, size_t size)
 {
     struct buffer_entry *e = NULL;
     if (data && (!ol->max_size || ol->size < ol->max_size))
@@ -1319,7 +1319,7 @@  buffer_list_file(const char *fn, int max_line_len)
             bl = buffer_list_new(0);
             while (fgets(line, max_line_len, fp) != NULL)
             {
-                buffer_list_push(bl, (unsigned char *)line);
+                buffer_list_push(bl, line);
             }
             free(line);
         }
diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h
index 8579cea..e588b80 100644
--- a/src/openvpn/buffer.h
+++ b/src/openvpn/buffer.h
@@ -1095,9 +1095,9 @@  bool buffer_list_defined(const struct buffer_list *ol);
 
 void buffer_list_reset(struct buffer_list *ol);
 
-void buffer_list_push(struct buffer_list *ol, const unsigned char *str);
+void buffer_list_push(struct buffer_list *ol, const char *str);
 
-struct buffer_entry *buffer_list_push_data(struct buffer_list *ol, const uint8_t *data, size_t size);
+struct buffer_entry *buffer_list_push_data(struct buffer_list *ol, const void *data, size_t size);
 
 struct buffer *buffer_list_peek(struct buffer_list *ol);
 
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 55b106c..650f9e0 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -250,7 +250,7 @@  man_output_list_push_str(struct management *man, const char *str)
 {
     if (management_connected(man) && str)
     {
-        buffer_list_push(man->connection.out, (const unsigned char *) str);
+        buffer_list_push(man->connection.out, str);
     }
 }
 
@@ -2190,13 +2190,13 @@  man_read(struct management *man)
          * process command line if complete
          */
         {
-            const unsigned char *line;
+            const char *line;
             while ((line = command_line_get(man->connection.in)))
             {
 #ifdef MANAGEMENT_IN_EXTRA
                 if (man->connection.in_extra)
                 {
-                    if (!strcmp((char *)line, "END"))
+                    if (!strcmp(line, "END"))
                     {
                         in_extra_dispatch(man);
                     }
@@ -3791,18 +3791,18 @@  command_line_add(struct command_line *cl, const unsigned char *buf, const int le
     }
 }
 
-const unsigned char *
+const char *
 command_line_get(struct command_line *cl)
 {
     int i;
-    const unsigned char *ret = NULL;
+    const char *ret = NULL;
 
     i = buf_substring_len(&cl->buf, '\n');
     if (i >= 0)
     {
         buf_copy_excess(&cl->residual, &cl->buf, i);
         buf_chomp(&cl->buf);
-        ret = (const unsigned char *) BSTR(&cl->buf);
+        ret = BSTR(&cl->buf);
     }
     return ret;
 }
diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h
index 676be64..364488f 100644
--- a/src/openvpn/manage.h
+++ b/src/openvpn/manage.h
@@ -70,7 +70,7 @@  void command_line_free(struct command_line *cl);
 
 void command_line_add(struct command_line *cl, const unsigned char *buf, const int len);
 
-const unsigned char *command_line_get(struct command_line *cl);
+const char *command_line_get(struct command_line *cl);
 
 void command_line_reset(struct command_line *cl);