Squash more warnings, including char* / string constant ones in msystem & policy parser.

This commit is contained in:
Brian Cox 2016-04-21 00:16:14 -07:00
parent 210a394b1c
commit 0cb48a433a
8 changed files with 48 additions and 52 deletions

View File

@ -167,7 +167,7 @@
* to add to it, just stick the new environment variables * to add to it, just stick the new environment variables
* at the end of the array; the program does the rest automatically * at the end of the array; the program does the rest automatically
*/ */
char *nvfix[] = { /* these MUST be set or reset */ const char* nvfix[] = { /* these MUST be set or reset */
DEF_PATH, /* a safe path */ DEF_PATH, /* a safe path */
DEF_SHELL, /* a safe shell */ DEF_SHELL, /* a safe shell */
DEF_IFS, /* a safe IFS */ DEF_IFS, /* a safe IFS */
@ -215,7 +215,7 @@ char *getenv(); /* get variable from environment */
# endif # endif
#else #else
# ifdef __STDC__ # ifdef __STDC__
static char *strdup(char *str) static char *strdup(char* str)
# else # else
static char *strdup(str) static char *strdup(str)
char *str; char *str;
@ -239,7 +239,7 @@ char *getenv(); /* get variable from environment */
* (if space already allocated) increase the allocation by PTR_INC * (if space already allocated) increase the allocation by PTR_INC
*/ */
#ifdef __STDC__ #ifdef __STDC__
static char **c2alloc(char **old, int *sz_alloc) static char **c2alloc(const char**old, int *sz_alloc)
#else #else
static char **c2alloc(old, sz_alloc) static char **c2alloc(old, sz_alloc)
char **old; char **old;
@ -257,8 +257,8 @@ int *sz_alloc;
/* success! copy the old and free it, if appropriate */ /* success! copy the old and free it, if appropriate */
if (old != NULL){ if (old != NULL){
for(i = 0; i < *sz_alloc; i++) for(i = 0; i < *sz_alloc; i++)
x.cpp[i] = old[i]; x.cpp[i] = (char*)old[i];
x.cpp = old; x.cpp = (char**)old;
(void) free(x.vp); (void) free(x.vp);
} }
/* now have PTR_INC more room */ /* now have PTR_INC more room */
@ -310,7 +310,7 @@ void le_clobber()
*/ */
if (envp != NULL){ if (envp != NULL){
/* it's defined -- is it fixed? */ /* it's defined -- is it fixed? */
if (envp != nvfix){ if (envp != (char**)nvfix){
/* no -- usual walk the list crud */ /* no -- usual walk the list crud */
for(i = 0; envp[i] != NULL; i++) for(i = 0; envp[i] != NULL; i++)
(void) free(envp[i]); (void) free(envp[i]);
@ -331,7 +331,7 @@ void le_clobber()
* get a pointer to the environment element * get a pointer to the environment element
*/ */
#ifdef __STDC__ #ifdef __STDC__
static int le_getenv(char *var) static int le_getenv(const char* var)
#else #else
static int le_getenv(var) static int le_getenv(var)
char *var; char *var;
@ -352,7 +352,7 @@ char *var;
for(i = 0; envp[i] != NULL; i++){ for(i = 0; envp[i] != NULL; i++){
/* compare */ /* compare */
p = envp[i]; p = envp[i];
q = var; q = (char*)var;
while(*p && *q && *p == *q) while(*p && *q && *p == *q)
p++, q++; p++, q++;
/* have we a match? */ /* have we a match? */
@ -372,7 +372,7 @@ char *var;
* set an environment variable * set an environment variable
*/ */
#ifdef __STDC__ #ifdef __STDC__
int le_set(char *env) int le_set(const char* env)
#else #else
int le_set(env) int le_set(env)
char *env; char *env;
@ -385,7 +385,7 @@ char *env;
* seeif youneed to create the environment list * seeif youneed to create the environment list
*/ */
if (sz_envp == 0){ if (sz_envp == 0){
if ((envp = c2alloc(envp, &sz_envp)) == NULL){ if ((envp = c2alloc((const char**)envp, &sz_envp)) == NULL){
ERMSG("ran out of memory"); ERMSG("ran out of memory");
return(SE_NOMEM); return(SE_NOMEM);
} }
@ -428,7 +428,7 @@ char *env;
/* /*
* if it isn't defined, see if you need to create the environment list * if it isn't defined, see if you need to create the environment list
*/ */
if (nend == sz_envp && (envp = c2alloc(envp, &sz_envp)) == NULL){ if (nend == sz_envp && (envp = c2alloc((const char**)envp, &sz_envp)) == NULL){
ERMSG("ran out of memory"); ERMSG("ran out of memory");
return(SE_NOMEM); return(SE_NOMEM);
} }
@ -457,7 +457,7 @@ char *env;
* clear a current environment variable * clear a current environment variable
*/ */
#ifdef __STDC__ #ifdef __STDC__
int le_unset(char *env) int le_unset(const char* env)
#else #else
int le_unset(env) int le_unset(env)
char *env; char *env;
@ -578,13 +578,13 @@ int gid;
* get the shell to use for the subcommand * get the shell to use for the subcommand
*/ */
#ifdef __STDC__ #ifdef __STDC__
static char *shellenv(void) static const char *shellenv(void)
#else #else
static char *shellenv() static const char *shellenv()
#endif #endif
{ {
register int i; /* counter in a for loop */ register int i; /* counter in a for loop */
register char *shptr; /* points to shell name */ register const char *shptr; /* points to shell name */
/* /*
* error check; should never happen * error check; should never happen
@ -612,15 +612,15 @@ static char *shellenv()
* like system but A LOT safer * like system but A LOT safer
*/ */
#ifdef __STDC__ #ifdef __STDC__
int msystem(char *cmd) int msystem(const char* cmd)
#else #else
int msystem(cmd) int msystem(cmd)
char *cmd; char *cmd;
#endif #endif
{ {
char *argv[5]; /* argument list */ const char *argv[5]; /* argument list */
register char *p; /* temoporary pointers */ register char *p; /* temoporary pointers */
register char *shptr; /* the program to be run */ register const char* shptr; /* the program to be run */
register int i; /* index number of child */ register int i; /* index number of child */
/* /*
@ -645,7 +645,7 @@ char *cmd;
/* /*
* run it * run it
*/ */
if ((i = schild(shptr, argv, envp, (FILE **) NULL, octmask)) < 0) if ((i = schild(shptr, (const char**)argv, (const char**)envp, (FILE **) NULL, octmask)) < 0)
return(127); return(127);
return(echild(i)); return(echild(i));
} }
@ -664,16 +664,16 @@ static struct popenfunc { /* association of pid, file pointer */
* like popen but A LOT safer * like popen but A LOT safer
*/ */
#ifdef __STDC__ #ifdef __STDC__
FILE *mpopen(char *cmd, char *mode) FILE *mpopen(const char* cmd, const char* mode)
#else #else
FILE *mpopen(cmd, mode) FILE *mpopen(cmd, mode)
char *cmd; char *cmd;
char *mode; char *mode;
#endif #endif
{ {
char *argv[5]; /* argument list */ const char *argv[5]; /* argument list */
register char *p; /* temoporary pointers */ register char *p; /* temoporary pointers */
register char *shptr; /* the program to be run */ register const char *shptr; /* the program to be run */
FILE *fpa[3]; /* process communication descriptors */ FILE *fpa[3]; /* process communication descriptors */
register int indx; /* index number of child */ register int indx; /* index number of child */
@ -706,7 +706,7 @@ char *mode;
/* /*
* run it * run it
*/ */
if ((pfunc[indx].pid = schild(shptr, argv, envp, fpa, octmask)) < 0) if ((pfunc[indx].pid = schild(shptr, (const char**)argv, (const char**)envp, fpa, octmask)) < 0)
return(NULL); return(NULL);
return(pfunc[indx].fp = ((*mode == 'w') ? fpa[0] : fpa[1])); return(pfunc[indx].fp = ((*mode == 'w') ? fpa[0] : fpa[1]));
} }
@ -751,16 +751,16 @@ FILE *fp;
* (0, 1, 2) * (0, 1, 2)
*/ */
#ifdef __STDC__ #ifdef __STDC__
int mfpopen(char *cmd, FILE *fpa[]) int mfpopen(const char* cmd, FILE *fpa[])
#else #else
int mfpopen(cmd, fpa) int mfpopen(cmd, fpa)
char *cmd; char *cmd;
FILE *fpa[]; FILE *fpa[];
#endif #endif
{ {
char *argv[5]; /* argument list */ const char *argv[5]; /* argument list */
register char *p; /* temoporary pointers */ register char *p; /* temoporary pointers */
register char *shptr; /* the program to be run */ register const char *shptr; /* the program to be run */
register int indx; /* index number of child */ register int indx; /* index number of child */
/* /*
@ -788,7 +788,7 @@ FILE *fpa[];
/* /*
* run it * run it
*/ */
if ((pfunc[indx].pid = schild(shptr, argv, envp, fpa, octmask)) < 0) if ((pfunc[indx].pid = schild(shptr, (const char**)argv, (const char**)envp, fpa, octmask)) < 0)
return(-1); return(-1);
return(indx); return(indx);
} }
@ -831,7 +831,7 @@ FILE *fp[];
* uses arg vector, not command, and file descriptors 0, 1, 2 * uses arg vector, not command, and file descriptors 0, 1, 2
*/ */
#ifdef __STDC__ #ifdef __STDC__
int mxfpopen(char *argv[], FILE *fpa[]) int mxfpopen(const char* argv[], FILE *fpa[])
#else #else
int mxfpopen(argv, fpa) int mxfpopen(argv, fpa)
char *argv[]; char *argv[];
@ -852,7 +852,7 @@ FILE *fpa[];
/* /*
* run it * run it
*/ */
if ((pfunc[indx].pid = schild(argv[0], argv, envp, fpa, octmask)) < 0) if ((pfunc[indx].pid = schild(argv[0], argv, (const char**)envp, fpa, octmask)) < 0)
return(-1); return(-1);
return(indx); return(indx);
} }
@ -887,7 +887,7 @@ static tw_sighandler_t savesig[MAX_SIGNAL];
* to omask * to omask
*/ */
#ifdef __STDC__ #ifdef __STDC__
int schild(char *cmd, char **argp, char **envptr, FILE *fp[], int mask) int schild(const char* cmd, const char** argp, const char** envptr, FILE *fp[], int mask)
#else #else
int schild(cmd, argp, envptr, fp, mask) int schild(cmd, argp, envptr, fp, mask)
char *cmd; char *cmd;
@ -954,7 +954,7 @@ int mask;
(void) close(p[2][1]); (void) close(p[2][1]);
} }
/* exec the command and environment */ /* exec the command and environment */
(void) execve(cmd, argp, envptr); (void) execve(cmd, (char* const*)argp, (char* const*)envptr);
/* should never happen ... */ /* should never happen ... */
_exit(EXIT_BAD); _exit(EXIT_BAD);
} }

View File

@ -56,21 +56,21 @@
*/ */
#ifdef __STDC__ #ifdef __STDC__
void le_clobber(void); void le_clobber(void);
int le_set(char *); int le_set(const char*);
int le_unset(char *); int le_unset(const char*);
int le_umask(int); int le_umask(int);
int le_openfd(int); int le_openfd(int);
int le_closefd(int); int le_closefd(int);
int le_euid(int); int le_euid(int);
int le_egid(int); int le_egid(int);
int msystem(char *); int msystem(const char*);
FILE *mpopen(char *, char *); FILE *mpopen(const char*, const char*);
int mpclose(FILE *); int mpclose(FILE *);
int mfpopen(char *, FILE *[]); int mfpopen(const char*, FILE *[]);
int mfpclose(int, FILE *[]); int mfpclose(int, FILE *[]);
int mxfpopen(char *[], FILE *[]); int mxfpopen(const char*[], FILE *[]);
int mxfpclose(int, FILE *[]); int mxfpclose(int, FILE *[]);
int schild(char *, char *[], char *[], FILE *[], int); int schild(const char*, const char*[], const char*[], FILE *[], int);
int echild(int); int echild(int);
#else #else
void le_clobber(); void le_clobber();

View File

@ -66,7 +66,7 @@ int cSerRefCountTable::Lookup(const iSerRefCountObj* pObj)
// pay no attention to this cast :-) // pay no attention to this cast :-)
itr = mObjToIdTbl.find(const_cast<iSerRefCountObj*>(pObj)); itr = mObjToIdTbl.find(const_cast<iSerRefCountObj*>(pObj));
return itr == mObjToIdTbl.end() ? NULL : itr->second; return (itr == mObjToIdTbl.end()) ? 0 : itr->second;
} }
// find object for specified id. returns NULL if not in table // find object for specified id. returns NULL if not in table

View File

@ -552,7 +552,7 @@ TSTRING cMD5Signature::AsStringHex() const
for(int i = 0; i < SIG_BYTE_SIZE; ++i) for(int i = 0; i < SIG_BYTE_SIZE; ++i)
{ {
_stprintf(stringBuffer, _T("%02lx"), dbuf[i]); _stprintf(stringBuffer, _T("%02lx"), (unsigned long)dbuf[i]);
_tcscat(sigStringOut, stringBuffer); _tcscat(sigStringOut, stringBuffer);
} }
ret.append(sigStringOut); ret.append(sigStringOut);

View File

@ -136,7 +136,7 @@ void cPolicyParser::Execute( cGenreSpecListVector& policy, cErrorBucket* pError
// it doesn't look at any args following pszErr // it doesn't look at any args following pszErr
// Only call this with fully formatted message // Only call this with fully formatted message
// Parser will ALWAYS call the narrow-char version, so special case Unicode compile // Parser will ALWAYS call the narrow-char version, so special case Unicode compile
void tw_yy_scan::yyerror( char* pszErr, ... ) //throw( eParserHelper ) void tw_yy_scan::yyerror( const char* pszErr, ... ) //throw( eParserHelper )
{ {
TOSTRINGSTREAM ssError; // final error string TOSTRINGSTREAM ssError; // final error string

View File

@ -80,7 +80,7 @@ public:
virtual int yygetc() { return mIn.get(); }; virtual int yygetc() { return mIn.get(); };
virtual void yyerror( char *pszErr, ... ); //throw( eParserHelper ) virtual void yyerror( const char *pszErr, ... ); //throw( eParserHelper )
// this is the MKS error function. But, since some operating systems (e.g. like AIX) // this is the MKS error function. But, since some operating systems (e.g. like AIX)
// don't offer a vnsprintf, so there's no way we can safely output the error // don't offer a vnsprintf, so there's no way we can safely output the error
// from the va_arg list to a string without possible buffer overflow. // from the va_arg list to a string without possible buffer overflow.

View File

@ -624,7 +624,7 @@ yy_scan::~yy_scan()
// Print error message, showing current line number // Print error message, showing current line number
void void
yy_scan::yyerror(char *fmt, ...) yy_scan::yyerror(const char *fmt, ...)
{ {
va_list va; va_list va;
@ -977,9 +977,7 @@ yy_scan::yylex()
std::string strError; std::string strError;
strError = FormatSyntaxError( yytext[0], "The global section only accepts statements of the form:\n variable = value;\n" ); strError = FormatSyntaxError( yytext[0], "The global section only accepts statements of the form:\n variable = value;\n" );
// MKS defines yyerror with char*, for some stupid reason, yyerror( strError.c_str());
// so cast it away
yyerror( const_cast<char*>( strError.c_str() ) );
} /* catches anything that cannot be deemed a variable definition and exits. */ } /* catches anything that cannot be deemed a variable definition and exits. */
break; break;
case 12: case 12:
@ -1145,9 +1143,7 @@ yy_scan::yylex()
std::string strError; std::string strError;
strError = FormatSyntaxError( yytext[0] ); strError = FormatSyntaxError( yytext[0] );
// MKS defines yyerror with char*, for some stupid reason, yyerror( strError.c_str() );
// so cast it away
yyerror( const_cast<char*>( strError.c_str() ) );
} /* catches anything else that's not in here and quits */ } /* catches anything else that's not in here and quits */
break; break;

View File

@ -130,16 +130,16 @@ public:
virtual int yywrap() { return 1; } // EOF processing virtual int yywrap() { return 1; } // EOF processing
virtual void yyerror(char *,...); // print error message virtual void yyerror(const char *,...); // print error message
virtual void output(int c) { putc(c, yyout); } virtual void output(int c) { putc(c, yyout); }
#ifdef YYEXIT #ifdef YYEXIT
virtual void YY_FATAL(char * msg) { // print message and set error flag virtual void YY_FATAL(const char * msg) { // print message and set error flag
yyerror(msg); yyLexFatal = 1; yyerror(msg); yyLexFatal = 1;
} }
#else // YYEXIT #else // YYEXIT
virtual void YY_FATAL(char * msg) { // print message and stop virtual void YY_FATAL(const char * msg) { // print message and stop
yyerror(msg); exit(1); yyerror(msg); exit(1);
} }
#endif // YYEXIT #endif // YYEXIT