Skip to content

Commit

Permalink
const.h avoid multiple function calls in strcmp/strncmp functions
Browse files Browse the repository at this point in the history
when the argument is the return value of a function call

Signed-off-by: Hans Zandbelt <hans.zandbelt@openidc.com>
  • Loading branch information
zandbelt committed Dec 18, 2023
1 parent 1e876c6 commit c14d2c2
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>

#include <apr_strings.h>

#ifdef __STDC_LIB_EXT1__
#define _oidc_memset(b, c, __len) memset_s(b, __len, c, __len)
#define _oidc_memcpy(__dst, __src, __n) memcpy_s(__dst, __src, __n)
Expand All @@ -67,10 +69,18 @@
#define _oidc_strcpy(__dst, __src) strcpy(__dst, __src)
#endif

#define _oidc_strlen(s) (s ? strlen(s) : 0)
#define _oidc_strcmp(a, b) ((a && b) ? apr_strnatcmp(a, b) : -1)
#define _oidc_strnatcasecmp(a, b) ((a && b) ? apr_strnatcasecmp(a, b) : -1)
#define _oidc_strncmp(a, b, size) ((a && b) ? strncmp(a, b, size) : -1)
static inline size_t _oidc_strlen(const char *s) {
return (s ? strlen(s) : 0);
}
static inline int _oidc_strcmp(const char *a, const char *b) {
return ((a && b) ? apr_strnatcmp(a, b) : -1);
}
static inline int _oidc_strnatcasecmp(const char *a, const char *b) {
return ((a && b) ? apr_strnatcasecmp(a, b) : -1);
}
static inline int _oidc_strncmp(const char *a, const char *b, size_t n) {
return ((a && b) ? strncmp(a, b, n) : -1);
}

#define _oidc_str_to_int(s) (s ? (int)strtol(s, NULL, 10) : 0)

Expand Down

0 comments on commit c14d2c2

Please sign in to comment.