From: Christophe CURIS <[email protected]>

A number of functions do not actually modify the strings given as
parameter, but only read or duplicate it. In this case it is a good
practice to mark that parameter as pointer-to-const to let the
compiler known about it, to be able to perform appropriate
optimisations.
---
 WINGs/WINGs/WUtil.h  |    6 +++---
 WINGs/proplist.c     |   18 +++++++++---------
 WINGs/string.c       |    4 ++--
 WINGs/userdefaults.c |    2 +-
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h
index 84f60b9..d993e58 100644
--- a/WINGs/WINGs/WUtil.h
+++ b/WINGs/WINGs/WUtil.h
@@ -220,7 +220,7 @@ char* wstrndup(const char *str, size_t len);
  * str1 and str2 can be any strings including static and constant strings.
  * str1 and str2 will not be modified.
  * Free the returned string when you're done with it. */
-char* wstrconcat(char *str1, char *str2);
+char* wstrconcat(const char *str1, const char *str2);
 
 /* This will append src to dst, and return dst. dst MUST be either NULL
  * or a string that was a result of a dynamic allocation (malloc, realloc
@@ -229,7 +229,7 @@ char* wstrconcat(char *str1, char *str2);
  * it is equivalent to calling wstrdup(src) ).
  * The returned address may be different from the original address of dst,
  * so always assign the returned address to avoid dangling pointers. */
-char* wstrappend(char *dst, char *src);
+char* wstrappend(char *dst, const char *src);
 
 size_t wstrlcpy(char *, const char *, size_t);
 size_t wstrlcat(char *, const char *, size_t);
@@ -815,7 +815,7 @@ Bool WMWritePropListToFile(WMPropList *plist, char *path);
 
 char* wusergnusteppath(void);
 
-char* wdefaultspathfordomain(char *domain);
+char* wdefaultspathfordomain(const char *domain);
 
 char* wglobaldefaultspathfordomain(const char *domain);
 
diff --git a/WINGs/proplist.c b/WINGs/proplist.c
index 1f50546..ee80500 100644
--- a/WINGs/proplist.c
+++ b/WINGs/proplist.c
@@ -502,22 +502,22 @@ static INLINE int getNonSpaceChar(PLData * pldata)
        return c;
 }
 
-static char *unescapestr(char *src)
+static char *unescapestr(const char *src)
 {
        char *dest = wmalloc(strlen(src) + 1);
-       char *sPtr, *dPtr;
+       char *dPtr;
        char ch;
 
-       for (sPtr = src, dPtr = dest; *sPtr; sPtr++, dPtr++) {
-               if (*sPtr != '\\') {
-                       *dPtr = *sPtr;
+       for (dPtr = dest; *src; src++, dPtr++) {
+               if (*src != '\\') {
+                       *dPtr = *src;
                } else {
-                       ch = *(++sPtr);
+                       ch = *(++src);
                        if ((ch >= '0') && (ch <= '3')) {
                                /* assume next 2 chars are octal too */
                                *dPtr = ((ch & 07) << 6);
-                               *dPtr |= ((*(++sPtr) & 07) << 3);
-                               *dPtr |= *(++sPtr) & 07;
+                               *dPtr |= ((*(++src) & 07) << 3);
+                               *dPtr |= *(++src) & 07;
                        } else {
                                switch (ch) {
                                case 'a':
@@ -542,7 +542,7 @@ static char *unescapestr(char *src)
                                        *dPtr = '\f';
                                        break;
                                default:
-                                       *dPtr = *sPtr;
+                                       *dPtr = *src;
                                }
                        }
                }
diff --git a/WINGs/string.c b/WINGs/string.c
index 8da008f..4db9981 100644
--- a/WINGs/string.c
+++ b/WINGs/string.c
@@ -203,7 +203,7 @@ char *wstrndup(const char *str, size_t len)
        return copy;
 }
 
-char *wstrconcat(char *str1, char *str2)
+char *wstrconcat(const char *str1, const char *str2)
 {
        char *str;
        size_t slen;
@@ -226,7 +226,7 @@ char *wstrconcat(char *str1, char *str2)
        return str;
 }
 
-char *wstrappend(char *dst, char *src)
+char *wstrappend(char *dst, const char *src)
 {
        size_t slen;
 
diff --git a/WINGs/userdefaults.c b/WINGs/userdefaults.c
index 6de410e..96575a0 100644
--- a/WINGs/userdefaults.c
+++ b/WINGs/userdefaults.c
@@ -80,7 +80,7 @@ char *wusergnusteppath()
        return path;
 }
 
-char *wdefaultspathfordomain(char *domain)
+char *wdefaultspathfordomain(const char *domain)
 {
        char *path;
        char *gspath;
-- 
1.7.10.4


-- 
To unsubscribe, send mail to [email protected].

Reply via email to