1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-14 19:24:43 +03:00
Martin Schwenke 85a4024651 Clean up warnings: popt sure does some strange things
popt generates 4 compiler warnings with GCC 4.6.  There are 2
different types:

* 3 instances of:

    warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]

  One occurs in the _free() hack that is used to try and avoid a
  compiler warning.  I guess GCC got smarter?  ;-)

  The other is where an array of constant strings is passed to
  execvp(2), which arguably has the wrong type, since it has no need
  to modify the strings.

  Both of these can be worked around by casting to intptr_t before
  casting to the desired argument type.

  In poptReadConfigFile() the variable file is declared to be a
  constant string.  However, it is then passed to read(2) straight
  away and an attempt is made to cast away the "const".  However, to
  protect the value the of file is assigned to (const char *) chptr
  before it is passed to any other functions, so this protects the
  value anyway.  I'm not sure exactly what the thinking was
  here... but there seems to be no use having file be constant.

* 1 instance of:

    warning: variable ‘rc’ set but not used [-Wunused-but-set-variable]

  for the result of an execvp(2) call.  Recast the return type to
  void.  However, due to some #if-fu in the function, that can make rc
  unused in this function.  So we also need to wrap the declaration of
  rc in some corresponding #if-fu to make it disappear if not used.

Signed-off-by: Martin Schwenke <martin@meltin.net>

(This used to be ctdb commit ac9236e64bd0b61740cc787819a1222bc6a67d4a)
2011-11-11 14:28:30 +11:00

117 lines
2.7 KiB
C

/** \ingroup popt
* \file popt/poptint.h
*/
/* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.rpm.org/pub/rpm/dist. */
#ifndef H_POPTINT
#define H_POPTINT
/**
* Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
* @param p memory to free
* @retval NULL always
*/
/*@unused@*/ static inline /*@null@*/ void *
_free(/*@only@*/ /*@null@*/ const void * p)
/*@modifies p @*/
{
if (p != NULL) free((void *)(intptr_t)p);
return NULL;
}
/* Bit mask macros. */
/*@-exporttype -redef @*/
typedef unsigned int __pbm_bits;
/*@=exporttype =redef @*/
#define __PBM_NBITS (8 * sizeof (__pbm_bits))
#define __PBM_IX(d) ((d) / __PBM_NBITS)
#define __PBM_MASK(d) ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS))
/*@-exporttype -redef @*/
typedef struct {
__pbm_bits bits[1];
} pbm_set;
/*@=exporttype =redef @*/
#define __PBM_BITS(set) ((set)->bits)
#define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits))
#define PBM_FREE(s) _free(s);
#define PBM_SET(d, s) (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d))
#define PBM_CLR(d, s) (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d))
#define PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0)
struct optionStackEntry {
int argc;
/*@only@*/ /*@null@*/
const char ** argv;
/*@only@*/ /*@null@*/
pbm_set * argb;
int next;
/*@only@*/ /*@null@*/
const char * nextArg;
/*@observer@*/ /*@null@*/
const char * nextCharArg;
/*@dependent@*/ /*@null@*/
poptItem currAlias;
int stuffed;
};
struct poptContext_s {
struct optionStackEntry optionStack[POPT_OPTION_DEPTH];
/*@dependent@*/
struct optionStackEntry * os;
/*@owned@*/ /*@null@*/
const char ** leftovers;
int numLeftovers;
int nextLeftover;
/*@keep@*/
const struct poptOption * options;
int restLeftover;
/*@only@*/ /*@null@*/
const char * appName;
/*@only@*/ /*@null@*/
poptItem aliases;
int numAliases;
int flags;
/*@owned@*/ /*@null@*/
poptItem execs;
int numExecs;
/*@only@*/ /*@null@*/
const char ** finalArgv;
int finalArgvCount;
int finalArgvAlloced;
/*@dependent@*/ /*@null@*/
poptItem doExec;
/*@only@*/
const char * execPath;
int execAbsolute;
/*@only@*/
const char * otherHelp;
/*@null@*/
pbm_set * arg_strip;
};
#ifdef HAVE_LIBINTL_H
#include <libintl.h>
#endif
#if defined(HAVE_GETTEXT) && !defined(__LCLINT__)
#define _(foo) gettext(foo)
#else
#define _(foo) foo
#endif
#if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__)
#define D_(dom, str) dgettext(dom, str)
#define POPT_(foo) D_("popt", foo)
#else
#define D_(dom, str) str
#define POPT_(foo) foo
#endif
#define N_(foo) foo
#endif