summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2014-12-16 01:50:01 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2014-12-16 01:50:01 -0500
commitdad58115251f3d838006dbd86773d02fc8dddc00 (patch)
treef201d8050efe67772d87b428020d0742a4c3f8f5
parenta4c5e4e58f757e4125a4e80d7b914d0f8167b6ef (diff)
Get -pedantic
-rw-r--r--common/Makefile.am2
-rw-r--r--common/nslcd-prot.h161
-rw-r--r--compat/Makefile.am2
-rw-r--r--nslcd/Makefile.am2
-rw-r--r--nslcd/common.h6
-rw-r--r--nslcd/db_shadow.c2
-rw-r--r--nslcd/hackers_parse.c36
-rw-r--r--nslcd/hackers_parse.h4
-rw-r--r--tests/Makefile.am2
9 files changed, 120 insertions, 97 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
index 8b30964..e97c731 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -20,7 +20,7 @@
noinst_LIBRARIES = libtio.a libprot.a libdict.a libexpr.a libinotify_helpers.a
AM_CPPFLAGS=-I$(top_srcdir) -D_FORTIFY_SOURCE=2
-AM_CFLAGS = -fPIC -Wall -Werror -Wextra -Wno-unused-parameter
+AM_CFLAGS = -fPIC -Werror -Wall -Wextra -Wno-unused-parameter -pedantic
libtio_a_SOURCES = tio.c tio.h
diff --git a/common/nslcd-prot.h b/common/nslcd-prot.h
index 5355bfa..696f875 100644
--- a/common/nslcd-prot.h
+++ b/common/nslcd-prot.h
@@ -101,15 +101,15 @@ static void debug_dump(const void *ptr, size_t size)
} while(0)
#define WRITE_INT32(fp, i) \
- ({ \
+ (__extension__ ({ \
DEBUG_PRINT("WRITE_INT32 : var="__STRING(i)" int32=%08x", (int)i); \
int32_t tmpint32 = htonl((int32_t)(i)); \
WRITE(fp, &tmpint32, sizeof(int32_t)); \
tmpint32; \
- })
+ }))
#define WRITE_STRING(fp, str) \
- ({ \
+ (__extension__ ({ \
DEBUG_PRINT("WRITE_STRING: var="__STRING(str)" string=\"%s\"", (str)); \
if ((str) == NULL) \
{ \
@@ -124,46 +124,52 @@ static void debug_dump(const void *ptr, size_t size)
WRITE(fp, (str), tmpint32); \
} \
} \
- })
+ }))
#define WRITE_STRINGLIST(fp, arr) \
- if ((arr) == NULL) \
- { \
- DEBUG_PRINT("WRITE_STRLST: var="__STRING(arr)" num=%d", 0); \
- WRITE_INT32(fp, 0); \
- } \
- else \
- { \
- /* first determine length of array */ \
- for (tmp3int32 = 0; (arr)[tmp3int32] != NULL; tmp3int32++) \
- /* noting */ ; \
- /* write number of strings */ \
- DEBUG_PRINT("WRITE_STRLST: var="__STRING(arr)" num=%d", (int)tmp3int32); \
- WRITE_INT32(fp, tmp3int32); \
- /* write strings */ \
- for (tmp2int32 = 0; tmp2int32 < tmp3int32; tmp2int32++) \
+ (__extension__ ({ \
+ if ((arr) == NULL) \
{ \
- WRITE_STRING(fp, (arr)[tmp2int32]); \
+ DEBUG_PRINT("WRITE_STRLST: var="__STRING(arr)" num=%d", 0); \
+ WRITE_INT32(fp, 0); \
} \
- }
+ else \
+ { \
+ int32_t tmp3int32; \
+ /* first determine length of array */ \
+ for (tmp3int32 = 0; (arr)[tmp3int32] != NULL; tmp3int32++) \
+ /* noting */ ; \
+ /* write number of strings */ \
+ DEBUG_PRINT("WRITE_STRLST: var="__STRING(arr)" num=%d", (int)tmp3int32); \
+ WRITE_INT32(fp, tmp3int32); \
+ /* write strings */ \
+ for (int32_t tmp2int32 = 0; tmp2int32 < tmp3int32; tmp2int32++) \
+ { \
+ WRITE_STRING(fp, (arr)[tmp2int32]); \
+ } \
+ } \
+ }))
#define WRITE_STRINGLIST_EXCEPT(fp, arr, not) \
- /* first determine length of array */ \
- tmp3int32 = 0; \
- for (tmp2int32 = 0; (arr)[tmp2int32] != NULL; tmp2int32++) \
- if (strcmp((arr)[tmp2int32], (not)) != 0) \
- tmp3int32++; \
- /* write number of strings (mius one because we intend to skip one) */ \
- DEBUG_PRINT("WRITE_STRLST: var="__STRING(arr)" num=%d", (int)tmp3int32); \
- WRITE_INT32(fp, tmp3int32); \
- /* write strings */ \
- for (tmp2int32 = 0; (arr)[tmp2int32] != NULL; tmp2int32++) \
- { \
- if (strcmp((arr)[tmp2int32], (not)) != 0) \
+ (__extension__ ({ \
+ /* first determine length of array */ \
+ int32_t tmp2int32; \
+ int32_t tmp3int32 = 0; \
+ for (tmp2int32 = 0; (arr)[tmp2int32] != NULL; tmp2int32++) \
+ if (strcmp((arr)[tmp2int32], (not)) != 0) \
+ tmp3int32++; \
+ /* write number of strings (mius one because we intend to skip one) */ \
+ DEBUG_PRINT("WRITE_STRLST: var="__STRING(arr)" num=%d", (int)tmp3int32);\
+ WRITE_INT32(fp, tmp3int32); \
+ /* write strings */ \
+ for (tmp2int32 = 0; (arr)[tmp2int32] != NULL; tmp2int32++) \
{ \
- WRITE_STRING(fp, (arr)[tmp2int32]); \
+ if (strcmp((arr)[tmp2int32], (not)) != 0) \
+ { \
+ WRITE_STRING(fp, (arr)[tmp2int32]); \
+ } \
} \
- }
+ }))
/* READ macros, used for reading data, on read error they will
call the ERROR_OUT_READERROR or ERROR_OUT_BUFERROR macro
@@ -184,16 +190,16 @@ static void debug_dump(const void *ptr, size_t size)
} while(0)
#define READ_INT32(fp, i) \
- ({ \
+ (__extension__ ({ \
int32_t tmpint32; \
READ(fp, &tmpint32, sizeof(int32_t)); \
(i) = (int32_t)ntohl(tmpint32); \
DEBUG_PRINT("READ_INT32 : var="__STRING(i)" int32==%08x", (int)(i)); \
- })
+ }))
/* read a string in a fixed-size "normal" buffer */
#define READ_STRING(fp, buffer) \
- ({ \
+ (__extension__ ({ \
/* read the size of the string */ \
int32_t tmpint32; \
READ(fp, &tmpint32, sizeof(int32_t)); \
@@ -215,7 +221,7 @@ static void debug_dump(const void *ptr, size_t size)
/* null-terminate string in buffer */ \
buffer[tmpint32] = '\0'; \
DEBUG_PRINT("READ_STRING: var="__STRING(buffer)" string=\"%s\"", buffer); \
- })
+ }))
/* READ BUF macros that read data into a pre-allocated buffer.
these macros may require the availability of the following
@@ -231,7 +237,7 @@ static void debug_dump(const void *ptr, size_t size)
/* check that the buffer has sz bytes left in it */
#define BUF_CHECK(fp, sz) \
- ({ \
+ (__extension__ ({ \
if ((bufptr + (size_t)(sz)) > buflen) \
{ \
/* will not fit */ \
@@ -239,46 +245,53 @@ static void debug_dump(const void *ptr, size_t size)
DEBUG_PRINT("READ : buffer %d bytes too small", tmpint32); \
ERROR_OUT_BUFERROR(fp); \
} \
- })
+ }))
/* move the buffer pointer */
#define BUF_SKIP(sz) \
- bufptr += (size_t)(sz)
+ do { bufptr += (size_t)(sz); } while(0)
/* move BUF_CUR foreward so that it is aligned to the specified
type width */
#define BUF_ALIGN(fp, type) \
- /* figure out number of bytes to skip foreward */ \
- tmp2int32 = (sizeof(type) - ((BUF_CUR - (char *)NULL) % sizeof(type))) \
- % sizeof(type); \
- /* check and skip */ \
- BUF_CHECK(fp, tmp2int32); \
- BUF_SKIP(tmp2int32);
+ (__extension__ ({ \
+ /* figure out number of bytes to skip foreward */ \
+ int32_t tmp2int32; \
+ tmp2int32 = (sizeof(type) - ((BUF_CUR - (char *)NULL) % sizeof(type))) \
+ % sizeof(type); \
+ /* check and skip */ \
+ BUF_CHECK(fp, tmp2int32); \
+ BUF_SKIP(tmp2int32); \
+ }))
/* allocate a piece of the buffer to store an array in */
#define BUF_ALLOC(fp, ptr, type, num) \
- /* align to the specified type width */ \
- BUF_ALIGN(fp, type); \
- /* check that we have enough room */ \
- BUF_CHECK(fp, (size_t)(num) * sizeof(type)); \
- /* store the pointer */ \
- (ptr) = (type *)BUF_CUR; \
- /* reserve the space */ \
- BUF_SKIP((size_t)(num) * sizeof(type));
+ do { \
+ /* align to the specified type width */ \
+ BUF_ALIGN(fp, type); \
+ /* check that we have enough room */ \
+ BUF_CHECK(fp, (size_t)(num) * sizeof(type)); \
+ /* store the pointer */ \
+ (ptr) = (type *)BUF_CUR; \
+ /* reserve the space */ \
+ BUF_SKIP((size_t)(num) * sizeof(type)); \
+ } while(0)
/* read a binary blob into the buffer */
#define READ_BUF(fp, ptr, sz) \
- /* check that there is enough room and read */ \
- BUF_CHECK(fp, sz); \
- READ(fp, BUF_CUR, (size_t)sz); \
- /* store pointer and skip */ \
- (ptr) = BUF_CUR; \
- BUF_SKIP(sz);
+ do { \
+ /* check that there is enough room and read */ \
+ BUF_CHECK(fp, sz); \
+ READ(fp, BUF_CUR, (size_t)sz); \
+ /* store pointer and skip */ \
+ (ptr) = BUF_CUR; \
+ BUF_SKIP(sz); \
+ } while(0)
/* read string in the buffer (using buffer, buflen and bufptr)
and store the actual location of the string in field */
#define READ_BUF_STRING(fp, field) \
- ({ \
+ (__extension__ ({ \
int32 tmpint32; \
/* read the size of the string */ \
READ(fp, &tmpint32, sizeof(int32_t)); \
@@ -297,13 +310,13 @@ static void debug_dump(const void *ptr, size_t size)
/* prepare result */ \
(field) = BUF_CUR; \
BUF_SKIP(tmpint32 + 1); \
- })
+ }))
/* read an array from a stram and store it as a null-terminated
array list (size for the array is allocated) */
#define READ_BUF_STRINGLIST(fp, arr) \
- ({ \
- int32 tmpint32; \
+ (__extension__ ({ \
+ int32 tmp2int32, tmp3int32; \
/* read the number of entries */ \
READ(fp, &tmp3int32, sizeof(int32_t)); \
tmp3int32 = ntohl(tmp3int32); \
@@ -317,7 +330,7 @@ static void debug_dump(const void *ptr, size_t size)
} \
/* set last entry to NULL */ \
(arr)[tmp2int32] = NULL; \
- })
+ }))
/* SKIP macros for skipping over certain parts of the protocol stream. */
@@ -335,7 +348,7 @@ static void debug_dump(const void *ptr, size_t size)
/* read a string from the stream but don't do anything with the result */
#define SKIP_STRING(fp) \
- ({ \
+ (__extension__ ({ \
int32_t tmpint32; \
/* read the size of the string */ \
READ(fp, &tmpint32, sizeof(int32_t)); \
@@ -343,12 +356,12 @@ static void debug_dump(const void *ptr, size_t size)
DEBUG_PRINT("READ_STRING: skip %d bytes", (int)tmpint32); \
/* read (skip) the specified number of bytes */ \
SKIP(fp, tmpint32); \
- })
+ }))
/* skip a list of strings */
#define SKIP_STRINGLIST(fp) \
- ({ \
- int32_t tmpint32; \
+ (__extension__ ({ \
+ int32_t tmp2int32, tmp3int32; \
/* read the number of entries */ \
READ(fp, &tmp3int32, sizeof(int32_t)); \
tmp3int32 = ntohl(tmp3int32); \
@@ -358,7 +371,7 @@ static void debug_dump(const void *ptr, size_t size)
{ \
SKIP_STRING(fp); \
} \
- })
+ }))
/* These are functions and macors for performing common operations in
@@ -367,7 +380,7 @@ static void debug_dump(const void *ptr, size_t size)
/* Read the response code (the result code of the query) from
the stream. */
#define READ_RESPONSE_CODE(fp) \
- ({ \
+ (__extension__ ({ \
int32_t tmpint32; \
READ(fp, &tmpint32, sizeof(int32_t)); \
tmpint32 = ntohl(tmpint32); \
@@ -375,6 +388,6 @@ static void debug_dump(const void *ptr, size_t size)
{ \
ERROR_OUT_NOSUCCESS(fp); \
} \
- })
+ }))
#endif /* not COMMON__NSLCD_PROT_H */
diff --git a/compat/Makefile.am b/compat/Makefile.am
index 922b7c6..6738813 100644
--- a/compat/Makefile.am
+++ b/compat/Makefile.am
@@ -20,7 +20,7 @@
noinst_LIBRARIES = libcompat.a
AM_CPPFLAGS=-I$(top_srcdir) -D_FORTIFY_SOURCE=2
-AM_CFLAGS = -fPIC -Wall -Werror -Wextra -Wno-unused-parameter
+AM_CFLAGS = -fPIC -Werror -Wall -Wextra -Wno-unused-parameter -pedantic
EXTRA_DIST = getopt_long.c getopt_long.h \
shell.h \
diff --git a/nslcd/Makefile.am b/nslcd/Makefile.am
index cee5597..a6fc7f8 100644
--- a/nslcd/Makefile.am
+++ b/nslcd/Makefile.am
@@ -21,7 +21,7 @@
sbin_PROGRAMS = nslcd
AM_CPPFLAGS=-I$(top_srcdir) -D_FORTIFY_SOURCE=2 -D_XOPEN_SOURCE=500
-AM_CFLAGS = -std=c99 $(PTHREAD_CFLAGS) -Wall -Werror -Wextra -Wno-unused-parameter
+AM_CFLAGS = -std=c99 $(PTHREAD_CFLAGS) -Werror -Wall -Wextra -Wno-unused-parameter -pedantic
nslcd_SOURCES = nslcd.c ../nslcd.h ../common/nslcd-prot.h \
../common/inotify_helpers.h \
diff --git a/nslcd/common.h b/nslcd/common.h
index ac84734..61b2112 100644
--- a/nslcd/common.h
+++ b/nslcd/common.h
@@ -112,9 +112,9 @@ void invalidator_do(enum nss_map_selector map);
tentry *entry = NULL; \
int rc = 1; \
fndecls \
- tentry *search(int *rcp) { fnsearch } \
- int write(TFILE *fp, tentry *entry) { fnwrite } \
- void clean() { fnclean } \
+ __extension__ tentry *search(int *rcp) { fnsearch } \
+ __extension__ int write(TFILE *fp, tentry *entry) { fnwrite } \
+ __extension__ void clean() { fnclean } \
/* read request parameters */ \
fnread \
/* validate request parameters */ \
diff --git a/nslcd/db_shadow.c b/nslcd/db_shadow.c
index cfc7cb8..d7adf6c 100644
--- a/nslcd/db_shadow.c
+++ b/nslcd/db_shadow.c
@@ -52,7 +52,7 @@ static void passwd2shadow(struct passwd *p, struct shadow *s)
s->inact_days = -1;
s->expire_date = -1;
s->flag = -1;
-};
+}
static int write_shadow(TFILE *fp, struct shadow *entry, uid_t calleruid)
{
diff --git a/nslcd/hackers_parse.c b/nslcd/hackers_parse.c
index 2a98fc1..c26feae 100644
--- a/nslcd/hackers_parse.c
+++ b/nslcd/hackers_parse.c
@@ -47,10 +47,23 @@
/* Get a string value from a YAML scalar node */
#define STR_VALUE(node) \
- ({ \
+ (__extension__ ({ \
ASSERT((node)->type == YAML_SCALAR_NODE); \
((char*)(node)->data.scalar.value); \
- })
+ }))
+
+#define MALLOC(size) REALLOC(NULL, size)
+
+#define REALLOC(ptr, size) \
+ (__extension__ ({ \
+ errno = 0; \
+ void *ret = realloc(ptr, size); \
+ if (ret == (ptr)) { \
+ error(0, errno, "could not (re)allocate memory"); \
+ goto error; \
+ }; \
+ ret; \
+ }))
/* Bitmask flags for the completion of the fields in
* 'struct passwd' (which is defined in <pwd.h>) */
@@ -66,28 +79,25 @@
static
gid_t
name2gid(const char *name) {
- gid_t gid;
+ gid_t gid = 0;
+ char *buf = NULL;
ssize_t buflen = sysconf(_SC_GETGR_R_SIZE_MAX);
if (buflen < 1)
buflen = 256;
- char *buf = malloc(buflen);
+ buf = MALLOC(buflen);
struct group grp;
struct group *ret;
while (getgrnam_r(name, &grp, buf, (size_t)buflen, &ret) < 0) {
if (errno == ERANGE) {
buflen += 256;
- buf = realloc(buf, buflen);
+ buf = REALLOC(buf, buflen);
} else {
- gid = 0;
- goto end;
+ goto error;
}
}
- if (ret == NULL) {
- gid = 0;
- goto end;
- }
- gid = ret->gr_gid;
- end:
+ if (ret != NULL)
+ gid = ret->gr_gid;
+ error:
free(buf);
return gid;
}
diff --git a/nslcd/hackers_parse.h b/nslcd/hackers_parse.h
index e1df21d..1a092f6 100644
--- a/nslcd/hackers_parse.h
+++ b/nslcd/hackers_parse.h
@@ -9,14 +9,14 @@
/* Free+zero a 'struct passwd' */
#define PASSWD_FREE(user) \
- ({ \
+ (__extension__ ({ \
free((user).pw_name); \
free((user).pw_passwd); \
free((user).pw_gecos); \
free((user).pw_dir); \
free((user).pw_shell); \
ZERO(user); \
- })
+ }))
/** Returns 0 on error, or the UID on success. Only handles "normal
* user" UIDs; that is in the range [1000,9999]. */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9674551..6f16efb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -38,7 +38,7 @@ EXTRA_DIST = README nslcd-test.conf usernames.txt testenv.sh test_myldap.sh \
CLEANFILES = $(EXTRA_PROGRAMS)
AM_CPPFLAGS = -I$(top_srcdir) -D_FORTIFY_SOURCE=2
-AM_CFLAGS = $(PTHREAD_CFLAGS) -g -Wall -Werror -Wextra -Wno-unused-parameter
+AM_CFLAGS = $(PTHREAD_CFLAGS) -g -Werror -Wall -Wextra -Wno-unused-parameter -pedantic
test_dict_SOURCES = test_dict.c ../common/dict.h
test_dict_LDADD = ../common/libdict.a