Resolve numerous "initialization discards ‘const’ qualifier from pointer
target type" warnings that were present.

Note that in the process of fixing the warning in 'parse_actions', a
small buffer overflow was also corrected (the statement
'sprintf(new_words[0], "+%d", i)' writes one character more than
originally existed in new_words[0]).

Signed-off-by: Jason Gerecke <killert...@gmail.com>
---
 tools/tools-shared.c |  2 +-
 tools/tools-shared.h |  2 +-
 tools/xsetwacom.c    | 33 +++++++++++++--------------------
 3 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/tools/tools-shared.c b/tools/tools-shared.c
index f999cf4..4796c3c 100644
--- a/tools/tools-shared.c
+++ b/tools/tools-shared.c
@@ -111,7 +111,7 @@ int set_serial_attr(int fd, unsigned int baud)
 
 }
 
-int write_to_tablet(int fd, char *command)
+int write_to_tablet(int fd, const char *command)
 {
        int len = 0;
 
diff --git a/tools/tools-shared.h b/tools/tools-shared.h
index 0a1e41f..05cb563 100644
--- a/tools/tools-shared.h
+++ b/tools/tools-shared.h
@@ -22,7 +22,7 @@
 void version(void);
 int open_device(const char *path);
 int set_serial_attr(int fd, unsigned int baud);
-int write_to_tablet(int fd, char *command);
+int write_to_tablet(int fd, const char *command);
 int stop_tablet(int fd);
 int start_tablet(int fd);
 int wait_for_tablet(int fd);
diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
index db3a776..22b47de 100644
--- a/tools/xsetwacom.c
+++ b/tools/xsetwacom.c
@@ -550,8 +550,8 @@ is_deprecated_parameter(const char *name)
 }
 
 struct modifier {
-       char *name;
-       char *converted;
+       const char *name;
+       const char *converted;
 };
 
 static struct modifier modifiers[] = {
@@ -964,7 +964,7 @@ static void list(Display *dpy, int argc, char **argv)
  * specialkeys.
  * @return The X Keysym representing specialkey.
  */
-static char *convert_specialkey(const char *specialkey)
+static const char *convert_specialkey(const char *specialkey)
 {
        struct modifier *m = modifiers;
 
@@ -1201,7 +1201,7 @@ static int special_map_keystrokes(Display *dpy, int argc, 
char **argv, unsigned
                KeySym ks;
                KeyCode kc;
                int need_press = 0, need_release = 0;
-               char *key = argv[i];
+               const char *key = argv[i];
 
                if (strlen(key) > 1)
                {
@@ -1332,25 +1332,18 @@ static Bool parse_actions(Display *dpy, int argc, char 
**argv, unsigned long* da
        int  i = 0;
        int  nwords = 0;
        char **words = NULL;
-
+       
        /* translate cmdline commands */
        words = strjoinsplit(argc, argv, &nwords);
 
        if (nwords==1 && sscanf(words[0], "%d", &i) == 1)
        { /* Mangle "simple" button maps into proper actions */
-               char **new_words = realloc(words, sizeof(char*)*2);
-               if (new_words == NULL)
-               {
-                       fprintf(stderr, "Unable to reallocate memory.\n");
-                       return False;
-               }
-
-               sprintf(new_words[0], "+%d", i);
-               new_words[1] = new_words[0];
-               new_words[0] = "button";
-
-               words  = new_words;
-               nwords = 2;
+               char *nargv[1];
+               
+               free(words);
+               nargv[0] = alloca(32);
+               sprintf(nargv[0], "button +%d", i);
+               words = strjoinsplit(1, nargv, &nwords);
        }
 
        for (i = 0; i < nwords && *nitems < size; i++)
@@ -1876,7 +1869,7 @@ static void get_mode(Display *dpy, XDevice *dev, param_t* 
param, int argc, char
 
 static void get_rotate(Display *dpy, XDevice *dev, param_t* param, int argc, 
char **argv)
 {
-       char *rotation = NULL;
+       const char *rotation = NULL;
        Atom prop, type;
        int format;
        unsigned char* data;
@@ -2870,7 +2863,7 @@ static void test_is_modifier(void)
 static void test_convert_specialkey(void)
 {
        char i;
-       char *converted;
+       const char *converted;
        char buff[5];
        struct modifier *m;
 
-- 
2.2.2


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to