From 48d51b66fac883fc8648fb6b9df487382b8addc2 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sun, 4 Mar 2007 20:03:06 +0000 Subject: code improvements by making type casts explicit, flagging ignored return values, renames and flagging of parameters and some miscelanious improvements (thanks to gcc warnings, splint, rats and flawfinder) git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@265 ef36b2f9-881f-0410-afb5-c4e39611909c --- nss/common.c | 8 ++++---- nss/common.h | 25 ++++++++++++------------- nss/group.c | 6 +++--- nss/hosts.c | 13 +++++++------ nss/netgroup.c | 2 +- nss/networks.c | 8 ++++---- nss/prototypes.h | 4 ++-- nss/services.c | 2 +- 8 files changed, 34 insertions(+), 34 deletions(-) (limited to 'nss') diff --git a/nss/common.c b/nss/common.c index da4c68f..29e06f2 100644 --- a/nss/common.c +++ b/nss/common.c @@ -37,7 +37,7 @@ /* translates a nsklcd return code (as defined in nslcd.h) to a nss code (as defined in nss.h) */ -enum nss_status nslcd2nss(int code) +enum nss_status nslcd2nss(int32_t code) { switch (code) { @@ -62,15 +62,15 @@ FILE *nslcd_client_open() addr.sun_family=AF_UNIX; strcpy(addr.sun_path,NSLCD_SOCKET); /* connect to the socket */ - if (connect(sock,(struct sockaddr *)&addr,sizeof(struct sockaddr_un))<0) + if (connect(sock,(struct sockaddr *)&addr,(socklen_t)sizeof(struct sockaddr_un))<0) { - close(sock); + (void)close(sock); return NULL; } /* create a stream object */ if ((fp=fdopen(sock,"w+"))==NULL) { - close(sock); + (void)close(sock); return NULL; } /* return the stream */ diff --git a/nss/common.h b/nss/common.h index 723d203..03c60b4 100644 --- a/nss/common.h +++ b/nss/common.h @@ -32,8 +32,7 @@ /* This function maps an nslcd return code (as defined in nslcd.h) to an nss code (as defined in nss.h). */ -enum nss_status nslcd2nss(int code) - PURE MUST_USE; +enum nss_status nslcd2nss(int32_t code); /* returns a socket to the server or NULL on error (see errno), socket should be closed with fclose() */ @@ -51,24 +50,24 @@ FILE *nslcd_client_open(void) /* Write a request header with a request code. */ #define WRITE_REQUEST(fp,req) \ - WRITE_INT32(fp,NSLCD_VERSION) \ - WRITE_INT32(fp,req) + WRITE_INT32(fp,(int32_t)NSLCD_VERSION) \ + WRITE_INT32(fp,(int32_t)req) /* Read a response header and check that the returned request code equals the expected code. */ #define READ_RESPONSEHEADER(fp,req) \ READ_TYPE(fp,tmpint32,int32_t); \ - if (tmpint32!=NSLCD_VERSION) \ + if (tmpint32!=(int32_t)NSLCD_VERSION) \ { ERROR_OUT_READERROR(fp) } \ READ_TYPE(fp,tmpint32,int32_t); \ - if (tmpint32!=(req)) \ + if (tmpint32!=(int32_t)(req)) \ { ERROR_OUT_READERROR(fp) } /* Read the response code (the result code of the query) from the stream. */ #define READ_RESPONSE_CODE(fp) \ READ_TYPE(fp,tmpint32,int32_t); \ - if (tmpint32!=NSLCD_RESULT_SUCCESS) \ + if (tmpint32!=(int32_t)NSLCD_RESULT_SUCCESS) \ { ERROR_OUT_NOSUCCESS(fp,tmpint32) } /* These are macros for handling read and write problems, they are @@ -83,7 +82,7 @@ FILE *nslcd_client_open(void) /* Macro is called to handle errors on fread(). */ #define ERROR_OUT_READERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ return NSS_STATUS_UNAVAIL; @@ -94,7 +93,7 @@ FILE *nslcd_client_open(void) Something more inteligent (e.g. ungetting the read data from the stream) should be implemented. */ #define ERROR_OUT_BUFERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ERANGE; \ return NSS_STATUS_TRYAGAIN; @@ -107,7 +106,7 @@ FILE *nslcd_client_open(void) /* This macro is called if the read status code is not NSLCD_RESULT_SUCCESS. */ #define ERROR_OUT_NOSUCCESS(fp,retv) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ return nslcd2nss(retv); @@ -141,7 +140,7 @@ FILE *nslcd_client_open(void) retv=readfn; \ /* close socket and we're done */ \ if (retv==NSS_STATUS_SUCCESS) \ - fclose(fp); \ + (void)fclose(fp); \ return retv; /* This macro can be used to generate a get..byname() function @@ -169,7 +168,7 @@ FILE *nslcd_client_open(void) errnop=&errnocp; \ /* close the existing stream if it is still open */ \ if (fp!=NULL) \ - fclose(fp); \ + (void)fclose(fp); \ /* open a new stream and write the request */ \ OPEN_SOCK(fp); \ WRITE_REQUEST(fp,action); \ @@ -202,7 +201,7 @@ FILE *nslcd_client_open(void) #define NSS_ENDENT(fp) \ if (fp!=NULL) \ { \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ } \ return NSS_STATUS_SUCCESS; diff --git a/nss/group.c b/nss/group.c index 4e51f94..ebf09a9 100644 --- a/nss/group.c +++ b/nss/group.c @@ -50,12 +50,12 @@ static enum nss_status read_gids( FILE *fp,long int *start,long int *size, gid_t **groupsp,long int limit,int *errnop) { - int32_t res=NSLCD_RESULT_SUCCESS; + int32_t res=(int32_t)NSLCD_RESULT_SUCCESS; int32_t tmpint32,tmp2int32,tmp3int32; gid_t gid; int num=0; /* loop over results */ - while (res==NSLCD_RESULT_SUCCESS) + while (res==(int32_t)NSLCD_RESULT_SUCCESS) { /* skip group name */ SKIP_STRING(fp); @@ -77,7 +77,7 @@ static enum nss_status read_gids( READ_TYPE(fp,res,int32_t); } /* return the proper status code */ - return (res==NSLCD_RESULT_NOTFOUND)?NSS_STATUS_SUCCESS:nslcd2nss(res); + return (res==(int32_t)NSLCD_RESULT_NOTFOUND)?NSS_STATUS_SUCCESS:nslcd2nss(res); } #endif /* REENABLE_WHEN_WORKING */ diff --git a/nss/hosts.c b/nss/hosts.c index 2720b54..2eae67d 100644 --- a/nss/hosts.c +++ b/nss/hosts.c @@ -40,7 +40,7 @@ #undef ERROR_OUT_READERROR #define ERROR_OUT_READERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ *h_errnop=NO_RECOVERY; \ @@ -48,7 +48,7 @@ #undef ERROR_OUT_BUFERROR #define ERROR_OUT_BUFERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ERANGE; \ *h_errnop=TRY_AGAIN; \ @@ -60,7 +60,7 @@ #undef ERROR_OUT_NOSUCCESS #define ERROR_OUT_NOSUCCESS(fp,retv) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ *h_errnop=HOST_NOT_FOUND; \ @@ -75,7 +75,8 @@ static enum nss_status read_hostent( char *buffer,size_t buflen,int *errnop,int *h_errnop) { int32_t tmpint32,tmp2int32,tmp3int32; - int numaddr,i; + int32_t numaddr; + int i; int readaf; size_t bufptr=0; /* read the host entry */ @@ -88,7 +89,7 @@ static enum nss_status read_hostent( /* allocate memory for array */ /* Note: this may allocate too much memory (e.g. also for address records of other address families) but - this is an easy way to do it */ + this is a simple way to do it */ BUF_ALLOC(fp,result->h_addr_list,char *,numaddr+1); /* go through the address list and filter on af */ i=0; @@ -134,7 +135,7 @@ static enum nss_status read_hostent_erronempty( { *errnop=ENOENT; *h_errnop=NO_ADDRESS; - fclose(fp); + (void)fclose(fp); return NSS_STATUS_NOTFOUND; } return NSS_STATUS_SUCCESS; diff --git a/nss/netgroup.c b/nss/netgroup.c index 3f0a60f..39f77f6 100644 --- a/nss/netgroup.c +++ b/nss/netgroup.c @@ -35,7 +35,7 @@ if we have sucessfully read some entries */ #undef ERROR_OUT_NOSUCCESS #define ERROR_OUT_NOSUCCESS(fp,retv) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ if (result->first) \ { \ diff --git a/nss/networks.c b/nss/networks.c index 37653f3..91dfc52 100644 --- a/nss/networks.c +++ b/nss/networks.c @@ -40,7 +40,7 @@ #undef ERROR_OUT_READERROR #define ERROR_OUT_READERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ *h_errnop=NO_RECOVERY; \ @@ -48,7 +48,7 @@ #undef ERROR_OUT_BUFERROR #define ERROR_OUT_BUFERROR(fp) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ERANGE; \ *h_errnop=TRY_AGAIN; \ @@ -60,7 +60,7 @@ #undef ERROR_OUT_NOSUCCESS #define ERROR_OUT_NOSUCCESS(fp,retv) \ - fclose(fp); \ + (void)fclose(fp); \ fp=NULL; \ *errnop=ENOENT; \ *h_errnop=HOST_NOT_FOUND; \ @@ -94,7 +94,7 @@ static enum nss_status read_netent( { /* read address and translate to host byte order */ READ_TYPE(fp,tmpint32,int32_t); - result->n_net=ntohl(tmpint32); + result->n_net=ntohl((uint32_t)tmpint32); /* signal that we've read a proper entry */ retv=NSS_STATUS_SUCCESS; /* don't return here to not upset the stream */ diff --git a/nss/prototypes.h b/nss/prototypes.h index 6cf039e..c41e797 100644 --- a/nss/prototypes.h +++ b/nss/prototypes.h @@ -99,8 +99,8 @@ enum nss_status _nss_ldap_getaliasent_r(struct aliasent *result,char *buffer,siz enum nss_status _nss_ldap_endaliasent(void); /* ethers - ethernet numbers */ -enum nss_status _nss_ldap_gethostton_r(const char *name,struct etherent *resut,char *buffer,size_t buflen,int *errnop); -enum nss_status _nss_ldap_getntohost_r(const struct ether_addr *addr,struct etherent *eth,char *buffer,size_t buflen,int *errnop); +enum nss_status _nss_ldap_gethostton_r(const char *name,struct etherent *result,char *buffer,size_t buflen,int *errnop); +enum nss_status _nss_ldap_getntohost_r(const struct ether_addr *addr,struct etherent *result,char *buffer,size_t buflen,int *errnop); enum nss_status _nss_ldap_setetherent(int stayopen); enum nss_status _nss_ldap_getetherent_r(struct etherent *result,char *buffer,size_t buflen,int *errnop); enum nss_status _nss_ldap_endetherent(void); diff --git a/nss/services.c b/nss/services.c index f79012a..f9ec7c5 100644 --- a/nss/services.c +++ b/nss/services.c @@ -40,7 +40,7 @@ static enum nss_status read_servent( READ_STRINGLIST_NULLTERM(fp,result->s_aliases); /* store port number in network byte order */ READ_TYPE(fp,tmpint32,int32_t); - result->s_port=ntohs(tmpint32); + result->s_port=ntohs((uint16_t)tmpint32); READ_STRING_BUF(fp,result->s_proto); /* we're done */ return NSS_STATUS_SUCCESS; -- cgit v1.2.3