From 466ba9cb60816a455c15e7c3dba5f325f005f2fe Mon Sep 17 00:00:00 2001 From: Garrett Wollman Date: Sat, 21 Jul 2012 01:22:02 -0400 Subject: [PATCH] opr: constify various string functions and mark them AFS_NONNULL() 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 Reviewed-by: Derrick Brashear --- src/opr/casestrcpy.c | 6 +++--- src/opr/opr.h | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/opr/casestrcpy.c b/src/opr/casestrcpy.c index 7f80ded..e1dc37a 100644 --- a/src/opr/casestrcpy.c +++ b/src/opr/casestrcpy.c @@ -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 * diff --git a/src/opr/opr.h b/src/opr/opr.h index d42f6db..e55a45e 100644 --- a/src/opr/opr.h +++ b/src/opr/opr.h @@ -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 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 -- 1.9.4