]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
opr: constify various string functions and mark them AFS_NONNULL()
authorGarrett Wollman <wollman@csail.mit.edu>
Sat, 21 Jul 2012 05:22:02 +0000 (01:22 -0400)
committerDerrick Brashear <shadow@dementix.org>
Sun, 22 Jul 2012 12:21:56 +0000 (05:21 -0700)
All of these string functions require at least one non-null argument.
Mark them as AFS_NONNULL() so that the compiler and static checker can
find erroneous uses.  The "source" arguments of lcstring and ucstring
can be const, so do so.  (This doesn't affect anything in the tree
right now.)  While here, note a few unfixed issues with these interfaces.)

Change-Id: If2a8dd4d617795560e92c09ee604780f90edce6a
Reviewed-on: http://gerrit.openafs.org/7804
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
src/opr/casestrcpy.c
src/opr/opr.h

index 7f80dedda6c7f5d64f7a814316db2589931849e9..e1dc37a44b540a6e2ce4116280ad18c68e3fac72 100644 (file)
@@ -18,7 +18,7 @@
 
 /* Just like strncpy but shift-case in transit and forces null termination */
 char *
-lcstring(char *d, char *s, int n)
+lcstring(char *d, const char *s, int n)
 {
     char *original_d = d;
     char c;
@@ -39,7 +39,7 @@ lcstring(char *d, char *s, int n)
 }
 
 char *
-ucstring(char *d, char *s, int n)
+ucstring(char *d, const char *s, int n)
 {
     char *original_d = d;
     char c;
@@ -86,7 +86,7 @@ stoupper(char *s)
  *   buf: storage for the composed string. Any data in it will be lost.
  *   len: length of the buffer.
  *   ...: variable number of string arguments. The last argument must be
- *        NULL.
+ *        (char *)NULL.
  * Returns buf or NULL if the buffer was not sufficiently large.
  */
 char *
index d42f6db98bd17ad840fc4a0114c18c964abac547..e55a45e6d0e254a0f3418e27a2968839e0c17761 100644 (file)
@@ -3,6 +3,7 @@
 
 /* macros */
 
+/* should use offsetof() if available */
 #define opr_containerof(ptr, structure, member) \
    ((structure *)((char *)(ptr)-(char *)(&((structure *)NULL)->member)))
 
@@ -26,12 +27,13 @@ extern void opr_AssertFailU(const char *, const char *, int) AFS_NORETURN;
 #define ucstring opr_ucstring
 #define stolower opr_stolower
 #define stoupper opr_stoupper
+/* XXX str* is in the implementation namespace when <string.h> is included */
 #define strcompose opr_strcompose
 
-extern char *opr_lcstring(char *d, char *s, int n);
-extern char *opr_ucstring(char *d, char *s, int n);
-extern void opr_stolower(char *s);
-extern void opr_stoupper(char *s);
-extern char *opr_strcompose(char *buf, size_t len, ...);
+extern char *opr_lcstring(char *d, const char *s, int n) AFS_NONNULL((1,2));
+extern char *opr_ucstring(char *d, const char *s, int n) AFS_NONNULL((1,2));
+extern void opr_stolower(char *s) AFS_NONNULL();
+extern void opr_stoupper(char *s) AFS_NONNULL();
+extern char *opr_strcompose(char *buf, size_t len, ...) AFS_NONNULL((1));
 
 #endif