From: Peter Johnson Date: Wed, 3 Oct 2001 01:44:47 +0000 (-0000) Subject: Add some (optional through configure) additional warning flags. Add options X-Git-Tag: v0.1.0~278 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=98e25fc1f6cb656a91a2310147c9a535a2eab162;p=yasm Add some (optional through configure) additional warning flags. Add options to configure to enable profiling and enable -Werror. Make changes to ensure everything builds with all additional warnings and -Werror enabled. Most of these changes consist of adding "const" modifiers for functions that get constant literal strings. svn path=/trunk/yasm/; revision=252 --- diff --git a/check/check.c b/check/check.c index 829c95f3..44df732f 100644 --- a/check/check.c +++ b/check/check.c @@ -37,7 +37,7 @@ extern int nofork_exit_status; #endif -Suite *suite_create (char *name) +Suite *suite_create (const char *name) { Suite *s; s = emalloc (sizeof(Suite)); /* freed in suite_free */ @@ -61,7 +61,7 @@ void suite_free (Suite *s) free(s); } -TCase *tcase_create (char *name) +TCase *tcase_create (const char *name) { TCase *tc = emalloc (sizeof(TCase)); /*freed in tcase_free */ if (name == NULL) @@ -93,7 +93,7 @@ void suite_add_tcase (Suite *s, TCase *tc) list_add_end (s->tclst, tc); } -void tcase_add_test_ (TCase *tc, TFun fn, char *name) +void tcase_add_test_ (TCase *tc, TFun fn, const char *name) { TF * tf; if (tc == NULL || fn == NULL || name == NULL) @@ -111,7 +111,7 @@ void tcase_set_fixture (TCase *tc, SFun setup, SFun teardown) } -void tcase_fn_start (int msqid, char *fname, char *file, int line) +void tcase_fn_start (int msqid, const char *fname, const char *file, int line) { send_last_loc_msg (msqid, file, line); } @@ -121,7 +121,8 @@ void mark_point_ (int msqid, char *file, int line) send_last_loc_msg (msqid, file, line); } -int fail_unless_ (int msqid, int result, char *file, int line, char * msg) +int fail_unless_ (int msqid, int result, const char *file, int line, + const char * msg) { if (line > MAXLINE) eprintf ("Line number %d too large to use", line); diff --git a/check/check.h b/check/check.h index 0f6047ac..cb9130c8 100644 --- a/check/check.h +++ b/check/check.h @@ -105,14 +105,14 @@ typedef void (*TFun) (int); typedef void (*SFun) (void); /*! Create a test suite */ -Suite *suite_create (char *name); +Suite *suite_create (const char *name); /*! Free a test suite (For the moment, this also frees all contained test cases) */ void suite_free (Suite *s); /*! Create a test case */ -TCase *tcase_create (char *name); +TCase *tcase_create (const char *name); /*! Free a test case (Note that as it stands, one will normally free the contaning suite) */ @@ -126,7 +126,7 @@ void suite_add_tcase (Suite *s, TCase *tc); #define tcase_add_test(tc,tf) tcase_add_test_(tc,tf,"" # tf "") /*! Add a test function to a test case (function version -- use this when the macro won't work */ -void tcase_add_test_ (TCase *tc, TFun tf, char *fname); +void tcase_add_test_ (TCase *tc, TFun tf, const char *fname); /*! @@ -138,7 +138,7 @@ test functions, and so must not exit or signal (e.g., segfault) void tcase_set_fixture(TCase *tc, SFun setup, SFun teardown); /*! Internal function to mark the start of a test function */ -void tcase_fn_start (int msqid, char *fname, char *file, int line); +void tcase_fn_start (int msqid, const char *fname, const char *file, int line); /*! Start a unit test with START_TEST(unit_name), end with END_TEST One must use braces within a START_/END_ pair to declare new variables */ @@ -156,7 +156,8 @@ static void testname__ (int msqid__)\ if(fail_unless_(msqid__,result,__FILE__,__LINE__,msg)) return; /*! Non macro version of #fail_unless, with more complicated interface */ -int fail_unless_ (int msqid, int result, char *file, int line, char *msg); +int fail_unless_ (int msqid, int result, const char *file, int line, + const char *msg); /*! Always fail */ #define fail(msg) fail_unless_(msqid__,0,__FILE__,__LINE__,msg) @@ -208,7 +209,7 @@ int tr_lno (TestResult *tr); /*! File name at which failure occured */ char *tr_lfile (TestResult *tr); /*! Test case in which unit test was run */ -char *tr_tcname (TestResult *tr); +const char *tr_tcname (TestResult *tr); /*! Creates an SRunner for the given suite */ SRunner *srunner_create (Suite *s); diff --git a/check/check_impl.h b/check/check_impl.h index 1fd74208..814f39c5 100644 --- a/check/check_impl.h +++ b/check/check_impl.h @@ -33,16 +33,16 @@ enum { typedef struct TF { TFun fn; - char *name; + const char *name; } TF; struct Suite { - char *name; + const char *name; List *tclst; /* List of test cases */ }; struct TCase { - char *name; + const char *name; List *tflst; /* list of test functions */ SFun setup; SFun teardown; @@ -58,8 +58,8 @@ struct TestResult { int rtype; /* Type of result */ char *file; /* File where the test occured */ int line; /* Line number where the test occurred */ - char *tcname; /* Test case that generated the result */ - char *tfname; /* Test function that generated the result */ + const char *tcname; /* Test case that generated the result */ + const char *tfname; /* Test function that generated the result */ char *msg; /* Failure message */ }; diff --git a/check/check_log.c b/check/check_log.c index 67bd900d..07b4b8f4 100644 --- a/check/check_log.c +++ b/check/check_log.c @@ -52,13 +52,13 @@ char *srunner_log_fname (SRunner *sr) return sr->log_fname; } -void srunner_register_lfun (SRunner *sr, FILE *lfile, int close, +void srunner_register_lfun (SRunner *sr, FILE *lfile, int doclose, LFun lfun, enum print_verbosity printmode) { Log *l = emalloc (sizeof(Log)); l->lfile = lfile; l->lfun = lfun; - l->close = close; + l->close = doclose; l->mode = printmode; list_add_end (sr->loglst, l); return; diff --git a/check/check_log.h b/check/check_log.h index a7205d7d..ad67bc9e 100644 --- a/check/check_log.h +++ b/check/check_log.h @@ -13,7 +13,7 @@ void stdout_lfun (SRunner *sr, FILE *file, enum print_verbosity, void lfile_lfun (SRunner *sr, FILE *file, enum print_verbosity, void *obj, enum cl_event evt); -void srunner_register_lfun (SRunner *sr, FILE *lfile, int close, +void srunner_register_lfun (SRunner *sr, FILE *lfile, int doclose, LFun lfun, enum print_verbosity); FILE *srunner_open_lfile (SRunner *sr); diff --git a/check/check_msg.c b/check/check_msg.c index d88d7820..edc50dce 100644 --- a/check/check_msg.c +++ b/check/check_msg.c @@ -55,10 +55,10 @@ enum { LASTLOCMSG = 1, FAILUREMSG = 2 }; -static LastLocMsg *create_last_loc_msg (char *file, int line); -static FailureMsg *create_failure_msg (char *msg); +static LastLocMsg *create_last_loc_msg (const char *file, int line); +static FailureMsg *create_failure_msg (const char *msg); -static FailureMsg *create_failure_msg (char *msg) +static FailureMsg *create_failure_msg (const char *msg) { FailureMsg *m = emalloc (sizeof(FailureMsg)); m->message_type = (long int) FAILUREMSG; @@ -67,7 +67,7 @@ static FailureMsg *create_failure_msg (char *msg) } -static LastLocMsg *create_last_loc_msg (char *file, int line) +static LastLocMsg *create_last_loc_msg (const char *file, int line) { LastLocMsg *m = emalloc (sizeof(LastLocMsg)); m->message_type = (long int) LASTLOCMSG; @@ -112,7 +112,7 @@ int last_loc_line (LastLocMsg *msg) } -void send_last_loc_msg (int msqid, char * file, int line) +void send_last_loc_msg (int msqid, const char * file, int line) { #ifdef USE_FORKWAITMSG int rval; @@ -148,7 +148,7 @@ void delete_msq (int msqid) } -void send_failure_msg (int msqid, char *msg) +void send_failure_msg (int msqid, const char *msg) { #ifdef USE_FORKWAITMSG int rval; diff --git a/check/check_msg.h b/check/check_msg.h index 76ab94ad..0a7e5e51 100644 --- a/check/check_msg.h +++ b/check/check_msg.h @@ -37,8 +37,8 @@ typedef struct FailureMsg { int create_msq (void); void delete_msq (int msqid); -void send_failure_msg (int msqid, char *msg); -void send_last_loc_msg (int msqid, char * file, int line); +void send_failure_msg (int msqid, const char *msg); +void send_last_loc_msg (int msqid, const char * file, int line); /* malloc'd return value which caller is responsible for freeing in each of the next two functions */ diff --git a/check/check_print.c b/check/check_print.c index 85fd44af..9dc658ef 100644 --- a/check/check_print.c +++ b/check/check_print.c @@ -28,7 +28,7 @@ static void srunner_fprint_summary (FILE *file, SRunner *sr, int print_mode); static void srunner_fprint_results (FILE *file, SRunner *sr, int print_mode); static int percent_passed (TestStats *t); -static char *rtype_to_string (int rtype); +static const char *rtype_to_string (int rtype); void srunner_print (SRunner *sr, int print_mode) { @@ -67,7 +67,7 @@ static void srunner_fprint_results (FILE *file, SRunner *sr, int print_mode) void tr_fprint (FILE *file, TestResult *tr, int print_mode) { - char *exact_msg; + const char *exact_msg; exact_msg = (tr->rtype == CRERROR) ? "(after this point) ": ""; if ((print_mode >= CRVERBOSE && tr->rtype == CRPASS) || (tr->rtype != CRPASS && print_mode >= CRNORMAL)) { @@ -88,7 +88,7 @@ static int percent_passed (TestStats *t) (float) t->n_checked * 100); } -static char *rtype_to_string (int rtype) +static const char *rtype_to_string (int rtype) { switch (rtype) { case CRPASS: diff --git a/check/check_run.c b/check/check_run.c index 90673fc9..ec4eee99 100644 --- a/check/check_run.c +++ b/check/check_run.c @@ -66,9 +66,10 @@ int nofork_exit_status; static void srunner_run_tcase (SRunner *sr, TCase *tc); static void srunner_add_failure (SRunner *sr, TestResult *tf); -static TestResult *tfun_run (int msqid, char *tcname, TF *tf); -static TestResult *receive_result_info (int msqid, int status, char *tcname, - char *tfname); +static TestResult *tfun_run (int msqid, const char *tcname, TF *tf); +static TestResult *receive_result_info (int msqid, int status, + const char *tcname, + const char *tfname); static void receive_last_loc_info (int msqid, TestResult *tr); static void receive_failure_info (int msqid, int status, TestResult *tr); static List *srunner_resultlst (SRunner *sr); @@ -113,8 +114,7 @@ void srunner_free (SRunner *sr) for (list_front(l); !list_at_end(l); list_advance(l)) { tr = list_val(l); free(tr->file); - if (tr->rtype == CRFAILURE || tr->rtype == CRERROR) - free(tr->msg); + free(tr->msg); free(tr); } list_free (sr->resultlst); @@ -222,9 +222,8 @@ static void receive_failure_info (int msqid, int status, TestResult *tr) if (WEXITSTATUS(status) == 0) { tr->rtype = CRPASS; - /* TODO: It would be cleaner to strdup this & - not special case the free...*/ - tr->msg = "Test passed"; + tr->msg = emalloc(strlen("Test passed") + 1); + strcpy (tr->msg, "Test passed"); } else { @@ -246,7 +245,8 @@ static void receive_failure_info (int msqid, int status, TestResult *tr) #else if (status == 0) { tr->rtype = CRPASS; - tr->msg = "Test passed"; + tr->msg = emalloc(strlen("Test passed") + 1); + strcpy (tr->msg, "Test passed"); } else { fmsg = receive_failure_msg (msqid); @@ -264,8 +264,8 @@ static void receive_failure_info (int msqid, int status, TestResult *tr) #endif } -static TestResult *receive_result_info (int msqid, int status, char *tcname, - char *tfname) +static TestResult *receive_result_info (int msqid, int status, + const char *tcname, const char *tfname) { TestResult *tr = emalloc (sizeof(TestResult)); @@ -276,7 +276,7 @@ static TestResult *receive_result_info (int msqid, int status, char *tcname, return tr; } -static TestResult *tfun_run (int msqid, char *tcname, TF *tfun) +static TestResult *tfun_run (int msqid, const char *tcname, TF *tfun) { #ifdef USE_FORKWAITMSG pid_t pid; @@ -370,7 +370,7 @@ int tr_rtype (TestResult *tr) return tr->rtype; } -char *tr_tcname (TestResult *tr) +const char *tr_tcname (TestResult *tr) { return tr->tcname; } diff --git a/check/error.c b/check/error.c index 4a486804..e67030d6 100644 --- a/check/error.c +++ b/check/error.c @@ -32,7 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -void eprintf (char *fmt, ...) +void eprintf (const char *fmt, ...) { va_list args; fflush(stdout); diff --git a/check/error.h b/check/error.h index da089b29..1fb3f107 100644 --- a/check/error.h +++ b/check/error.h @@ -24,7 +24,7 @@ /* Print error message and die If fmt ends in colon, include system error information */ -void eprintf (char *fmt, ...); +void eprintf (const char *fmt, ...); /* malloc or die */ void *emalloc(size_t n); void *erealloc(void *, size_t n); diff --git a/configure.ac b/configure.ac index 5f26f7d8..8340ae3c 100644 --- a/configure.ac +++ b/configure.ac @@ -9,7 +9,7 @@ AM_CONFIG_HEADER(config.h) AM_INIT_AUTOMAKE(yasm, 0.0.1) AC_ARG_ENABLE(dev, -[ --enable-dev Enable full development build capability], +[ --enable-dev Enable full development build capability], [case "${enableval}" in yes) dev=true ;; no) dev=false ;; @@ -17,8 +17,32 @@ AC_ARG_ENABLE(dev, esac],[dev=false]) AM_CONDITIONAL(DEV, test x$dev = xtrue) +AC_ARG_ENABLE(morewarn, +[ --enable-morewarn Enable lots of extra GCC warnings], +[case "${enableval}" in + yes) morewarn=true ;; + no) morewarn=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-morewarn) ;; +esac],[morewarn=false]) + +AC_ARG_ENABLE(warnerror, +[ --enable-warnerror Treat GCC warnings as errors], +[case "${enableval}" in + yes) warnerror=true ;; + no) warnerror=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-warnerror) ;; +esac],[warnerror=false]) + +AC_ARG_ENABLE(profiling, +[ --enable-profiling Enable profiling (requires GCC)], +[case "${enableval}" in + yes) profiling=true ;; + no) profiling=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-profiling) ;; +esac],[profiling=false]) + AC_ARG_ENABLE(check, -[ --disable-check Disable building of test suite and make check], +[ --disable-check Disable building of test suite and make check], [case "${enableval}" in yes) check=true ;; no) check=false ;; @@ -32,8 +56,20 @@ if ${dev}; then DEVFLAGS="-g" fi +if ${morewarn}; then + MOREWARNFLAGS="-Wbad-function-cast -Wcast-align -Wcast-qual -Wchar-subscripts -Winline -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-prototypes -Wwrite-strings" +fi + +if ${warnerror}; then + WARNERRORFLAGS="-Werror" +fi + +if ${profiling}; then + PROFILINGFLAGS="-pg" +fi + if test "$GCC" = yes; then - ANSI_CFLAGS="-ansi -pedantic -Wall $DEVFLAGS" + ANSI_CFLAGS="-ansi -pedantic -Wall $MOREWARNFLAGS $WARNERRORFLAGS $DEVFLAGS $PROFILINGFLAGS" else ANSI_CFLAGS="$DEVFLAGS" fi diff --git a/configure.in b/configure.in index 5f26f7d8..8340ae3c 100644 --- a/configure.in +++ b/configure.in @@ -9,7 +9,7 @@ AM_CONFIG_HEADER(config.h) AM_INIT_AUTOMAKE(yasm, 0.0.1) AC_ARG_ENABLE(dev, -[ --enable-dev Enable full development build capability], +[ --enable-dev Enable full development build capability], [case "${enableval}" in yes) dev=true ;; no) dev=false ;; @@ -17,8 +17,32 @@ AC_ARG_ENABLE(dev, esac],[dev=false]) AM_CONDITIONAL(DEV, test x$dev = xtrue) +AC_ARG_ENABLE(morewarn, +[ --enable-morewarn Enable lots of extra GCC warnings], +[case "${enableval}" in + yes) morewarn=true ;; + no) morewarn=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-morewarn) ;; +esac],[morewarn=false]) + +AC_ARG_ENABLE(warnerror, +[ --enable-warnerror Treat GCC warnings as errors], +[case "${enableval}" in + yes) warnerror=true ;; + no) warnerror=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-warnerror) ;; +esac],[warnerror=false]) + +AC_ARG_ENABLE(profiling, +[ --enable-profiling Enable profiling (requires GCC)], +[case "${enableval}" in + yes) profiling=true ;; + no) profiling=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-profiling) ;; +esac],[profiling=false]) + AC_ARG_ENABLE(check, -[ --disable-check Disable building of test suite and make check], +[ --disable-check Disable building of test suite and make check], [case "${enableval}" in yes) check=true ;; no) check=false ;; @@ -32,8 +56,20 @@ if ${dev}; then DEVFLAGS="-g" fi +if ${morewarn}; then + MOREWARNFLAGS="-Wbad-function-cast -Wcast-align -Wcast-qual -Wchar-subscripts -Winline -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-prototypes -Wwrite-strings" +fi + +if ${warnerror}; then + WARNERRORFLAGS="-Werror" +fi + +if ${profiling}; then + PROFILINGFLAGS="-pg" +fi + if test "$GCC" = yes; then - ANSI_CFLAGS="-ansi -pedantic -Wall $DEVFLAGS" + ANSI_CFLAGS="-ansi -pedantic -Wall $MOREWARNFLAGS $WARNERRORFLAGS $DEVFLAGS $PROFILINGFLAGS" else ANSI_CFLAGS="$DEVFLAGS" fi diff --git a/frontends/yasm/yasm-options.h b/frontends/yasm/yasm-options.h index 121f9e64..0d464883 100644 --- a/frontends/yasm/yasm-options.h +++ b/frontends/yasm/yasm-options.h @@ -35,13 +35,13 @@ */ typedef struct opt_option_s { - char sopt; /* short option letter if present, 0 otherwise */ - char *lopt; /* long option name if present, NULL otherwise */ - int takes_param; /* !=0 if option requires parameter, 0 if not */ + char sopt; /* short option letter if present, 0 otherwise */ + const char *lopt; /* long option name if present, NULL otherwise */ + int takes_param; /* !=0 if option requires parameter, 0 if not */ int (*handler) (char *cmd, char *param, int extra); - int extra; /* extra value for handler */ - char *description; /* description to use in help_msg() */ - char *param_desc; /* optional description for the param taken */ + int extra; /* extra value for handler */ + const char *description; /* description to use in help_msg() */ + const char *param_desc; /* optional description for the param taken */ /* (short - will be printed after option sopt/lopt) */ } opt_option; diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index 435ec46b..fd7a4993 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -62,7 +62,6 @@ static int files_open = 0; static FILE *in; /* Forward declarations: cmd line parser handlers */ -int not_an_option_handler(char *param); int opt_option_handler(char *cmd, char *param, int extra); int opt_format_handler(char *cmd, char *param, int extra); /* Fake handlers: remove them */ @@ -118,7 +117,7 @@ main(int argc, char *argv[]) if (!files_open) { in = stdin; - filename = strdup(""); + in_filename = strdup(""); } /* Get initial BITS setting from object format */ @@ -129,8 +128,8 @@ main(int argc, char *argv[]) if (OutputAllErrorWarning() > 0) return EXIT_FAILURE; - if (filename) - free(filename); + if (in_filename) + free(in_filename); return EXIT_SUCCESS; } @@ -142,7 +141,7 @@ not_an_option_handler(char *param) { if (files_open > 0) { WarningNow("can open only one input file, only latest file will be processed"); - free(filename); + free(in_filename); fclose(in); } @@ -151,7 +150,7 @@ not_an_option_handler(char *param) ErrorNow(_("could not open file `%s'"), param); return 1; } - filename = strdup(param); + in_filename = strdup(param); files_open++; return 0; diff --git a/libyasm/bitvect.c b/libyasm/bitvect.c index 2f547432..ca391ff5 100644 --- a/libyasm/bitvect.c +++ b/libyasm/bitvect.c @@ -319,9 +319,9 @@ N_word BitVector_Mask(N_int bits) /* bit vector mask (unused bits) */ return(mask); } -charptr BitVector_Version(void) +const char * BitVector_Version(void) { - return((charptr)"6.0"); + return("6.0"); } N_int BitVector_Word_Bits(void) @@ -1783,7 +1783,7 @@ ErrCode BitVector_from_Enum(wordptr addr, charptr string) N_word bits = bits_(addr); N_word state = 1; N_word token; - N_word index; + N_word indx; N_word start; if (bits > 0) @@ -1795,8 +1795,8 @@ ErrCode BitVector_from_Enum(wordptr addr, charptr string) /* separate because isdigit() is likely a macro! */ if (isdigit(token) != 0) { - string += BIT_VECTOR_str2int(string,&index); - if (index < bits) token = (N_word) '0'; + string += BIT_VECTOR_str2int(string,&indx); + if (indx < bits) token = (N_word) '0'; else error = ErrCode_Indx; } else string++; @@ -1821,15 +1821,15 @@ ErrCode BitVector_from_Enum(wordptr addr, charptr string) switch (token) { case (N_word) '-': - start = index; + start = indx; state = 3; break; case (N_word) ',': - BIT_VECTOR_SET_BIT(addr,index) + BIT_VECTOR_SET_BIT(addr,indx) state = 5; break; case (N_word) '\0': - BIT_VECTOR_SET_BIT(addr,index) + BIT_VECTOR_SET_BIT(addr,indx) state = 0; break; default: @@ -1841,10 +1841,10 @@ ErrCode BitVector_from_Enum(wordptr addr, charptr string) switch (token) { case (N_word) '0': - if (start < index) - BitVector_Interval_Fill(addr,start,index); - else if (start == index) - BIT_VECTOR_SET_BIT(addr,index) + if (start < indx) + BitVector_Interval_Fill(addr,start,indx); + else if (start == indx) + BIT_VECTOR_SET_BIT(addr,indx) else error = ErrCode_Ordr; state = 4; break; @@ -1889,36 +1889,36 @@ void BitVector_Dispose(charptr string) if (string != NULL) free((voidptr) string); } -void BitVector_Bit_Off(wordptr addr, N_int index) /* X = X \ {x} */ +void BitVector_Bit_Off(wordptr addr, N_int indx) /* X = X \ {x} */ { - if (index < bits_(addr)) BIT_VECTOR_CLR_BIT(addr,index) + if (indx < bits_(addr)) BIT_VECTOR_CLR_BIT(addr,indx) } -void BitVector_Bit_On(wordptr addr, N_int index) /* X = X + {x} */ +void BitVector_Bit_On(wordptr addr, N_int indx) /* X = X + {x} */ { - if (index < bits_(addr)) BIT_VECTOR_SET_BIT(addr,index) + if (indx < bits_(addr)) BIT_VECTOR_SET_BIT(addr,indx) } -boolean BitVector_bit_flip(wordptr addr, N_int index) /* X=(X+{x})\(X*{x}) */ +boolean BitVector_bit_flip(wordptr addr, N_int indx) /* X=(X+{x})\(X*{x}) */ { N_word mask; - if (index < bits_(addr)) return( BIT_VECTOR_FLP_BIT(addr,index,mask) ); - else return( FALSE ); + if (indx < bits_(addr)) return( BIT_VECTOR_FLP_BIT(addr,indx,mask) ); + else return( FALSE ); } -boolean BitVector_bit_test(wordptr addr, N_int index) /* {x} in X ? */ +boolean BitVector_bit_test(wordptr addr, N_int indx) /* {x} in X ? */ { - if (index < bits_(addr)) return( BIT_VECTOR_TST_BIT(addr,index) ); - else return( FALSE ); + if (indx < bits_(addr)) return( BIT_VECTOR_TST_BIT(addr,indx) ); + else return( FALSE ); } -void BitVector_Bit_Copy(wordptr addr, N_int index, boolean bit) +void BitVector_Bit_Copy(wordptr addr, N_int indx, boolean bit) { - if (index < bits_(addr)) + if (indx < bits_(addr)) { - if (bit) BIT_VECTOR_SET_BIT(addr,index) - else BIT_VECTOR_CLR_BIT(addr,index) + if (bit) BIT_VECTOR_SET_BIT(addr,indx) + else BIT_VECTOR_CLR_BIT(addr,indx) } } diff --git a/libyasm/bitvect.h b/libyasm/bitvect.h index 6509881e..7fbc2ce5 100644 --- a/libyasm/bitvect.h +++ b/libyasm/bitvect.h @@ -114,7 +114,7 @@ N_word BitVector_Mask (N_int bits); /* bit vector mask (unused bits) */ /* ===> CLASS METHODS: <=== */ -charptr BitVector_Version (void); /* returns version string */ +const char * BitVector_Version (void); /* returns version string */ N_int BitVector_Word_Bits (void); /* returns # of bits in machine word */ N_int BitVector_Long_Bits (void); /* returns # of bits in unsigned long */ @@ -193,13 +193,13 @@ void BitVector_Dispose (charptr string); /* ===> bit vector bit operations, functions & tests: */ -void BitVector_Bit_Off (wordptr addr, N_int index); /* X = X \ {x} */ -void BitVector_Bit_On (wordptr addr, N_int index); /* X = X + {x} */ -boolean BitVector_bit_flip(wordptr addr, N_int index); /* X=(X+{x})\(X*{x}) */ +void BitVector_Bit_Off (wordptr addr, N_int indx); /* X = X \ {x} */ +void BitVector_Bit_On (wordptr addr, N_int indx); /* X = X + {x} */ +boolean BitVector_bit_flip(wordptr addr, N_int indx); /* X=(X+{x})\(X*{x}) */ -boolean BitVector_bit_test(wordptr addr, N_int index); /* {x} in X ? */ +boolean BitVector_bit_test(wordptr addr, N_int indx); /* {x} in X ? */ -void BitVector_Bit_Copy(wordptr addr, N_int index, boolean bit); +void BitVector_Bit_Copy(wordptr addr, N_int indx, boolean bit); /* ===> bit vector bit shift & rotate functions: */ diff --git a/libyasm/bytecode.c b/libyasm/bytecode.c index 01695afe..f031635f 100644 --- a/libyasm/bytecode.c +++ b/libyasm/bytecode.c @@ -274,7 +274,7 @@ bytecode_new_common(void) bc->len = 0; - bc->filename = strdup(filename); + bc->filename = strdup(in_filename); bc->lineno = line_number; bc->offset = 0; @@ -576,7 +576,7 @@ bytecodes_append(bytecodehead *headp, bytecode *bc) } dataval * -dataval_new_expr(expr *exp) +dataval_new_expr(expr *expn) { dataval *retval = malloc(sizeof(dataval)); @@ -584,7 +584,7 @@ dataval_new_expr(expr *exp) Fatal(FATAL_NOMEM); retval->type = DV_EXPR; - retval->data.exp = exp; + retval->data.expn = expn; return retval; } @@ -629,7 +629,7 @@ dataval_print(datavalhead *head) break; case DV_EXPR: printf(" Expr="); - expr_print(cur->data.exp); + expr_print(cur->data.expn); printf("\n"); break; case DV_FLOAT: diff --git a/libyasm/bytecode.h b/libyasm/bytecode.h index 01a0ac19..05d39de3 100644 --- a/libyasm/bytecode.h +++ b/libyasm/bytecode.h @@ -57,7 +57,7 @@ typedef struct dataval_s { enum { DV_EMPTY, DV_EXPR, DV_FLOAT, DV_STRING } type; union { - struct expr_s *exp; + struct expr_s *expn; struct floatnum_s *flt; char *str_val; } data; @@ -231,7 +231,7 @@ void bytecode_print(bytecode *bc); */ bytecode *bytecodes_append(bytecodehead *headp, bytecode *bc); -dataval *dataval_new_expr(struct expr_s *exp); +dataval *dataval_new_expr(struct expr_s *expn); dataval *dataval_new_float(struct floatnum_s *flt); dataval *dataval_new_string(char *str_val); diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c index 377da658..f6a24d54 100644 --- a/libyasm/errwarn.c +++ b/libyasm/errwarn.c @@ -59,7 +59,7 @@ static unsigned int warning_count = 0; * When adding a string here, keep errwarn.h in sync! */ /* Fatal error messages. Match up with fatal_num enum in errwarn.h. */ -static char *fatal_msgs[] = { +static const char *fatal_msgs[] = { N_("unknown"), N_("out of memory") }; @@ -116,7 +116,7 @@ conv_unprint(char ch) /* Parser error handler. Moves error into our error handling system. */ void -ParserError(char *s) +ParserError(const char *s) { Error("%s %s", _("parser error:"), s); previous_error_parser = 1; @@ -125,7 +125,7 @@ ParserError(char *s) /* Report an internal error. Essentially a fatal error with trace info. * Exit immediately because it's essentially an assert() trap. */ void -InternalError(unsigned int line, char *file, char *message) +InternalError(unsigned int line, const char *file, const char *message) { fprintf(stderr, _("INTERNAL ERROR at %s, line %d: %s\n"), file, line, message); @@ -153,7 +153,7 @@ Fatal(fatal_num num) * argument types. Does not print the error, only stores it for * OutputAllErrorWarning() to print. */ void -Error(char *fmt, ...) +Error(const char *fmt, ...) { va_list ap; errwarn *we; @@ -177,7 +177,7 @@ Error(char *fmt, ...) Fatal(FATAL_NOMEM); we->type = WE_ERROR; - we->filename = strdup(filename); + we->filename = strdup(in_filename); if (!we->filename) Fatal(FATAL_NOMEM); we->line = line_number; @@ -200,7 +200,7 @@ Error(char *fmt, ...) * argument types. Does not print the warning, only stores it for * OutputAllErrorWarning() to print. */ void -Warning(char *fmt, ...) +Warning(const char *fmt, ...) { va_list ap; errwarn *we; @@ -215,7 +215,7 @@ Warning(char *fmt, ...) Fatal(FATAL_NOMEM); we->type = WE_WARNING; - we->filename = strdup(filename); + we->filename = strdup(in_filename); if (!we->filename) Fatal(FATAL_NOMEM); we->line = line_number; @@ -234,7 +234,7 @@ Warning(char *fmt, ...) } void -ErrorNow(char *fmt, ...) +ErrorNow(const char *fmt, ...) { va_list ap; @@ -245,7 +245,7 @@ ErrorNow(char *fmt, ...) } void -WarningNow(char *fmt, ...) +WarningNow(const char *fmt, ...) { va_list ap; @@ -257,13 +257,13 @@ WarningNow(char *fmt, ...) } void -ErrorAt(char *filename, unsigned long line, char *fmt, ...) +ErrorAt(const char *filename, unsigned long line, const char *fmt, ...) { /* TODO */ } void -WarningAt(char *filename, unsigned long line, char *fmt, ...) +WarningAt(const char *filename, unsigned long line, const char *fmt, ...) { /* TODO */ } diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h index cb701f95..6a7d9ece 100644 --- a/libyasm/errwarn.h +++ b/libyasm/errwarn.h @@ -32,27 +32,27 @@ typedef enum { char *conv_unprint(char ch); -void ParserError(char *); +void ParserError(const char *); -void InternalError(unsigned int line, char *file, char *message); +void InternalError(unsigned int line, const char *file, const char *message); void Fatal(fatal_num); -void Error(char *, ...); -void Warning(char *, ...); +void Error(const char *, ...); +void Warning(const char *, ...); /* Use Error() and Warning() instead of ErrorAt() and WarningAt() when being * called in line order from a parser. The *At() functions are much slower, * at least in the current implementation. */ -void ErrorAt(char *filename, unsigned long line, char *, ...); -void WarningAt(char *filename, unsigned long line, char *, ...); +void ErrorAt(const char *filename, unsigned long line, const char *, ...); +void WarningAt(const char *filename, unsigned long line, const char *, ...); /* These two functions immediately output the error or warning, with no file * or line information. They should be used for errors and warnings outside * the parser stage (at program startup, for instance). */ -void ErrorNow(char *, ...); -void WarningNow(char *, ...); +void ErrorNow(const char *, ...); +void WarningNow(const char *, ...); /* Returns total number of errors to this point in assembly. */ unsigned int OutputAllErrorWarning(void); diff --git a/libyasm/linemgr.c b/libyasm/linemgr.c index 92aa3e89..4af39630 100644 --- a/libyasm/linemgr.c +++ b/libyasm/linemgr.c @@ -29,7 +29,7 @@ RCSID("$IdPath$"); -char *filename = (char *)NULL; +char *in_filename = (char *)NULL; unsigned int line_number = 1; unsigned char mode_bits = 0; unsigned int asm_options = 0; diff --git a/libyasm/linemgr.h b/libyasm/linemgr.h index 4cae3b83..373d1dd8 100644 --- a/libyasm/linemgr.h +++ b/libyasm/linemgr.h @@ -22,7 +22,7 @@ #ifndef YASM_GLOBALS_H #define YASM_GLOBALS_H -extern char *filename; +extern char *in_filename; extern unsigned int line_number; extern unsigned char mode_bits; extern unsigned int asm_options; diff --git a/libyasm/symrec.c b/libyasm/symrec.c index 5d545632..2283f0d5 100644 --- a/libyasm/symrec.c +++ b/libyasm/symrec.c @@ -71,7 +71,7 @@ symrec_get_or_new(const char *name) if (!rec->name) Fatal(FATAL_NOMEM); rec->type = SYM_UNKNOWN; - rec->filename = strdup(filename); + rec->filename = strdup(in_filename); rec->line = line_number; rec->status = SYM_NOSTATUS; rec->visibility = SYM_LOCAL; diff --git a/libyasm/tests/bytecode_test.c b/libyasm/tests/bytecode_test.c index 9d333b5f..708cc094 100644 --- a/libyasm/tests/bytecode_test.c +++ b/libyasm/tests/bytecode_test.c @@ -1,7 +1,14 @@ /* $IdPath$ * */ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef STDC_HEADERS +# include +#endif + #include "check.h" #include "util.h" @@ -37,7 +44,8 @@ START_TEST(test_effaddr_new_reg) } END_TEST -Suite *bytecode_suite(void) +static Suite * +bytecode_suite(void) { Suite *s = suite_create("bytecode"); TCase *tc_conversion = tcase_create("Conversion"); @@ -48,7 +56,8 @@ Suite *bytecode_suite(void) return s; } -int main(void) +int +main(void) { int nf; Suite *s = bytecode_suite(); diff --git a/libyasm/tests/floatnum_test.c b/libyasm/tests/floatnum_test.c index d94797c6..f3f6f99c 100644 --- a/libyasm/tests/floatnum_test.c +++ b/libyasm/tests/floatnum_test.c @@ -1,7 +1,14 @@ /* $IdPath$ * */ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef STDC_HEADERS +# include +#endif + #include "check.h" #include "bitvect.h" @@ -9,20 +16,23 @@ #include "floatnum.h" floatnum *flt; -void get_family_setup(void) +static void +get_family_setup(void) { flt = malloc(sizeof(floatnum)); flt->mantissa = BitVector_Create(80, TRUE); } -void get_family_teardown(void) +static void +get_family_teardown(void) { BitVector_Destroy(flt->mantissa); free(flt); } -void pi_setup(void) +static void +pi_setup(void) { /* test value: 3.141592653589793 */ /* 80-bit little endian mantissa: C6 0D E9 BD 68 21 A2 DA 0F C9 */ @@ -86,7 +96,8 @@ START_TEST(test_get_extended_pi) } END_TEST -Suite *bytecode_suite(void) +static Suite * +floatnum_suite(void) { Suite *s = suite_create("floatnum"); TCase *tc_get_single = tcase_create("get_single"); @@ -108,10 +119,11 @@ Suite *bytecode_suite(void) return s; } -int main(void) +int +main(void) { int nf; - Suite *s = bytecode_suite(); + Suite *s = floatnum_suite(); SRunner *sr = srunner_create(s); BitVector_Boot(); srunner_run_all(sr, CRNORMAL); diff --git a/modules/parsers/nasm/bison.y.in b/modules/parsers/nasm/bison.y.in index 9b633fbd..f0c66ad8 100644 --- a/modules/parsers/nasm/bison.y.in +++ b/modules/parsers/nasm/bison.y.in @@ -52,7 +52,7 @@ RCSID("$IdPath$"); void init_table(void); extern int nasm_parser_lex(void); static unsigned long ConvertCharConstToInt(char *); -void nasm_parser_error(char *); +void nasm_parser_error(const char *); extern objfmt *nasm_parser_objfmt; extern sectionhead nasm_parser_sections; @@ -471,7 +471,7 @@ ConvertCharConstToInt(char *cc) } void -nasm_parser_error(char *s) +nasm_parser_error(const char *s) { ParserError(s); } diff --git a/modules/parsers/nasm/nasm-bison.y b/modules/parsers/nasm/nasm-bison.y index 9b633fbd..f0c66ad8 100644 --- a/modules/parsers/nasm/nasm-bison.y +++ b/modules/parsers/nasm/nasm-bison.y @@ -52,7 +52,7 @@ RCSID("$IdPath$"); void init_table(void); extern int nasm_parser_lex(void); static unsigned long ConvertCharConstToInt(char *); -void nasm_parser_error(char *); +void nasm_parser_error(const char *); extern objfmt *nasm_parser_objfmt; extern sectionhead nasm_parser_sections; @@ -471,7 +471,7 @@ ConvertCharConstToInt(char *cc) } void -nasm_parser_error(char *s) +nasm_parser_error(const char *s) { ParserError(s); } diff --git a/modules/parsers/nasm/token.l.in b/modules/parsers/nasm/token.l.in index 4f4b72b2..43c95f59 100644 --- a/modules/parsers/nasm/token.l.in +++ b/modules/parsers/nasm/token.l.in @@ -49,6 +49,8 @@ RCSID("$IdPath$"); #define yylval nasm_parser_lval +int nasm_parser_lex(void); + extern int (*nasm_parser_yyinput) (char *buf, int max_size); #undef YY_INPUT #define YY_INPUT(b, r, ms) (r = nasm_parser_yyinput(b, ms)) diff --git a/src/bitvect.c b/src/bitvect.c index 2f547432..ca391ff5 100644 --- a/src/bitvect.c +++ b/src/bitvect.c @@ -319,9 +319,9 @@ N_word BitVector_Mask(N_int bits) /* bit vector mask (unused bits) */ return(mask); } -charptr BitVector_Version(void) +const char * BitVector_Version(void) { - return((charptr)"6.0"); + return("6.0"); } N_int BitVector_Word_Bits(void) @@ -1783,7 +1783,7 @@ ErrCode BitVector_from_Enum(wordptr addr, charptr string) N_word bits = bits_(addr); N_word state = 1; N_word token; - N_word index; + N_word indx; N_word start; if (bits > 0) @@ -1795,8 +1795,8 @@ ErrCode BitVector_from_Enum(wordptr addr, charptr string) /* separate because isdigit() is likely a macro! */ if (isdigit(token) != 0) { - string += BIT_VECTOR_str2int(string,&index); - if (index < bits) token = (N_word) '0'; + string += BIT_VECTOR_str2int(string,&indx); + if (indx < bits) token = (N_word) '0'; else error = ErrCode_Indx; } else string++; @@ -1821,15 +1821,15 @@ ErrCode BitVector_from_Enum(wordptr addr, charptr string) switch (token) { case (N_word) '-': - start = index; + start = indx; state = 3; break; case (N_word) ',': - BIT_VECTOR_SET_BIT(addr,index) + BIT_VECTOR_SET_BIT(addr,indx) state = 5; break; case (N_word) '\0': - BIT_VECTOR_SET_BIT(addr,index) + BIT_VECTOR_SET_BIT(addr,indx) state = 0; break; default: @@ -1841,10 +1841,10 @@ ErrCode BitVector_from_Enum(wordptr addr, charptr string) switch (token) { case (N_word) '0': - if (start < index) - BitVector_Interval_Fill(addr,start,index); - else if (start == index) - BIT_VECTOR_SET_BIT(addr,index) + if (start < indx) + BitVector_Interval_Fill(addr,start,indx); + else if (start == indx) + BIT_VECTOR_SET_BIT(addr,indx) else error = ErrCode_Ordr; state = 4; break; @@ -1889,36 +1889,36 @@ void BitVector_Dispose(charptr string) if (string != NULL) free((voidptr) string); } -void BitVector_Bit_Off(wordptr addr, N_int index) /* X = X \ {x} */ +void BitVector_Bit_Off(wordptr addr, N_int indx) /* X = X \ {x} */ { - if (index < bits_(addr)) BIT_VECTOR_CLR_BIT(addr,index) + if (indx < bits_(addr)) BIT_VECTOR_CLR_BIT(addr,indx) } -void BitVector_Bit_On(wordptr addr, N_int index) /* X = X + {x} */ +void BitVector_Bit_On(wordptr addr, N_int indx) /* X = X + {x} */ { - if (index < bits_(addr)) BIT_VECTOR_SET_BIT(addr,index) + if (indx < bits_(addr)) BIT_VECTOR_SET_BIT(addr,indx) } -boolean BitVector_bit_flip(wordptr addr, N_int index) /* X=(X+{x})\(X*{x}) */ +boolean BitVector_bit_flip(wordptr addr, N_int indx) /* X=(X+{x})\(X*{x}) */ { N_word mask; - if (index < bits_(addr)) return( BIT_VECTOR_FLP_BIT(addr,index,mask) ); - else return( FALSE ); + if (indx < bits_(addr)) return( BIT_VECTOR_FLP_BIT(addr,indx,mask) ); + else return( FALSE ); } -boolean BitVector_bit_test(wordptr addr, N_int index) /* {x} in X ? */ +boolean BitVector_bit_test(wordptr addr, N_int indx) /* {x} in X ? */ { - if (index < bits_(addr)) return( BIT_VECTOR_TST_BIT(addr,index) ); - else return( FALSE ); + if (indx < bits_(addr)) return( BIT_VECTOR_TST_BIT(addr,indx) ); + else return( FALSE ); } -void BitVector_Bit_Copy(wordptr addr, N_int index, boolean bit) +void BitVector_Bit_Copy(wordptr addr, N_int indx, boolean bit) { - if (index < bits_(addr)) + if (indx < bits_(addr)) { - if (bit) BIT_VECTOR_SET_BIT(addr,index) - else BIT_VECTOR_CLR_BIT(addr,index) + if (bit) BIT_VECTOR_SET_BIT(addr,indx) + else BIT_VECTOR_CLR_BIT(addr,indx) } } diff --git a/src/bitvect.h b/src/bitvect.h index 6509881e..7fbc2ce5 100644 --- a/src/bitvect.h +++ b/src/bitvect.h @@ -114,7 +114,7 @@ N_word BitVector_Mask (N_int bits); /* bit vector mask (unused bits) */ /* ===> CLASS METHODS: <=== */ -charptr BitVector_Version (void); /* returns version string */ +const char * BitVector_Version (void); /* returns version string */ N_int BitVector_Word_Bits (void); /* returns # of bits in machine word */ N_int BitVector_Long_Bits (void); /* returns # of bits in unsigned long */ @@ -193,13 +193,13 @@ void BitVector_Dispose (charptr string); /* ===> bit vector bit operations, functions & tests: */ -void BitVector_Bit_Off (wordptr addr, N_int index); /* X = X \ {x} */ -void BitVector_Bit_On (wordptr addr, N_int index); /* X = X + {x} */ -boolean BitVector_bit_flip(wordptr addr, N_int index); /* X=(X+{x})\(X*{x}) */ +void BitVector_Bit_Off (wordptr addr, N_int indx); /* X = X \ {x} */ +void BitVector_Bit_On (wordptr addr, N_int indx); /* X = X + {x} */ +boolean BitVector_bit_flip(wordptr addr, N_int indx); /* X=(X+{x})\(X*{x}) */ -boolean BitVector_bit_test(wordptr addr, N_int index); /* {x} in X ? */ +boolean BitVector_bit_test(wordptr addr, N_int indx); /* {x} in X ? */ -void BitVector_Bit_Copy(wordptr addr, N_int index, boolean bit); +void BitVector_Bit_Copy(wordptr addr, N_int indx, boolean bit); /* ===> bit vector bit shift & rotate functions: */ diff --git a/src/bytecode.c b/src/bytecode.c index 01695afe..f031635f 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -274,7 +274,7 @@ bytecode_new_common(void) bc->len = 0; - bc->filename = strdup(filename); + bc->filename = strdup(in_filename); bc->lineno = line_number; bc->offset = 0; @@ -576,7 +576,7 @@ bytecodes_append(bytecodehead *headp, bytecode *bc) } dataval * -dataval_new_expr(expr *exp) +dataval_new_expr(expr *expn) { dataval *retval = malloc(sizeof(dataval)); @@ -584,7 +584,7 @@ dataval_new_expr(expr *exp) Fatal(FATAL_NOMEM); retval->type = DV_EXPR; - retval->data.exp = exp; + retval->data.expn = expn; return retval; } @@ -629,7 +629,7 @@ dataval_print(datavalhead *head) break; case DV_EXPR: printf(" Expr="); - expr_print(cur->data.exp); + expr_print(cur->data.expn); printf("\n"); break; case DV_FLOAT: diff --git a/src/bytecode.h b/src/bytecode.h index 01a0ac19..05d39de3 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -57,7 +57,7 @@ typedef struct dataval_s { enum { DV_EMPTY, DV_EXPR, DV_FLOAT, DV_STRING } type; union { - struct expr_s *exp; + struct expr_s *expn; struct floatnum_s *flt; char *str_val; } data; @@ -231,7 +231,7 @@ void bytecode_print(bytecode *bc); */ bytecode *bytecodes_append(bytecodehead *headp, bytecode *bc); -dataval *dataval_new_expr(struct expr_s *exp); +dataval *dataval_new_expr(struct expr_s *expn); dataval *dataval_new_float(struct floatnum_s *flt); dataval *dataval_new_string(char *str_val); diff --git a/src/errwarn.c b/src/errwarn.c index 377da658..f6a24d54 100644 --- a/src/errwarn.c +++ b/src/errwarn.c @@ -59,7 +59,7 @@ static unsigned int warning_count = 0; * When adding a string here, keep errwarn.h in sync! */ /* Fatal error messages. Match up with fatal_num enum in errwarn.h. */ -static char *fatal_msgs[] = { +static const char *fatal_msgs[] = { N_("unknown"), N_("out of memory") }; @@ -116,7 +116,7 @@ conv_unprint(char ch) /* Parser error handler. Moves error into our error handling system. */ void -ParserError(char *s) +ParserError(const char *s) { Error("%s %s", _("parser error:"), s); previous_error_parser = 1; @@ -125,7 +125,7 @@ ParserError(char *s) /* Report an internal error. Essentially a fatal error with trace info. * Exit immediately because it's essentially an assert() trap. */ void -InternalError(unsigned int line, char *file, char *message) +InternalError(unsigned int line, const char *file, const char *message) { fprintf(stderr, _("INTERNAL ERROR at %s, line %d: %s\n"), file, line, message); @@ -153,7 +153,7 @@ Fatal(fatal_num num) * argument types. Does not print the error, only stores it for * OutputAllErrorWarning() to print. */ void -Error(char *fmt, ...) +Error(const char *fmt, ...) { va_list ap; errwarn *we; @@ -177,7 +177,7 @@ Error(char *fmt, ...) Fatal(FATAL_NOMEM); we->type = WE_ERROR; - we->filename = strdup(filename); + we->filename = strdup(in_filename); if (!we->filename) Fatal(FATAL_NOMEM); we->line = line_number; @@ -200,7 +200,7 @@ Error(char *fmt, ...) * argument types. Does not print the warning, only stores it for * OutputAllErrorWarning() to print. */ void -Warning(char *fmt, ...) +Warning(const char *fmt, ...) { va_list ap; errwarn *we; @@ -215,7 +215,7 @@ Warning(char *fmt, ...) Fatal(FATAL_NOMEM); we->type = WE_WARNING; - we->filename = strdup(filename); + we->filename = strdup(in_filename); if (!we->filename) Fatal(FATAL_NOMEM); we->line = line_number; @@ -234,7 +234,7 @@ Warning(char *fmt, ...) } void -ErrorNow(char *fmt, ...) +ErrorNow(const char *fmt, ...) { va_list ap; @@ -245,7 +245,7 @@ ErrorNow(char *fmt, ...) } void -WarningNow(char *fmt, ...) +WarningNow(const char *fmt, ...) { va_list ap; @@ -257,13 +257,13 @@ WarningNow(char *fmt, ...) } void -ErrorAt(char *filename, unsigned long line, char *fmt, ...) +ErrorAt(const char *filename, unsigned long line, const char *fmt, ...) { /* TODO */ } void -WarningAt(char *filename, unsigned long line, char *fmt, ...) +WarningAt(const char *filename, unsigned long line, const char *fmt, ...) { /* TODO */ } diff --git a/src/errwarn.h b/src/errwarn.h index cb701f95..6a7d9ece 100644 --- a/src/errwarn.h +++ b/src/errwarn.h @@ -32,27 +32,27 @@ typedef enum { char *conv_unprint(char ch); -void ParserError(char *); +void ParserError(const char *); -void InternalError(unsigned int line, char *file, char *message); +void InternalError(unsigned int line, const char *file, const char *message); void Fatal(fatal_num); -void Error(char *, ...); -void Warning(char *, ...); +void Error(const char *, ...); +void Warning(const char *, ...); /* Use Error() and Warning() instead of ErrorAt() and WarningAt() when being * called in line order from a parser. The *At() functions are much slower, * at least in the current implementation. */ -void ErrorAt(char *filename, unsigned long line, char *, ...); -void WarningAt(char *filename, unsigned long line, char *, ...); +void ErrorAt(const char *filename, unsigned long line, const char *, ...); +void WarningAt(const char *filename, unsigned long line, const char *, ...); /* These two functions immediately output the error or warning, with no file * or line information. They should be used for errors and warnings outside * the parser stage (at program startup, for instance). */ -void ErrorNow(char *, ...); -void WarningNow(char *, ...); +void ErrorNow(const char *, ...); +void WarningNow(const char *, ...); /* Returns total number of errors to this point in assembly. */ unsigned int OutputAllErrorWarning(void); diff --git a/src/globals.c b/src/globals.c index 92aa3e89..4af39630 100644 --- a/src/globals.c +++ b/src/globals.c @@ -29,7 +29,7 @@ RCSID("$IdPath$"); -char *filename = (char *)NULL; +char *in_filename = (char *)NULL; unsigned int line_number = 1; unsigned char mode_bits = 0; unsigned int asm_options = 0; diff --git a/src/globals.h b/src/globals.h index 4cae3b83..373d1dd8 100644 --- a/src/globals.h +++ b/src/globals.h @@ -22,7 +22,7 @@ #ifndef YASM_GLOBALS_H #define YASM_GLOBALS_H -extern char *filename; +extern char *in_filename; extern unsigned int line_number; extern unsigned char mode_bits; extern unsigned int asm_options; diff --git a/src/linemgr.c b/src/linemgr.c index 92aa3e89..4af39630 100644 --- a/src/linemgr.c +++ b/src/linemgr.c @@ -29,7 +29,7 @@ RCSID("$IdPath$"); -char *filename = (char *)NULL; +char *in_filename = (char *)NULL; unsigned int line_number = 1; unsigned char mode_bits = 0; unsigned int asm_options = 0; diff --git a/src/linemgr.h b/src/linemgr.h index 4cae3b83..373d1dd8 100644 --- a/src/linemgr.h +++ b/src/linemgr.h @@ -22,7 +22,7 @@ #ifndef YASM_GLOBALS_H #define YASM_GLOBALS_H -extern char *filename; +extern char *in_filename; extern unsigned int line_number; extern unsigned char mode_bits; extern unsigned int asm_options; diff --git a/src/main.c b/src/main.c index 435ec46b..fd7a4993 100644 --- a/src/main.c +++ b/src/main.c @@ -62,7 +62,6 @@ static int files_open = 0; static FILE *in; /* Forward declarations: cmd line parser handlers */ -int not_an_option_handler(char *param); int opt_option_handler(char *cmd, char *param, int extra); int opt_format_handler(char *cmd, char *param, int extra); /* Fake handlers: remove them */ @@ -118,7 +117,7 @@ main(int argc, char *argv[]) if (!files_open) { in = stdin; - filename = strdup(""); + in_filename = strdup(""); } /* Get initial BITS setting from object format */ @@ -129,8 +128,8 @@ main(int argc, char *argv[]) if (OutputAllErrorWarning() > 0) return EXIT_FAILURE; - if (filename) - free(filename); + if (in_filename) + free(in_filename); return EXIT_SUCCESS; } @@ -142,7 +141,7 @@ not_an_option_handler(char *param) { if (files_open > 0) { WarningNow("can open only one input file, only latest file will be processed"); - free(filename); + free(in_filename); fclose(in); } @@ -151,7 +150,7 @@ not_an_option_handler(char *param) ErrorNow(_("could not open file `%s'"), param); return 1; } - filename = strdup(param); + in_filename = strdup(param); files_open++; return 0; diff --git a/src/options.h b/src/options.h index 121f9e64..0d464883 100644 --- a/src/options.h +++ b/src/options.h @@ -35,13 +35,13 @@ */ typedef struct opt_option_s { - char sopt; /* short option letter if present, 0 otherwise */ - char *lopt; /* long option name if present, NULL otherwise */ - int takes_param; /* !=0 if option requires parameter, 0 if not */ + char sopt; /* short option letter if present, 0 otherwise */ + const char *lopt; /* long option name if present, NULL otherwise */ + int takes_param; /* !=0 if option requires parameter, 0 if not */ int (*handler) (char *cmd, char *param, int extra); - int extra; /* extra value for handler */ - char *description; /* description to use in help_msg() */ - char *param_desc; /* optional description for the param taken */ + int extra; /* extra value for handler */ + const char *description; /* description to use in help_msg() */ + const char *param_desc; /* optional description for the param taken */ /* (short - will be printed after option sopt/lopt) */ } opt_option; diff --git a/src/parsers/nasm/bison.y.in b/src/parsers/nasm/bison.y.in index 9b633fbd..f0c66ad8 100644 --- a/src/parsers/nasm/bison.y.in +++ b/src/parsers/nasm/bison.y.in @@ -52,7 +52,7 @@ RCSID("$IdPath$"); void init_table(void); extern int nasm_parser_lex(void); static unsigned long ConvertCharConstToInt(char *); -void nasm_parser_error(char *); +void nasm_parser_error(const char *); extern objfmt *nasm_parser_objfmt; extern sectionhead nasm_parser_sections; @@ -471,7 +471,7 @@ ConvertCharConstToInt(char *cc) } void -nasm_parser_error(char *s) +nasm_parser_error(const char *s) { ParserError(s); } diff --git a/src/parsers/nasm/nasm-bison.y b/src/parsers/nasm/nasm-bison.y index 9b633fbd..f0c66ad8 100644 --- a/src/parsers/nasm/nasm-bison.y +++ b/src/parsers/nasm/nasm-bison.y @@ -52,7 +52,7 @@ RCSID("$IdPath$"); void init_table(void); extern int nasm_parser_lex(void); static unsigned long ConvertCharConstToInt(char *); -void nasm_parser_error(char *); +void nasm_parser_error(const char *); extern objfmt *nasm_parser_objfmt; extern sectionhead nasm_parser_sections; @@ -471,7 +471,7 @@ ConvertCharConstToInt(char *cc) } void -nasm_parser_error(char *s) +nasm_parser_error(const char *s) { ParserError(s); } diff --git a/src/parsers/nasm/token.l.in b/src/parsers/nasm/token.l.in index 4f4b72b2..43c95f59 100644 --- a/src/parsers/nasm/token.l.in +++ b/src/parsers/nasm/token.l.in @@ -49,6 +49,8 @@ RCSID("$IdPath$"); #define yylval nasm_parser_lval +int nasm_parser_lex(void); + extern int (*nasm_parser_yyinput) (char *buf, int max_size); #undef YY_INPUT #define YY_INPUT(b, r, ms) (r = nasm_parser_yyinput(b, ms)) diff --git a/src/symrec.c b/src/symrec.c index 5d545632..2283f0d5 100644 --- a/src/symrec.c +++ b/src/symrec.c @@ -71,7 +71,7 @@ symrec_get_or_new(const char *name) if (!rec->name) Fatal(FATAL_NOMEM); rec->type = SYM_UNKNOWN; - rec->filename = strdup(filename); + rec->filename = strdup(in_filename); rec->line = line_number; rec->status = SYM_NOSTATUS; rec->visibility = SYM_LOCAL; diff --git a/src/tests/bytecode_test.c b/src/tests/bytecode_test.c index 9d333b5f..708cc094 100644 --- a/src/tests/bytecode_test.c +++ b/src/tests/bytecode_test.c @@ -1,7 +1,14 @@ /* $IdPath$ * */ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef STDC_HEADERS +# include +#endif + #include "check.h" #include "util.h" @@ -37,7 +44,8 @@ START_TEST(test_effaddr_new_reg) } END_TEST -Suite *bytecode_suite(void) +static Suite * +bytecode_suite(void) { Suite *s = suite_create("bytecode"); TCase *tc_conversion = tcase_create("Conversion"); @@ -48,7 +56,8 @@ Suite *bytecode_suite(void) return s; } -int main(void) +int +main(void) { int nf; Suite *s = bytecode_suite(); diff --git a/src/tests/floatnum_test.c b/src/tests/floatnum_test.c index d94797c6..f3f6f99c 100644 --- a/src/tests/floatnum_test.c +++ b/src/tests/floatnum_test.c @@ -1,7 +1,14 @@ /* $IdPath$ * */ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef STDC_HEADERS +# include +#endif + #include "check.h" #include "bitvect.h" @@ -9,20 +16,23 @@ #include "floatnum.h" floatnum *flt; -void get_family_setup(void) +static void +get_family_setup(void) { flt = malloc(sizeof(floatnum)); flt->mantissa = BitVector_Create(80, TRUE); } -void get_family_teardown(void) +static void +get_family_teardown(void) { BitVector_Destroy(flt->mantissa); free(flt); } -void pi_setup(void) +static void +pi_setup(void) { /* test value: 3.141592653589793 */ /* 80-bit little endian mantissa: C6 0D E9 BD 68 21 A2 DA 0F C9 */ @@ -86,7 +96,8 @@ START_TEST(test_get_extended_pi) } END_TEST -Suite *bytecode_suite(void) +static Suite * +floatnum_suite(void) { Suite *s = suite_create("floatnum"); TCase *tc_get_single = tcase_create("get_single"); @@ -108,10 +119,11 @@ Suite *bytecode_suite(void) return s; } -int main(void) +int +main(void) { int nf; - Suite *s = bytecode_suite(); + Suite *s = floatnum_suite(); SRunner *sr = srunner_create(s); BitVector_Boot(); srunner_run_all(sr, CRNORMAL);