From 0cb48a433a9e1defb8096a3aaa1d8ac166c9d9aa Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 21 Apr 2016 00:16:14 -0700 Subject: [PATCH] Squash more warnings, including char* / string constant ones in msystem & policy parser. --- src/core/msystem.cpp | 62 +++++++++++++++++------------------ src/core/msystem.h | 14 ++++---- src/core/srefcounttbl.cpp | 2 +- src/fco/signature.cpp | 2 +- src/twparser/policyparser.cpp | 2 +- src/twparser/policyparser.h | 2 +- src/twparser/yylex.cpp | 10 ++---- src/twparser/yylex.h | 6 ++-- 8 files changed, 48 insertions(+), 52 deletions(-) diff --git a/src/core/msystem.cpp b/src/core/msystem.cpp index 60feef1..3900a76 100644 --- a/src/core/msystem.cpp +++ b/src/core/msystem.cpp @@ -167,7 +167,7 @@ * to add to it, just stick the new environment variables * 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_SHELL, /* a safe shell */ DEF_IFS, /* a safe IFS */ @@ -215,7 +215,7 @@ char *getenv(); /* get variable from environment */ # endif #else # ifdef __STDC__ - static char *strdup(char *str) + static char *strdup(char* str) # else static char *strdup(str) char *str; @@ -239,7 +239,7 @@ char *getenv(); /* get variable from environment */ * (if space already allocated) increase the allocation by PTR_INC */ #ifdef __STDC__ -static char **c2alloc(char **old, int *sz_alloc) +static char **c2alloc(const char**old, int *sz_alloc) #else static char **c2alloc(old, sz_alloc) char **old; @@ -257,8 +257,8 @@ int *sz_alloc; /* success! copy the old and free it, if appropriate */ if (old != NULL){ for(i = 0; i < *sz_alloc; i++) - x.cpp[i] = old[i]; - x.cpp = old; + x.cpp[i] = (char*)old[i]; + x.cpp = (char**)old; (void) free(x.vp); } /* now have PTR_INC more room */ @@ -310,7 +310,7 @@ void le_clobber() */ if (envp != NULL){ /* it's defined -- is it fixed? */ - if (envp != nvfix){ + if (envp != (char**)nvfix){ /* no -- usual walk the list crud */ for(i = 0; envp[i] != NULL; i++) (void) free(envp[i]); @@ -331,7 +331,7 @@ void le_clobber() * get a pointer to the environment element */ #ifdef __STDC__ -static int le_getenv(char *var) +static int le_getenv(const char* var) #else static int le_getenv(var) char *var; @@ -352,7 +352,7 @@ char *var; for(i = 0; envp[i] != NULL; i++){ /* compare */ p = envp[i]; - q = var; + q = (char*)var; while(*p && *q && *p == *q) p++, q++; /* have we a match? */ @@ -372,7 +372,7 @@ char *var; * set an environment variable */ #ifdef __STDC__ -int le_set(char *env) +int le_set(const char* env) #else int le_set(env) char *env; @@ -385,7 +385,7 @@ char *env; * seeif youneed to create the environment list */ 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"); return(SE_NOMEM); } @@ -428,7 +428,7 @@ char *env; /* * 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"); return(SE_NOMEM); } @@ -457,7 +457,7 @@ char *env; * clear a current environment variable */ #ifdef __STDC__ -int le_unset(char *env) +int le_unset(const char* env) #else int le_unset(env) char *env; @@ -578,13 +578,13 @@ int gid; * get the shell to use for the subcommand */ #ifdef __STDC__ -static char *shellenv(void) +static const char *shellenv(void) #else -static char *shellenv() +static const char *shellenv() #endif { 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 @@ -612,15 +612,15 @@ static char *shellenv() * like system but A LOT safer */ #ifdef __STDC__ -int msystem(char *cmd) +int msystem(const char* cmd) #else int msystem(cmd) char *cmd; #endif { - char *argv[5]; /* argument list */ + const char *argv[5]; /* argument list */ 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 */ /* @@ -645,7 +645,7 @@ char *cmd; /* * 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(echild(i)); } @@ -664,16 +664,16 @@ static struct popenfunc { /* association of pid, file pointer */ * like popen but A LOT safer */ #ifdef __STDC__ -FILE *mpopen(char *cmd, char *mode) +FILE *mpopen(const char* cmd, const char* mode) #else FILE *mpopen(cmd, mode) char *cmd; char *mode; #endif { - char *argv[5]; /* argument list */ + const char *argv[5]; /* argument list */ 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 */ register int indx; /* index number of child */ @@ -706,7 +706,7 @@ char *mode; /* * 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(pfunc[indx].fp = ((*mode == 'w') ? fpa[0] : fpa[1])); } @@ -751,16 +751,16 @@ FILE *fp; * (0, 1, 2) */ #ifdef __STDC__ -int mfpopen(char *cmd, FILE *fpa[]) +int mfpopen(const char* cmd, FILE *fpa[]) #else int mfpopen(cmd, fpa) char *cmd; FILE *fpa[]; #endif { - char *argv[5]; /* argument list */ + const char *argv[5]; /* argument list */ 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 */ /* @@ -788,7 +788,7 @@ FILE *fpa[]; /* * 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(indx); } @@ -831,7 +831,7 @@ FILE *fp[]; * uses arg vector, not command, and file descriptors 0, 1, 2 */ #ifdef __STDC__ -int mxfpopen(char *argv[], FILE *fpa[]) +int mxfpopen(const char* argv[], FILE *fpa[]) #else int mxfpopen(argv, fpa) char *argv[]; @@ -852,7 +852,7 @@ FILE *fpa[]; /* * 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(indx); } @@ -887,7 +887,7 @@ static tw_sighandler_t savesig[MAX_SIGNAL]; * to omask */ #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 int schild(cmd, argp, envptr, fp, mask) char *cmd; @@ -954,7 +954,7 @@ int mask; (void) close(p[2][1]); } /* exec the command and environment */ - (void) execve(cmd, argp, envptr); + (void) execve(cmd, (char* const*)argp, (char* const*)envptr); /* should never happen ... */ _exit(EXIT_BAD); } diff --git a/src/core/msystem.h b/src/core/msystem.h index 0b45c64..6ff8e33 100644 --- a/src/core/msystem.h +++ b/src/core/msystem.h @@ -56,21 +56,21 @@ */ #ifdef __STDC__ void le_clobber(void); -int le_set(char *); -int le_unset(char *); +int le_set(const char*); +int le_unset(const char*); int le_umask(int); int le_openfd(int); int le_closefd(int); int le_euid(int); int le_egid(int); -int msystem(char *); -FILE *mpopen(char *, char *); +int msystem(const char*); +FILE *mpopen(const char*, const char*); int mpclose(FILE *); -int mfpopen(char *, FILE *[]); +int mfpopen(const char*, FILE *[]); int mfpclose(int, FILE *[]); -int mxfpopen(char *[], FILE *[]); +int mxfpopen(const char*[], 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); #else void le_clobber(); diff --git a/src/core/srefcounttbl.cpp b/src/core/srefcounttbl.cpp index ceffb19..6b43646 100644 --- a/src/core/srefcounttbl.cpp +++ b/src/core/srefcounttbl.cpp @@ -66,7 +66,7 @@ int cSerRefCountTable::Lookup(const iSerRefCountObj* pObj) // pay no attention to this cast :-) itr = mObjToIdTbl.find(const_cast(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 diff --git a/src/fco/signature.cpp b/src/fco/signature.cpp index 7fc6ee4..79f2922 100755 --- a/src/fco/signature.cpp +++ b/src/fco/signature.cpp @@ -552,7 +552,7 @@ TSTRING cMD5Signature::AsStringHex() const 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); } ret.append(sigStringOut); diff --git a/src/twparser/policyparser.cpp b/src/twparser/policyparser.cpp index bf1b907..ac771b2 100644 --- a/src/twparser/policyparser.cpp +++ b/src/twparser/policyparser.cpp @@ -136,7 +136,7 @@ void cPolicyParser::Execute( cGenreSpecListVector& policy, cErrorBucket* pError // it doesn't look at any args following pszErr // Only call this with fully formatted message // 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 diff --git a/src/twparser/policyparser.h b/src/twparser/policyparser.h index 50aa9a2..83a2733 100644 --- a/src/twparser/policyparser.h +++ b/src/twparser/policyparser.h @@ -80,7 +80,7 @@ public: 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) // 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. diff --git a/src/twparser/yylex.cpp b/src/twparser/yylex.cpp index 5f482b1..e1374ff 100644 --- a/src/twparser/yylex.cpp +++ b/src/twparser/yylex.cpp @@ -624,7 +624,7 @@ yy_scan::~yy_scan() // Print error message, showing current line number void -yy_scan::yyerror(char *fmt, ...) +yy_scan::yyerror(const char *fmt, ...) { va_list va; @@ -977,9 +977,7 @@ yy_scan::yylex() std::string strError; 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, - // so cast it away - yyerror( const_cast( strError.c_str() ) ); + yyerror( strError.c_str()); } /* catches anything that cannot be deemed a variable definition and exits. */ break; case 12: @@ -1145,9 +1143,7 @@ yy_scan::yylex() std::string strError; strError = FormatSyntaxError( yytext[0] ); - // MKS defines yyerror with char*, for some stupid reason, - // so cast it away - yyerror( const_cast( strError.c_str() ) ); + yyerror( strError.c_str() ); } /* catches anything else that's not in here and quits */ break; diff --git a/src/twparser/yylex.h b/src/twparser/yylex.h index a8be6d9..b3167fc 100644 --- a/src/twparser/yylex.h +++ b/src/twparser/yylex.h @@ -130,16 +130,16 @@ public: 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); } #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; } #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); } #endif // YYEXIT